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
cdbe9857
Commit
cdbe9857
authored
Jan 30, 2013
by
Deena Wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests in cms.djangoapps.contentstore/tests/test_views.py
parent
38583621
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
9 deletions
+53
-9
cms/djangoapps/contentstore/tests/test_views.py
+53
-9
No files found.
cms/djangoapps/contentstore/tests/test_views.py
View file @
cdbe9857
...
@@ -6,7 +6,7 @@ import unittest
...
@@ -6,7 +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
django.http
import
Http404
,
HttpResponse
,
HttpRequest
,
HttpResponseRedirect
from
django.http
import
Http404
,
HttpResponse
,
HttpRequest
,
HttpResponseRedirect
,
HttpResponseBadRequest
from
django.conf
import
settings
from
django.conf
import
settings
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.test.client
import
Client
from
django.test.client
import
Client
...
@@ -18,8 +18,8 @@ from django.core.exceptions import PermissionDenied
...
@@ -18,8 +18,8 @@ from django.core.exceptions import PermissionDenied
from
xmodule.modulestore.django
import
modulestore
,
_MODULESTORES
from
xmodule.modulestore.django
import
modulestore
,
_MODULESTORES
import
contentstore.views
as
views
import
contentstore.views
as
views
import
auth.authz
as
a
from
contentstore.tests.factories
import
CourseFactory
,
ItemFactory
from
contentstore.tests.factories
import
XModuleCourseFactory
,
CourseFactory
from
xmodule.modulestore
import
Location
def
xml_store_config
(
data_dir
):
def
xml_store_config
(
data_dir
):
...
@@ -46,17 +46,21 @@ class ViewsTestCase(TestCase):
...
@@ -46,17 +46,21 @@ class ViewsTestCase(TestCase):
def
setUp
(
self
):
def
setUp
(
self
):
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'
]
# empty Modulestore
# empty Modulestore
self
.
_MODULESTORES
=
{}
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'
#self.toy_course = modulestore().get_course(self.course_id)
#self.toy_course = modulestore().get_course(self.course_id)
# Problem: Classes persist, need to delete stuff from modulestore
# Problem: Classes persist, need to delete stuff from modulestore
# is a CourseDescriptor object?
self
.
course
=
CourseFactory
.
create
()
self
.
course
=
CourseFactory
.
create
()
print
dir
(
self
.
course
)
# is a sequence descriptor
self
.
item
=
ItemFactory
.
create
(
template
=
'i4x://edx/templates/sequential/Empty'
)
def
tearDown
(
self
):
def
tearDown
(
self
):
pass
_MODULESTORES
=
{}
modulestore
()
.
collection
.
drop
()
def
test_has_access
(
self
):
def
test_has_access
(
self
):
user
=
MagicMock
(
is_staff
=
True
,
is_active
=
True
,
is_authenticated
=
True
)
user
=
MagicMock
(
is_staff
=
True
,
is_active
=
True
,
is_authenticated
=
True
)
...
@@ -72,15 +76,15 @@ class ViewsTestCase(TestCase):
...
@@ -72,15 +76,15 @@ class ViewsTestCase(TestCase):
self
.
user
=
MagicMock
(
is_staff
=
False
,
is_active
=
False
)
self
.
user
=
MagicMock
(
is_staff
=
False
,
is_active
=
False
)
self
.
user
.
is_authenticated
.
return_value
=
False
self
.
user
.
is_authenticated
.
return_value
=
False
request
=
MagicMock
(
user
=
self
.
user
)
request
=
MagicMock
(
user
=
self
.
user
)
#
Instead of raising exception when has_access is False, redirects
#
Redirects if request.user doesn't have access to location
self
.
assertIsInstance
(
views
.
course_index
(
request
,
'edX'
,
self
.
assertIsInstance
(
views
.
course_index
(
request
,
'edX'
,
'full'
,
'6.002_Spring_2012'
),
HttpResponseRedirect
)
'full'
,
'6.002_Spring_2012'
),
HttpResponseRedirect
)
self
.
user_2
=
MagicMock
(
is_staff
=
True
,
is_active
=
True
)
self
.
user_2
=
MagicMock
(
is_staff
=
True
,
is_active
=
True
)
self
.
user_2
.
is_authenticated
.
return_value
=
True
self
.
user_2
.
is_authenticated
.
return_value
=
True
request_2
=
MagicMock
(
user
=
self
.
user_2
)
request_2
=
MagicMock
(
user
=
self
.
user_2
)
#
Need to use XModuleStoreFactory?
#
Doesn't work unless we figure out render_to_response
print
views
.
course_index
(
request_2
,
'edX
'
,
## views.course_index(request_2, 'MITx
',
'full'
,
'6.002_Spring_2012
'
)
## '999', 'Robot_Super_Course
')
def
test_edit_subsection
(
self
):
def
test_edit_subsection
(
self
):
# Redirects if request.user doesn't have access to location
# Redirects if request.user doesn't have access to location
...
@@ -89,4 +93,44 @@ class ViewsTestCase(TestCase):
...
@@ -89,4 +93,44 @@ class ViewsTestCase(TestCase):
self
.
request
=
MagicMock
(
user
=
self
.
user
)
self
.
request
=
MagicMock
(
user
=
self
.
user
)
self
.
assertIsInstance
(
views
.
edit_subsection
(
self
.
request
,
self
.
location_2
),
self
.
assertIsInstance
(
views
.
edit_subsection
(
self
.
request
,
self
.
location_2
),
HttpResponseRedirect
)
HttpResponseRedirect
)
# If location isn't for a "sequential", return Bad Request
self
.
user_2
=
MagicMock
(
is_staff
=
True
,
is_active
=
True
)
self
.
user_2
.
is_authenticated
.
return_value
=
True
self
.
request_2
=
MagicMock
(
user
=
self
.
user_2
)
self
.
assertIsInstance
(
views
.
edit_subsection
(
self
.
request_2
,
self
.
location_3
),
HttpResponseBadRequest
)
# Need render_to_response
#views.edit_subsection(self.request_2, self.item.location)
def
test_edit_unit
(
self
):
# if user doesn't have access, should redirect
self
.
user
=
MagicMock
(
is_staff
=
False
,
is_active
=
False
)
self
.
user
.
is_authenticated
.
return_value
=
False
self
.
request
=
MagicMock
(
user
=
self
.
user
)
self
.
assertIsInstance
(
views
.
edit_unit
(
self
.
request
,
self
.
location_2
),
HttpResponseRedirect
)
def
test_assignment_type_update
(
self
):
# If user doesn't have access, should redirect
self
.
user
=
MagicMock
(
is_staff
=
False
,
is_active
=
False
)
self
.
user
.
is_authenticated
.
return_value
=
False
self
.
request
=
RequestFactory
()
.
get
(
'foo'
)
self
.
request
.
user
=
self
.
user
self
.
assertIsInstance
(
views
.
assignment_type_update
(
self
.
request
,
'MITx'
,
'999'
,
'course'
,
'Robot_Super_Course'
),
HttpResponseRedirect
)
# if user has access, then should return HttpResponse
self
.
user_2
=
MagicMock
(
is_staff
=
True
,
is_active
=
True
)
self
.
user_2
.
is_authenticated
.
return_value
=
True
self
.
request
.
user
=
self
.
user_2
get_response
=
views
.
assignment_type_update
(
self
.
request
,
'MITx'
,
'999'
,
'course'
,
'Robot_Super_Course'
)
self
.
assertIsInstance
(
get_response
,
HttpResponse
)
get_response_string
=
'{"id": 99, "location": ["i4x", "MITx", "999", "course", "Robot_Super_Course", null], "graderType": "Not Graded"}'
self
.
assertEquals
(
get_response
.
content
,
get_response_string
)
self
.
request_2
=
RequestFactory
()
.
post
(
'foo'
)
self
.
request_2
.
user
=
self
.
user_2
post_response
=
views
.
assignment_type_update
(
self
.
request_2
,
'MITx'
,
'999'
,
'course'
,
'Robot_Super_Course'
)
self
.
assertIsInstance
(
post_response
,
HttpResponse
)
self
.
assertEquals
(
post_response
.
content
,
'null'
)
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