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
993b92bc
Commit
993b92bc
authored
Aug 15, 2013
by
Julian Arni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add import tests
parent
7666aad0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
77 additions
and
0 deletions
+77
-0
cms/djangoapps/contentstore/tests/test_assets.py
+77
-0
No files found.
cms/djangoapps/contentstore/tests/test_assets.py
View file @
993b92bc
...
...
@@ -2,7 +2,12 @@
Unit tests for the asset upload endpoint.
"""
import
os
import
json
import
shutil
import
tarfile
import
tempfile
from
subprocess
import
call
from
datetime
import
datetime
from
io
import
BytesIO
from
pytz
import
UTC
...
...
@@ -70,6 +75,78 @@ class UploadTestCase(CourseTestCase):
resp
=
self
.
client
.
get
(
self
.
url
)
self
.
assertEquals
(
resp
.
status_code
,
405
)
class
ImportTestCase
(
CourseTestCase
):
"""
Unit tests for importing a course
"""
def
setUp
(
self
):
super
(
ImportTestCase
,
self
)
.
setUp
()
self
.
url
=
reverse
(
"import_course"
,
kwargs
=
{
'org'
:
self
.
course
.
location
.
org
,
'course'
:
self
.
course
.
location
.
course
,
'name'
:
self
.
course
.
location
.
name
,
})
self
.
content_dir
=
tempfile
.
mkdtemp
()
def
touch
(
name
):
""" Equivalent to shell's 'touch'"""
with
file
(
name
,
'a'
):
os
.
utime
(
name
,
None
)
# Create tar test files
good_dir
=
tempfile
.
mkdtemp
(
dir
=
self
.
content_dir
)
os
.
makedirs
(
os
.
path
.
join
(
good_dir
,
"course"
))
with
open
(
os
.
path
.
join
(
good_dir
,
"course.xml"
)
,
"w+"
)
as
f
:
f
.
write
(
'<course url_name="2013_Spring" org="EDx" course="0.00x"/>'
)
with
open
(
os
.
path
.
join
(
good_dir
,
"course"
,
"2013_Spring.xml"
),
"w+"
)
as
f
:
f
.
write
(
'<course></course>'
)
self
.
good_tar
=
os
.
path
.
join
(
self
.
content_dir
,
"good.tar.gz"
)
with
tarfile
.
open
(
self
.
good_tar
,
"w:gz"
)
as
gtar
:
gtar
.
add
(
good_dir
)
bad_dir
=
tempfile
.
mkdtemp
(
dir
=
self
.
content_dir
)
touch
(
os
.
path
.
join
(
bad_dir
,
"bad.xml"
))
self
.
bad_tar
=
os
.
path
.
join
(
self
.
content_dir
,
"bad.tar.gz"
)
with
tarfile
.
open
(
self
.
bad_tar
,
"w:gz"
)
as
btar
:
btar
.
add
(
bad_dir
)
def
tearDown
(
self
):
shutil
.
rmtree
(
self
.
content_dir
)
def
test_no_coursexml
(
self
):
"""
Check that the response for a tar.gz import without a course.xml is
correct.
"""
with
open
(
self
.
bad_tar
)
as
btar
:
resp
=
self
.
client
.
post
(
self
.
url
,
{
"name"
:
self
.
bad_tar
,
"course-data"
:
[
btar
]
})
self
.
assertEquals
(
resp
.
status_code
,
415
)
def
test_with_coursexml
(
self
):
"""
Check that the response for a tar.gz import with a course.xml is
correct.
"""
with
open
(
self
.
good_tar
)
as
gtar
:
resp
=
self
.
client
.
post
(
self
.
url
,
{
"name"
:
self
.
good_tar
,
"course-data"
:
[
gtar
]
})
self
.
assert2XX
(
resp
.
status_code
)
class
AssetsToJsonTestCase
(
TestCase
):
"""
...
...
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