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
7908d879
Commit
7908d879
authored
Jan 31, 2013
by
Deena Wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more tests for views.py
parent
abc3e5b0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
4 deletions
+28
-4
cms/djangoapps/contentstore/tests/test_views.py
+28
-4
No files found.
cms/djangoapps/contentstore/tests/test_views.py
View file @
7908d879
...
@@ -6,6 +6,7 @@ import unittest
...
@@ -6,6 +6,7 @@ import unittest
from
nose.tools
import
set_trace
from
nose.tools
import
set_trace
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
from
collections
import
defaultdict
from
collections
import
defaultdict
import
re
from
django.http
import
Http404
,
HttpResponse
,
HttpRequest
,
HttpResponseRedirect
,
HttpResponseBadRequest
from
django.http
import
Http404
,
HttpResponse
,
HttpRequest
,
HttpResponseRedirect
,
HttpResponseBadRequest
from
django.conf
import
settings
from
django.conf
import
settings
...
@@ -24,6 +25,7 @@ from xmodule.modulestore import Location
...
@@ -24,6 +25,7 @@ from xmodule.modulestore import Location
from
xmodule.x_module
import
ModuleSystem
from
xmodule.x_module
import
ModuleSystem
from
xmodule.error_module
import
ErrorModule
from
xmodule.error_module
import
ErrorModule
from
contentstore.utils
import
get_course_for_item
from
contentstore.utils
import
get_course_for_item
from
xmodule.templates
import
update_templates
class
Stub
():
class
Stub
():
pass
pass
...
@@ -50,12 +52,14 @@ TEST_DATA_XML_MODULESTORE = xml_store_config(TEST_DATA_DIR)
...
@@ -50,12 +52,14 @@ TEST_DATA_XML_MODULESTORE = xml_store_config(TEST_DATA_DIR)
class
ViewsTestCase
(
TestCase
):
class
ViewsTestCase
(
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
#modulestore().collection.drop()
self
.
_MODULESTORES
=
{}
modulestore
()
.
collection
.
drop
()
update_templates
()
self
.
location
=
[
'i4x'
,
'edX'
,
'toy'
,
'chapter'
,
'Overview'
]
self
.
location
=
[
'i4x'
,
'edX'
,
'toy'
,
'chapter'
,
'Overview'
]
self
.
location_2
=
[
'i4x'
,
'edX'
,
'full'
,
'course'
,
'6.002_Spring_2012'
]
self
.
location_2
=
[
'i4x'
,
'edX'
,
'full'
,
'course'
,
'6.002_Spring_2012'
]
self
.
location_3
=
[
'i4x'
,
'MITx'
,
'999'
,
'course'
,
'Robot_Super_Course'
]
self
.
location_3
=
[
'i4x'
,
'MITx'
,
'999'
,
'course'
,
'Robot_Super_Course'
]
# empty Modulestore
# empty Modulestore
self
.
_MODULESTORES
=
{}
self
.
course_id
=
'edX/toy/2012_Fall'
self
.
course_id
=
'edX/toy/2012_Fall'
self
.
course_id_2
=
'edx/full/6.002_Spring_2012'
self
.
course_id_2
=
'edx/full/6.002_Spring_2012'
# is a CourseDescriptor object?
# is a CourseDescriptor object?
...
@@ -210,6 +214,7 @@ class ViewsTestCase(TestCase):
...
@@ -210,6 +214,7 @@ class ViewsTestCase(TestCase):
self
.
assertEquals
(
s
.
children
[
0
]
.
n
,
1
)
self
.
assertEquals
(
s
.
children
[
0
]
.
n
,
1
)
def
test_get_module_previews
(
self
):
def
test_get_module_previews
(
self
):
raise
SkipTest
# needs a working render_to_string
# needs a working render_to_string
raise
SkipTest
raise
SkipTest
self
.
request
=
RequestFactory
()
.
get
(
'foo'
)
self
.
request
=
RequestFactory
()
.
get
(
'foo'
)
...
@@ -218,6 +223,7 @@ class ViewsTestCase(TestCase):
...
@@ -218,6 +223,7 @@ class ViewsTestCase(TestCase):
print
views
.
get_module_previews
(
self
.
request
,
self
.
course
)
print
views
.
get_module_previews
(
self
.
request
,
self
.
course
)
def
test_delete_item
(
self
):
def
test_delete_item
(
self
):
raise
SkipTest
# If user doesn't have permission, redirect
# If user doesn't have permission, redirect
self
.
no_permit_user
=
MagicMock
(
is_staff
=
False
,
is_active
=
False
)
self
.
no_permit_user
=
MagicMock
(
is_staff
=
False
,
is_active
=
False
)
self
.
no_permit_user
.
is_authenticated
.
return_value
=
True
self
.
no_permit_user
.
is_authenticated
.
return_value
=
True
...
@@ -297,7 +303,7 @@ class ViewsTestCase(TestCase):
...
@@ -297,7 +303,7 @@ class ViewsTestCase(TestCase):
self
.
assertIsInstance
(
views
.
save_item
(
self
.
request_3
),
HttpResponse
)
self
.
assertIsInstance
(
views
.
save_item
(
self
.
request_3
),
HttpResponse
)
self
.
assertEquals
(
modulestore
()
.
get_item
(
self
.
item_2
.
location
.
dict
())
.
definition
[
'data'
],
self
.
assertEquals
(
modulestore
()
.
get_item
(
self
.
item_2
.
location
.
dict
())
.
definition
[
'data'
],
{
u'foo'
:
u'bar'
})
{
u'foo'
:
u'bar'
})
# Test
metadata, which is a dictionary?
# Test
updating metadata
self
.
request_4
=
RequestFactory
()
.
post
(
self
.
item_2
.
location
.
url
())
self
.
request_4
=
RequestFactory
()
.
post
(
self
.
item_2
.
location
.
url
())
self
.
request_4
.
POST
=
self
.
request
.
POST
.
copy
()
self
.
request_4
.
POST
=
self
.
request
.
POST
.
copy
()
self
.
request_4
.
POST
.
update
({
'id'
:
self
.
item_2
.
location
.
url
(),
self
.
request_4
.
POST
.
update
({
'id'
:
self
.
item_2
.
location
.
url
(),
...
@@ -306,7 +312,25 @@ class ViewsTestCase(TestCase):
...
@@ -306,7 +312,25 @@ class ViewsTestCase(TestCase):
self
.
assertIsInstance
(
views
.
save_item
(
self
.
request_4
),
HttpResponse
)
self
.
assertIsInstance
(
views
.
save_item
(
self
.
request_4
),
HttpResponse
)
self
.
assertEquals
(
modulestore
()
.
get_item
(
self
.
item_2
.
location
.
dict
())
.
metadata
[
'foo'
],
self
.
assertEquals
(
modulestore
()
.
get_item
(
self
.
item_2
.
location
.
dict
())
.
metadata
[
'foo'
],
'bar'
)
'bar'
)
def
test_clone_item
(
self
):
# Test that user with no permissions gets redirected
self
.
no_permit_user
=
MagicMock
(
is_staff
=
False
,
is_active
=
False
)
self
.
no_permit_user
.
is_authenticated
.
return_value
=
True
self
.
request
=
RequestFactory
()
.
post
(
self
.
item
.
location
.
url
())
self
.
request
.
POST
=
self
.
request
.
POST
.
copy
()
self
.
request
.
POST
.
update
({
'id'
:
self
.
item
.
location
.
url
(),
'parent_location'
:
self
.
course
.
location
.
url
(),
'template'
:
self
.
location_3
,
'display_name'
:
'bar'
})
self
.
request
.
user
=
self
.
no_permit_user
self
.
assertRaises
(
PermissionDenied
,
views
.
clone_item
,
self
.
request
)
self
.
permit_user
=
MagicMock
(
is_staff
=
True
,
is_active
=
True
)
self
.
permit_user
.
is_authenticated
.
return_value
=
True
self
.
request
.
user
=
self
.
permit_user
response
=
views
.
clone_item
(
self
.
request
)
self
.
assertIsInstance
(
response
,
HttpResponse
)
self
.
assertRegexpMatches
(
response
.
content
,
'{"id": "i4x://MITx/999/course/'
)
def
f
(
x
):
def
f
(
x
):
x
.
n
+=
1
x
.
n
+=
1
...
...
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