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
d9fdccb5
Commit
d9fdccb5
authored
Jan 29, 2013
by
Deena Wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
testing testing tests
parent
85c412fc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
12 deletions
+42
-12
cms/djangoapps/contentstore/tests/test_views.py
+39
-6
lms/djangoapps/courseware/tests/test_module_render.py
+3
-6
No files found.
cms/djangoapps/contentstore/tests/test_views.py
View file @
d9fdccb5
...
@@ -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
from
django.http
import
Http404
,
HttpResponse
,
HttpRequest
,
HttpResponseRedirect
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
...
@@ -14,9 +14,12 @@ from django.conf import settings
...
@@ -14,9 +14,12 @@ from django.conf import settings
from
django.test
import
TestCase
from
django.test
import
TestCase
from
django.test.client
import
RequestFactory
from
django.test.client
import
RequestFactory
from
override_settings
import
override_settings
from
override_settings
import
override_settings
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
XModuleCourseFactory
,
CourseFactory
def
xml_store_config
(
data_dir
):
def
xml_store_config
(
data_dir
):
...
@@ -39,16 +42,46 @@ class UserFactory(factory.Factory):
...
@@ -39,16 +42,46 @@ class UserFactory(factory.Factory):
TEST_DATA_DIR
=
settings
.
COMMON_TEST_DATA_ROOT
TEST_DATA_DIR
=
settings
.
COMMON_TEST_DATA_ROOT
TEST_DATA_XML_MODULESTORE
=
xml_store_config
(
TEST_DATA_DIR
)
TEST_DATA_XML_MODULESTORE
=
xml_store_config
(
TEST_DATA_DIR
)
@override_settings
(
MODULESTORE
=
TEST_DATA_XML_MODULESTORE
)
class
ViewsTestCase
(
TestCase
):
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'
]
# 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
.
toy_course
=
modulestore
()
.
get_course
(
self
.
course_id
)
self
.
toy_course
=
modulestore
()
.
get_course
(
self
.
course_id
)
def
test_has_access
(
self
):
def
test_has_access
(
self
):
user
=
UserFactory
()
user
=
MagicMock
(
is_staff
=
True
,
is_active
=
True
,
is_authenticated
=
True
)
user
.
is_authenticated
=
True
m
=
MagicMock
()
set_trace
()
m
.
count
.
return_value
=
1
self
.
assertTrue
(
views
.
has_access
(
user
,
self
.
location
))
user
.
groups
.
filter
.
return_value
=
m
self
.
assertTrue
(
views
.
has_access
(
user
,
self
.
location_2
))
user
.
is_authenticated
=
False
self
.
assertFalse
(
views
.
has_access
(
user
,
self
.
location_2
))
def
test_course_index
(
self
):
# UserFactory doesn't work?
self
.
user
=
MagicMock
(
is_staff
=
False
,
is_active
=
False
)
self
.
user
.
is_authenticated
.
return_value
=
False
request
=
MagicMock
(
user
=
self
.
user
)
# Instead of raising exception when has_access is False, redirects
self
.
assertIsInstance
(
views
.
course_index
(
request
,
'edX'
,
'full'
,
'6.002_Spring_2012'
),
HttpResponseRedirect
)
self
.
user_2
=
MagicMock
(
is_staff
=
True
,
is_active
=
True
)
self
.
user_2
.
is_authenticated
.
return_value
=
True
request_2
=
MagicMock
(
user
=
self
.
user_2
)
# Bug? Raises error because calls modulestore().get_item(location)
#NotImplementedError: XMLModuleStores can't guarantee that definitions
#are unique. Use get_instance.
print
views
.
course_index
(
request_2
,
'edX'
,
'full'
,
'6.002_Spring_2012'
)
def
test_edit_subsection
(
self
):
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_subscription
(
self
.
request
,
self
.
location_2
),
HttpResponseRedirect
)
lms/djangoapps/courseware/tests/test_module_render.py
View file @
d9fdccb5
...
@@ -107,8 +107,7 @@ class ModuleRenderTestCase(PageLoader):
...
@@ -107,8 +107,7 @@ class ModuleRenderTestCase(PageLoader):
mock_user_2
=
MagicMock
(
User
)
mock_user_2
=
MagicMock
(
User
)
mock_user_2
.
is_authenticated
.
return_value
=
True
mock_user_2
.
is_authenticated
.
return_value
=
True
mock_module
=
MagicMock
()
mock_module
=
MagicMock
(
shared_state_key
=
'key'
)
mock_module
.
shared_state_key
=
'key'
mock_module
.
location
=
Location
(
'i4x'
,
'edX'
,
'toy'
,
'chapter'
,
'Overview'
)
mock_module
.
location
=
Location
(
'i4x'
,
'edX'
,
'toy'
,
'chapter'
,
'Overview'
)
mock_module
.
get_shared_state
.
return_value
=
'{}'
mock_module
.
get_shared_state
.
return_value
=
'{}'
mock_cache
=
MagicMock
()
mock_cache
=
MagicMock
()
...
@@ -197,11 +196,9 @@ class ModuleRenderTestCase(PageLoader):
...
@@ -197,11 +196,9 @@ class ModuleRenderTestCase(PageLoader):
# keep going
# keep going
def
test_preview_chemcalc
(
self
):
def
test_preview_chemcalc
(
self
):
mock_request
=
MagicMock
()
mock_request
=
MagicMock
(
method
=
'notGET'
)
mock_request
.
method
=
'notGET'
self
.
assertRaises
(
Http404
,
render
.
preview_chemcalc
,
mock_request
)
self
.
assertRaises
(
Http404
,
render
.
preview_chemcalc
,
mock_request
)
mock_request_2
=
MagicMock
()
mock_request_2
=
MagicMock
(
method
=
'GET'
)
mock_request_2
.
method
=
'GET'
mock_request_2
.
GET
.
get
.
return_value
=
None
mock_request_2
.
GET
.
get
.
return_value
=
None
self
.
assertEquals
(
render
.
preview_chemcalc
(
mock_request_2
)
.
content
,
self
.
assertEquals
(
render
.
preview_chemcalc
(
mock_request_2
)
.
content
,
json
.
dumps
({
'preview'
:
''
,
json
.
dumps
({
'preview'
:
''
,
...
...
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