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
8cf4f80d
Commit
8cf4f80d
authored
Oct 11, 2013
by
Don Mitchell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test 100 assets w/ pagination
parent
70f77ce4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
84 additions
and
3 deletions
+84
-3
cms/djangoapps/contentstore/tests/test_assets.py
+84
-3
No files found.
cms/djangoapps/contentstore/tests/test_assets.py
View file @
8cf4f80d
...
@@ -6,19 +6,20 @@ Unit tests for the asset upload endpoint.
...
@@ -6,19 +6,20 @@ Unit tests for the asset upload endpoint.
#pylint: disable=W0621
#pylint: disable=W0621
#pylint: disable=W0212
#pylint: disable=W0212
from
datetime
import
datetime
from
datetime
import
datetime
,
timedelta
from
io
import
BytesIO
from
io
import
BytesIO
from
pytz
import
UTC
from
pytz
import
UTC
import
json
import
re
from
unittest
import
TestCase
,
skip
from
unittest
import
TestCase
,
skip
from
.utils
import
CourseTestCase
from
.utils
import
CourseTestCase
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
from
contentstore.views
import
assets
from
contentstore.views
import
assets
from
xmodule.contentstore.content
import
StaticContent
from
xmodule.contentstore.content
import
StaticContent
,
XASSET_LOCATION_TAG
from
xmodule.modulestore
import
Location
from
xmodule.modulestore
import
Location
from
xmodule.contentstore.django
import
contentstore
from
xmodule.contentstore.django
import
contentstore
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.xml_importer
import
import_from_xml
from
xmodule.modulestore.xml_importer
import
import_from_xml
import
json
class
AssetsTestCase
(
CourseTestCase
):
class
AssetsTestCase
(
CourseTestCase
):
...
@@ -147,3 +148,82 @@ class LockAssetTestCase(CourseTestCase):
...
@@ -147,3 +148,82 @@ class LockAssetTestCase(CourseTestCase):
resp_asset
=
post_asset_update
(
False
)
resp_asset
=
post_asset_update
(
False
)
self
.
assertFalse
(
resp_asset
[
'locked'
])
self
.
assertFalse
(
resp_asset
[
'locked'
])
verify_asset_locked_state
(
False
)
verify_asset_locked_state
(
False
)
class
TestAssetIndex
(
CourseTestCase
):
"""
Test getting asset lists via http (Note, the assets don't actually exist)
"""
def
setUp
(
self
):
"""
Create fake asset entries for the other tests to use
"""
super
(
TestAssetIndex
,
self
)
.
setUp
()
self
.
entry_filter
=
self
.
create_asset_entries
(
contentstore
(),
100
)
def
tearDown
(
self
):
"""
Get rid of the entries
"""
contentstore
()
.
fs_files
.
remove
(
self
.
entry_filter
)
def
create_asset_entries
(
self
,
cstore
,
number
):
"""
Create the fake entries
"""
course_filter
=
Location
(
XASSET_LOCATION_TAG
,
category
=
'asset'
,
course
=
self
.
course
.
location
.
course
,
org
=
self
.
course
.
location
.
org
)
base_entry
=
{
'displayname'
:
'foo.jpg'
,
'chunkSize'
:
262144
,
'length'
:
0
,
'uploadDate'
:
datetime
(
2012
,
1
,
2
,
0
,
0
),
'contentType'
:
'image/jpeg'
,
}
for
i
in
range
(
number
):
base_entry
[
'displayname'
]
=
'{:03x}.jpeg'
.
format
(
i
)
base_entry
[
'uploadDate'
]
+=
timedelta
(
hours
=
i
)
base_entry
[
'_id'
]
=
course_filter
.
replace
(
name
=
base_entry
[
'displayname'
])
.
dict
()
cstore
.
fs_files
.
insert
(
base_entry
)
return
course_filter
.
dict
()
ASSET_LIST_RE
=
re
.
compile
(
r'AssetCollection\((.*)\);$'
,
re
.
MULTILINE
)
def
check_page_content
(
self
,
resp_content
,
entry_count
,
last_date
=
None
):
"""
:param entry_count:
:param last_date:
"""
match
=
self
.
ASSET_LIST_RE
.
search
(
resp_content
)
asset_list
=
json
.
loads
(
match
.
group
(
1
))
self
.
assertEqual
(
len
(
asset_list
),
entry_count
)
for
row
in
asset_list
:
datetext
=
row
[
'date_added'
]
parsed_date
=
datetime
.
strptime
(
datetext
,
"
%
b
%
d,
%
Y at
%
H:
%
M UTC"
)
if
last_date
is
None
:
last_date
=
parsed_date
else
:
self
.
assertGreaterEqual
(
last_date
,
parsed_date
)
return
last_date
def
test_query_assets
(
self
):
"""
The actual test
"""
# get all
asset_url
=
reverse
(
'asset_index'
,
kwargs
=
{
'org'
:
self
.
course
.
location
.
org
,
'course'
:
self
.
course
.
location
.
course
,
'name'
:
self
.
course
.
location
.
name
}
)
resp
=
self
.
client
.
get
(
asset_url
)
self
.
check_page_content
(
resp
.
content
,
100
)
# get first page of 10
resp
=
self
.
client
.
get
(
asset_url
+
"/start/0/max/10"
)
last_date
=
self
.
check_page_content
(
resp
.
content
,
10
)
# get next of 20
resp
=
self
.
client
.
get
(
asset_url
+
"/start/10/max/20"
)
last_date
=
self
.
check_page_content
(
resp
.
content
,
20
,
last_date
)
\ No newline at end of file
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