Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
70ee4b80
Commit
70ee4b80
authored
Jun 14, 2013
by
Chris Dodge
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add unit tests for asset delete/restore
parent
274d8997
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
116 additions
and
3 deletions
+116
-3
cms/djangoapps/contentstore/tests/test_contentstore.py
+108
-0
cms/djangoapps/contentstore/views/assets.py
+0
-1
cms/envs/test.py
+7
-1
common/lib/xmodule/xmodule/modulestore/xml_importer.py
+1
-1
No files found.
cms/djangoapps/contentstore/tests/test_contentstore.py
View file @
70ee4b80
...
...
@@ -28,6 +28,8 @@ from xmodule.templates import update_templates
from
xmodule.modulestore.xml_exporter
import
export_to_xml
from
xmodule.modulestore.xml_importer
import
import_from_xml
,
perform_xlint
from
xmodule.modulestore.inheritance
import
own_metadata
from
xmodule.contentstore.content
import
StaticContent
from
xmodule.contentstore.utils
import
restore_asset_from_trashcan
from
xmodule.capa_module
import
CapaDescriptor
from
xmodule.course_module
import
CourseDescriptor
...
...
@@ -35,6 +37,7 @@ from xmodule.seq_module import SequenceDescriptor
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
from
contentstore.views.component
import
ADVANCED_COMPONENT_TYPES
from
xmodule.exceptions
import
NotFoundError
from
django_comment_common.utils
import
are_permissions_roles_seeded
from
xmodule.exceptions
import
InvalidVersionError
...
...
@@ -382,6 +385,111 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
course
=
module_store
.
get_item
(
source_location
)
self
.
assertFalse
(
course
.
hide_progress_tab
)
def
test_asset_import
(
self
):
'''
This test validates that an image asset is imported and a thumbnail was generated for a .gif
'''
content_store
=
contentstore
()
module_store
=
modulestore
(
'direct'
)
import_from_xml
(
module_store
,
'common/test/data/'
,
[
'full'
],
static_content_store
=
content_store
)
course_location
=
CourseDescriptor
.
id_to_location
(
'edX/full/6.002_Spring_2012'
)
course
=
module_store
.
get_item
(
course_location
)
self
.
assertIsNotNone
(
course
)
# make sure we have some assets in our contentstore
all_assets
=
content_store
.
get_all_content_for_course
(
course_location
)
self
.
assertGreater
(
len
(
all_assets
),
0
)
# make sure we have some thumbnails in our contentstore
all_thumbnails
=
content_store
.
get_all_content_thumbnails_for_course
(
course_location
)
self
.
assertGreater
(
len
(
all_thumbnails
),
0
)
content
=
None
try
:
location
=
StaticContent
.
get_location_from_path
(
'/c4x/edX/full/asset/circuits_duality.gif'
)
content
=
content_store
.
find
(
location
)
except
NotFoundError
:
pass
self
.
assertIsNotNone
(
content
)
self
.
assertIsNotNone
(
content
.
thumbnail_location
)
thumbnail
=
None
try
:
thumbnail
=
content_store
.
find
(
content
.
thumbnail_location
)
except
:
pass
self
.
assertIsNotNone
(
thumbnail
)
def
test_asset_delete_and_restore
(
self
):
'''
This test will exercise the soft delete/restore functionality of the assets
'''
content_store
=
contentstore
()
trash_store
=
contentstore
(
'trashcan'
)
module_store
=
modulestore
(
'direct'
)
import_from_xml
(
module_store
,
'common/test/data/'
,
[
'full'
],
static_content_store
=
content_store
)
content
=
None
try
:
location
=
StaticContent
.
get_location_from_path
(
'/c4x/edX/full/asset/circuits_duality.gif'
)
content
=
content_store
.
find
(
location
)
except
NotFoundError
:
pass
self
.
assertIsNotNone
(
content
)
# go through the website to do the delete, since the soft-delete logic is in the view
url
=
reverse
(
'remove_asset'
,
kwargs
=
{
'org'
:
'edX'
,
'course'
:
'full'
,
'name'
:
'6.002_Spring_2012'
})
resp
=
self
.
client
.
post
(
url
,
{
'location'
:
'/c4x/edX/full/asset/circuits_duality.gif'
})
self
.
assertEqual
(
resp
.
status_code
,
200
)
asset_location
=
StaticContent
.
get_location_from_path
(
'/c4x/edX/full/asset/circuits_duality.gif'
)
# now try to find it in store, but they should not be there any longer
content
=
None
thumbnail
=
None
try
:
content
=
content_store
.
find
(
asset_location
)
thumbnail
=
trash_store
.
find
(
content
.
thumbnail_location
)
except
NotFoundError
:
pass
self
.
assertIsNone
(
content
)
self
.
assertIsNone
(
thumbnail
)
# now try to find it and the thumbnail in trashcan
content
=
None
thumbnail
=
None
try
:
content
=
trash_store
.
find
(
asset_location
)
thumbnail
=
trash_store
.
find
(
content
.
thumbnail_location
)
except
NotFoundError
:
pass
# should be in trashcan
self
.
assertIsNotNone
(
content
)
self
.
assertIsNotNone
(
thumbnail
)
# let's restore the asset
restore_asset_from_trashcan
(
'/c4x/edX/full/asset/circuits_duality.gif'
)
# now try to find it in courseware store, and they should be back after restore
content
=
None
thumbnail
=
None
try
:
content
=
content_store
.
find
(
asset_location
)
thumbnail
=
trash_store
.
find
(
content
.
thumbnail_location
)
except
NotFoundError
:
pass
self
.
assertIsNotNone
(
content
)
self
.
assertIsNotNone
(
thumbnail
)
def
test_clone_course
(
self
):
course_data
=
{
...
...
cms/djangoapps/contentstore/views/assets.py
View file @
70ee4b80
...
...
@@ -164,7 +164,6 @@ def remove_asset(request, org, course, name):
get_location_and_verify_access
(
request
,
org
,
course
,
name
)
location
=
request
.
POST
[
'location'
]
logging
.
debug
(
'location = {0}'
.
format
(
location
))
# make sure the location is valid
try
:
...
...
cms/envs/test.py
View file @
70ee4b80
...
...
@@ -70,7 +70,13 @@ CONTENTSTORE = {
'ENGINE'
:
'xmodule.contentstore.mongo.MongoContentStore'
,
'OPTIONS'
:
{
'host'
:
'localhost'
,
'db'
:
'xcontent'
,
'db'
:
'test_xmodule'
,
},
# allow for additional options that can be keyed on a name, e.g. 'trashcan'
'ADDITIONAL_OPTIONS'
:
{
'trashcan'
:
{
'bucket'
:
'trash_fs'
}
}
}
...
...
common/lib/xmodule/xmodule/modulestore/xml_importer.py
View file @
70ee4b80
...
...
@@ -30,7 +30,7 @@ def import_static_content(modules, course_loc, course_data_path, static_content_
try
:
content_path
=
os
.
path
.
join
(
dirname
,
filename
)
if
verbos
e
:
if
Tru
e
:
log
.
debug
(
'importing static content {0}...'
.
format
(
content_path
))
fullname_with_subpath
=
content_path
.
replace
(
static_dir
,
''
)
# strip away leading path from the name
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment