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
f306c4d7
Commit
f306c4d7
authored
Jan 07, 2014
by
Andy Armstrong
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2101 from edx/andya/pagination-test-fix
Fix pagination test failures
parents
536d8242
100ace64
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
28 deletions
+43
-28
cms/djangoapps/contentstore/tests/test_assets.py
+42
-27
cms/djangoapps/contentstore/tests/utils.py
+1
-1
No files found.
cms/djangoapps/contentstore/tests/test_assets.py
View file @
f306c4d7
...
...
@@ -24,11 +24,21 @@ from xmodule.modulestore.mongo.base import location_to_query
class
AssetsTestCase
(
CourseTestCase
):
"""
Parent class for all asset tests.
"""
def
setUp
(
self
):
super
(
AssetsTestCase
,
self
)
.
setUp
()
location
=
loc_mapper
()
.
translate_location
(
self
.
course
.
location
.
course_id
,
self
.
course
.
location
,
False
,
True
)
self
.
url
=
location
.
url_reverse
(
'assets/'
,
''
)
def
upload_asset
(
self
,
name
=
"asset-1"
):
f
=
BytesIO
(
name
)
f
.
name
=
name
+
".txt"
return
self
.
client
.
post
(
self
.
url
,
{
"name"
:
name
,
"file"
:
f
})
class
BasicAssetsTestCase
(
AssetsTestCase
):
def
test_basic
(
self
):
resp
=
self
.
client
.
get
(
self
.
url
,
HTTP_ACCEPT
=
'text/html'
)
self
.
assertEquals
(
resp
.
status_code
,
200
)
...
...
@@ -38,12 +48,7 @@ class AssetsTestCase(CourseTestCase):
path
=
StaticContent
.
get_static_path_from_location
(
location
)
self
.
assertEquals
(
path
,
'/static/my_file_name.jpg'
)
class
AssetsToyCourseTestCase
(
CourseTestCase
):
"""
Tests the assets returned from assets_handler for the toy test course.
"""
def
test_toy_assets
(
self
):
def
test_pdf_asset
(
self
):
module_store
=
modulestore
(
'direct'
)
_
,
course_items
=
import_from_xml
(
module_store
,
...
...
@@ -56,14 +61,35 @@ class AssetsToyCourseTestCase(CourseTestCase):
location
=
loc_mapper
()
.
translate_location
(
course
.
location
.
course_id
,
course
.
location
,
False
,
True
)
url
=
location
.
url_reverse
(
'assets/'
,
''
)
self
.
assert_correct_asset_response
(
url
,
0
,
3
,
3
)
self
.
assert_correct_asset_response
(
url
+
"?page_size=2"
,
0
,
2
,
3
)
self
.
assert_correct_asset_response
(
url
+
"?page_size=2&page=1"
,
2
,
1
,
3
)
# Test valid contentType for pdf asset (textbook.pdf)
resp
=
self
.
client
.
get
(
url
,
HTTP_ACCEPT
=
'application/json'
)
self
.
assertContains
(
resp
,
"/c4x/edX/toy/asset/textbook.pdf"
)
asset_location
=
StaticContent
.
get_location_from_path
(
'/c4x/edX/toy/asset/textbook.pdf'
)
content
=
contentstore
()
.
find
(
asset_location
)
# Check after import textbook.pdf has valid contentType ('application/pdf')
# Note: Actual contentType for textbook.pdf in asset.json is 'text/pdf'
self
.
assertEqual
(
content
.
content_type
,
'application/pdf'
)
class
PaginationTestCase
(
AssetsTestCase
):
"""
Tests the pagination of assets returned from the REST API.
"""
def
test_json_responses
(
self
):
self
.
upload_asset
(
"asset-1"
)
self
.
upload_asset
(
"asset-2"
)
self
.
upload_asset
(
"asset-3"
)
# Verify valid page requests
self
.
assert_correct_asset_response
(
self
.
url
,
0
,
3
,
3
)
self
.
assert_correct_asset_response
(
self
.
url
+
"?page_size=2"
,
0
,
2
,
3
)
self
.
assert_correct_asset_response
(
self
.
url
+
"?page_size=2&page=1"
,
2
,
1
,
3
)
# Verify querying outside the range of valid pages
self
.
assert_correct_asset_response
(
url
+
"?page_size=2&page=-1"
,
0
,
2
,
3
)
self
.
assert_correct_asset_response
(
url
+
"?page_size=2&page=2"
,
2
,
1
,
3
)
self
.
assert_correct_asset_response
(
url
+
"?page_size=3&page=1"
,
0
,
3
,
3
)
self
.
assert_correct_asset_response
(
self
.
url
+
"?page_size=2&page=-1"
,
0
,
2
,
3
)
self
.
assert_correct_asset_response
(
self
.
url
+
"?page_size=2&page=2"
,
2
,
1
,
3
)
self
.
assert_correct_asset_response
(
self
.
url
+
"?page_size=3&page=1"
,
0
,
3
,
3
)
def
assert_correct_asset_response
(
self
,
url
,
expected_start
,
expected_length
,
expected_total
):
resp
=
self
.
client
.
get
(
url
,
HTTP_ACCEPT
=
'application/json'
)
...
...
@@ -73,16 +99,8 @@ class AssetsToyCourseTestCase(CourseTestCase):
self
.
assertEquals
(
len
(
assets
),
expected_length
)
self
.
assertEquals
(
json_response
[
'totalCount'
],
expected_total
)
# Test valid contentType for pdf asset (textbook.pdf)
self
.
assertContains
(
resp
,
"/c4x/edX/toy/asset/textbook.pdf"
)
asset_location
=
StaticContent
.
get_location_from_path
(
'/c4x/edX/toy/asset/textbook.pdf'
)
content
=
contentstore
()
.
find
(
asset_location
)
# Check after import textbook.pdf has valid contentType ('application/pdf')
# Note: Actual contentType for textbook.pdf in asset.json is 'text/pdf'
self
.
assertEqual
(
content
.
content_type
,
'application/pdf'
)
class
UploadTestCase
(
Course
TestCase
):
class
UploadTestCase
(
Assets
TestCase
):
"""
Unit tests for uploading a file
"""
...
...
@@ -91,11 +109,8 @@ class UploadTestCase(CourseTestCase):
location
=
loc_mapper
()
.
translate_location
(
self
.
course
.
location
.
course_id
,
self
.
course
.
location
,
False
,
True
)
self
.
url
=
location
.
url_reverse
(
'assets/'
,
''
)
@skip
(
"CorruptGridFile error on continuous integration server"
)
def
test_happy_path
(
self
):
f
=
BytesIO
(
"sample content"
)
f
.
name
=
"sample.txt"
resp
=
self
.
client
.
post
(
self
.
url
,
{
"name"
:
"my-name"
,
"file"
:
f
})
resp
=
self
.
upload_asset
()
self
.
assertEquals
(
resp
.
status_code
,
200
)
def
test_no_file
(
self
):
...
...
@@ -103,7 +118,7 @@ class UploadTestCase(CourseTestCase):
self
.
assertEquals
(
resp
.
status_code
,
400
)
class
AssetToJsonTestCase
(
TestCase
):
class
AssetToJsonTestCase
(
Assets
TestCase
):
"""
Unit test for transforming asset information into something
we can send out to the client via JSON.
...
...
@@ -128,7 +143,7 @@ class AssetToJsonTestCase(TestCase):
self
.
assertIsNone
(
output
[
"thumbnail"
])
class
LockAssetTestCase
(
Course
TestCase
):
class
LockAssetTestCase
(
Assets
TestCase
):
"""
Unit test for locking and unlocking an asset.
"""
...
...
cms/djangoapps/contentstore/tests/utils.py
View file @
f306c4d7
...
...
@@ -72,7 +72,7 @@ class CourseTestCase(ModuleStoreTestCase):
email
=
'test+courses@edx.org'
password
=
'foo'
# Create the use so we can log them in.
# Create the use
r
so we can log them in.
self
.
user
=
User
.
objects
.
create_user
(
uname
,
email
,
password
)
# Note that we do not actually need to do anything
...
...
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