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
7e29a5a6
Commit
7e29a5a6
authored
Sep 22, 2014
by
Usman Khalid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added tests for parse_range_header() in contentserver.
PLAT-104
parent
ec508f59
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
2 deletions
+60
-2
common/djangoapps/contentserver/tests/test.py
+60
-2
No files found.
common/djangoapps/contentserver/tests/test.py
View file @
7e29a5a6
...
@@ -3,20 +3,22 @@ Tests for StaticContentServer
...
@@ -3,20 +3,22 @@ Tests for StaticContentServer
"""
"""
import
copy
import
copy
import
logging
import
logging
import
unittest
from
uuid
import
uuid4
from
uuid
import
uuid4
from
django.conf
import
settings
from
django.conf
import
settings
from
django.test.client
import
Client
from
django.test.client
import
Client
from
django.test.utils
import
override_settings
from
django.test.utils
import
override_settings
from
student.models
import
CourseEnrollment
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
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
from
xmodule.modulestore.xml_importer
import
import_from_xml
from
xmodule.modulestore.xml_importer
import
import_from_xml
from
contentserver.middleware
import
parse_range_header
from
student.models
import
CourseEnrollment
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
TEST_DATA_CONTENTSTORE
=
copy
.
deepcopy
(
settings
.
CONTENTSTORE
)
TEST_DATA_CONTENTSTORE
=
copy
.
deepcopy
(
settings
.
CONTENTSTORE
)
...
@@ -208,3 +210,59 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
...
@@ -208,3 +210,59 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
)
)
self
.
assertEqual
(
resp
.
status_code
,
416
)
self
.
assertEqual
(
resp
.
status_code
,
416
)
class
ParseRangeHeaderTestCase
(
unittest
.
TestCase
):
"""
Tests for the parse_range_header function.
"""
def
setUp
(
self
):
self
.
content_length
=
10000
def
test_bytes_unit
(
self
):
unit
,
__
=
parse_range_header
(
'bytes=100-'
,
self
.
content_length
)
self
.
assertEqual
(
unit
,
'bytes'
)
def
test_invalid_syntax
(
self
):
self
.
assertRaisesRegexp
(
ValueError
,
'Invalid syntax'
,
parse_range_header
,
'bytes'
,
self
.
content_length
)
self
.
assertRaisesRegexp
(
ValueError
,
'Invalid syntax'
,
parse_range_header
,
'bytes='
,
self
.
content_length
)
self
.
assertRaisesRegexp
(
ValueError
,
'too many values to unpack'
,
parse_range_header
,
'bytes=0='
,
self
.
content_length
)
self
.
assertRaisesRegexp
(
ValueError
,
'Invalid syntax'
,
parse_range_header
,
'bytes=0'
,
self
.
content_length
)
self
.
assertRaisesRegexp
(
ValueError
,
'Invalid syntax'
,
parse_range_header
,
'bytes=0-10,0'
,
self
.
content_length
)
def
test_byte_range_spec
(
self
):
__
,
ranges
=
parse_range_header
(
'bytes=100-'
,
self
.
content_length
)
self
.
assertEqual
(
len
(
ranges
),
1
)
self
.
assertEqual
(
ranges
[
0
],
(
100
,
9999
))
__
,
ranges
=
parse_range_header
(
'bytes=1000-'
,
self
.
content_length
)
self
.
assertEqual
(
len
(
ranges
),
1
)
self
.
assertEqual
(
ranges
[
0
],
(
1000
,
9999
))
__
,
ranges
=
parse_range_header
(
'bytes=100-199, 200-'
,
self
.
content_length
)
self
.
assertEqual
(
len
(
ranges
),
2
)
self
.
assertEqual
(
ranges
,
[(
100
,
199
),
(
200
,
9999
)])
__
,
ranges
=
parse_range_header
(
'bytes=100-199, 200-499'
,
self
.
content_length
)
self
.
assertEqual
(
len
(
ranges
),
2
)
self
.
assertEqual
(
ranges
,
[(
100
,
199
),
(
200
,
499
)])
self
.
assertRaisesRegexp
(
ValueError
,
'invalid literal for int()'
,
parse_range_header
,
'bytes=one-20'
,
self
.
content_length
)
def
test_suffix_byte_range_spec
(
self
):
__
,
ranges
=
parse_range_header
(
'bytes=-100'
,
self
.
content_length
)
self
.
assertEqual
(
len
(
ranges
),
1
)
self
.
assertEqual
(
ranges
[
0
],
(
9900
,
9999
))
__
,
ranges
=
parse_range_header
(
'bytes=-100, -200'
,
self
.
content_length
)
self
.
assertEqual
(
len
(
ranges
),
2
)
self
.
assertEqual
(
ranges
,
[(
9900
,
9999
),
(
9800
,
9999
)])
self
.
assertRaisesRegexp
(
ValueError
,
'invalid literal for int()'
,
parse_range_header
,
'bytes=-one'
,
self
.
content_length
)
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