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
b0a01819
Commit
b0a01819
authored
Mar 05, 2013
by
Jay Zoldak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pep8 fixes for tests
parent
cee24c5c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
167 additions
and
178 deletions
+167
-178
lms/djangoapps/courseware/tests/test_access.py
+5
-6
lms/djangoapps/courseware/tests/test_module_render.py
+50
-47
lms/djangoapps/courseware/tests/test_progress.py
+52
-53
lms/djangoapps/courseware/tests/test_views.py
+17
-14
lms/djangoapps/courseware/tests/tests.py
+43
-58
No files found.
lms/djangoapps/courseware/tests/test_access.py
View file @
b0a01819
import
unittest
import
unittest
import
logging
import
logging
import
time
import
time
from
mock
import
Mock
,
MagicMock
,
patch
from
mock
import
Mock
,
MagicMock
,
patch
from
django.conf
import
settings
from
django.conf
import
settings
from
django.test
import
TestCase
from
django.test
import
TestCase
from
xmodule.course_module
import
CourseDescriptor
from
xmodule.course_module
import
CourseDescriptor
from
xmodule.error_module
import
ErrorDescriptor
from
xmodule.error_module
import
ErrorDescriptor
from
xmodule.modulestore
import
Location
from
xmodule.modulestore
import
Location
from
xmodule.timeparse
import
parse_time
from
xmodule.timeparse
import
parse_time
from
xmodule.x_module
import
XModule
,
XModuleDescriptor
from
xmodule.x_module
import
XModule
,
XModuleDescriptor
import
courseware.access
as
access
import
courseware.access
as
access
from
factories
import
CourseEnrollmentAllowedFactory
from
factories
import
CourseEnrollmentAllowedFactory
class
AccessTestCase
(
TestCase
):
class
AccessTestCase
(
TestCase
):
def
test__has_global_staff_access
(
self
):
def
test__has_global_staff_access
(
self
):
u
=
Mock
(
is_staff
=
False
)
u
=
Mock
(
is_staff
=
False
)
...
...
lms/djangoapps/courseware/tests/test_module_render.py
View file @
b0a01819
...
@@ -12,39 +12,42 @@ from django.test.client import Client
...
@@ -12,39 +12,42 @@ from django.test.client import Client
from
django.conf
import
settings
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
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
from
django.test.utils
import
override_settings
from
django.test.utils
import
override_settings
from
courseware.models
import
StudentModule
,
StudentModuleCache
from
courseware.models
import
StudentModule
,
StudentModuleCache
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
from
xmodule.exceptions
import
NotFoundError
from
xmodule.exceptions
import
NotFoundError
from
xmodule.modulestore
import
Location
from
xmodule.modulestore
import
Location
import
courseware.module_render
as
render
import
courseware.module_render
as
render
from
xmodule.modulestore.django
import
modulestore
,
_MODULESTORES
from
xmodule.modulestore.django
import
modulestore
,
_MODULESTORES
from
xmodule.seq_module
import
SequenceModule
from
xmodule.seq_module
import
SequenceModule
from
courseware.tests.tests
import
PageLoader
from
courseware.tests.tests
import
PageLoader
from
student.models
import
Registration
from
student.models
import
Registration
from
factories
import
UserFactory
from
factories
import
UserFactory
class
Stub
:
class
Stub
:
def
__init__
(
self
):
def
__init__
(
self
):
pass
pass
def
xml_store_config
(
data_dir
):
def
xml_store_config
(
data_dir
):
return
{
return
{
'default'
:
{
'default'
:
{
'ENGINE'
:
'xmodule.modulestore.xml.XMLModuleStore'
,
'ENGINE'
:
'xmodule.modulestore.xml.XMLModuleStore'
,
'OPTIONS'
:
{
'OPTIONS'
:
{
'data_dir'
:
data_dir
,
'data_dir'
:
data_dir
,
'default_class'
:
'xmodule.hidden_module.HiddenDescriptor'
,
'default_class'
:
'xmodule.hidden_module.HiddenDescriptor'
,
}
}
}
}
}
}
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
)
@override_settings
(
MODULESTORE
=
TEST_DATA_XML_MODULESTORE
)
class
ModuleRenderTestCase
(
PageLoader
):
class
ModuleRenderTestCase
(
PageLoader
):
def
setUp
(
self
):
def
setUp
(
self
):
...
@@ -54,8 +57,8 @@ class ModuleRenderTestCase(PageLoader):
...
@@ -54,8 +57,8 @@ class ModuleRenderTestCase(PageLoader):
self
.
toy_course
=
modulestore
()
.
get_course
(
self
.
course_id
)
self
.
toy_course
=
modulestore
()
.
get_course
(
self
.
course_id
)
def
test_get_module
(
self
):
def
test_get_module
(
self
):
self
.
assertIsNone
(
render
.
get_module
(
'dummyuser'
,
None
,
\
self
.
assertIsNone
(
render
.
get_module
(
'dummyuser'
,
None
,
'invalid location'
,
None
,
None
))
'invalid location'
,
None
,
None
))
def
test_get_instance_module
(
self
):
def
test_get_instance_module
(
self
):
mock_user
=
MagicMock
()
mock_user
=
MagicMock
()
...
@@ -67,17 +70,17 @@ class ModuleRenderTestCase(PageLoader):
...
@@ -67,17 +70,17 @@ class ModuleRenderTestCase(PageLoader):
mock_module
=
MagicMock
()
mock_module
=
MagicMock
()
mock_module
.
descriptor
.
stores_state
=
False
mock_module
.
descriptor
.
stores_state
=
False
self
.
assertIsNone
(
render
.
get_instance_module
(
'dummy'
,
mock_user_2
,
self
.
assertIsNone
(
render
.
get_instance_module
(
'dummy'
,
mock_user_2
,
mock_module
,
'dummy'
))
mock_module
,
'dummy'
))
def
test_modx_dispatch
(
self
):
def
test_modx_dispatch
(
self
):
self
.
assertRaises
(
Http404
,
render
.
modx_dispatch
,
'dummy'
,
'dummy'
,
self
.
assertRaises
(
Http404
,
render
.
modx_dispatch
,
'dummy'
,
'dummy'
,
'invalid Location'
,
'dummy'
)
'invalid Location'
,
'dummy'
)
mock_request
=
MagicMock
()
mock_request
=
MagicMock
()
mock_request
.
FILES
.
keys
.
return_value
=
[
'file_id'
]
mock_request
.
FILES
.
keys
.
return_value
=
[
'file_id'
]
mock_request
.
FILES
.
getlist
.
return_value
=
[
'file'
]
*
(
settings
.
MAX_FILEUPLOADS_PER_INPUT
+
1
)
mock_request
.
FILES
.
getlist
.
return_value
=
[
'file'
]
*
(
settings
.
MAX_FILEUPLOADS_PER_INPUT
+
1
)
self
.
assertEquals
(
render
.
modx_dispatch
(
mock_request
,
'dummy'
,
self
.
location
,
self
.
assertEquals
(
render
.
modx_dispatch
(
mock_request
,
'dummy'
,
self
.
location
,
'dummy'
)
.
content
,
'dummy'
)
.
content
,
json
.
dumps
({
'success'
:
'Submission aborted! Maximum
%
d files may be submitted at once'
%
\
json
.
dumps
({
'success'
:
'Submission aborted! Maximum
%
d files may be submitted at once'
%
settings
.
MAX_FILEUPLOADS_PER_INPUT
}))
settings
.
MAX_FILEUPLOADS_PER_INPUT
}))
mock_request_2
=
MagicMock
()
mock_request_2
=
MagicMock
()
mock_request_2
.
FILES
.
keys
.
return_value
=
[
'file_id'
]
mock_request_2
.
FILES
.
keys
.
return_value
=
[
'file_id'
]
...
@@ -88,8 +91,8 @@ class ModuleRenderTestCase(PageLoader):
...
@@ -88,8 +91,8 @@ class ModuleRenderTestCase(PageLoader):
mock_request_2
.
FILES
.
getlist
.
return_value
=
filelist
mock_request_2
.
FILES
.
getlist
.
return_value
=
filelist
self
.
assertEquals
(
render
.
modx_dispatch
(
mock_request_2
,
'dummy'
,
self
.
location
,
self
.
assertEquals
(
render
.
modx_dispatch
(
mock_request_2
,
'dummy'
,
self
.
location
,
'dummy'
)
.
content
,
'dummy'
)
.
content
,
json
.
dumps
({
'success'
:
'Submission aborted! Your file "
%
s" is too large (max size:
%
d MB)'
%
\
json
.
dumps
({
'success'
:
'Submission aborted! Your file "
%
s" is too large (max size:
%
d MB)'
%
(
inputfile
.
name
,
settings
.
STUDENT_FILEUPLOAD_MAX_SIZE
/
(
1000
**
2
))}))
(
inputfile
.
name
,
settings
.
STUDENT_FILEUPLOAD_MAX_SIZE
/
(
1000
**
2
))}))
mock_request_3
=
MagicMock
()
mock_request_3
=
MagicMock
()
mock_request_3
.
POST
.
copy
.
return_value
=
{}
mock_request_3
.
POST
.
copy
.
return_value
=
{}
mock_request_3
.
FILES
=
False
mock_request_3
.
FILES
=
False
...
@@ -99,12 +102,12 @@ class ModuleRenderTestCase(PageLoader):
...
@@ -99,12 +102,12 @@ class ModuleRenderTestCase(PageLoader):
inputfile_2
.
name
=
'name'
inputfile_2
.
name
=
'name'
self
.
assertRaises
(
ItemNotFoundError
,
render
.
modx_dispatch
,
self
.
assertRaises
(
ItemNotFoundError
,
render
.
modx_dispatch
,
mock_request_3
,
'dummy'
,
self
.
location
,
'toy'
)
mock_request_3
,
'dummy'
,
self
.
location
,
'toy'
)
self
.
assertRaises
(
Http404
,
render
.
modx_dispatch
,
mock_request_3
,
'dummy'
,
self
.
assertRaises
(
Http404
,
render
.
modx_dispatch
,
mock_request_3
,
'dummy'
,
self
.
location
,
self
.
course_id
)
self
.
location
,
self
.
course_id
)
mock_request_3
.
POST
.
copy
.
return_value
=
{
'position'
:
1
}
mock_request_3
.
POST
.
copy
.
return_value
=
{
'position'
:
1
}
self
.
assertIsInstance
(
render
.
modx_dispatch
(
mock_request_3
,
'goto_position'
,
self
.
assertIsInstance
(
render
.
modx_dispatch
(
mock_request_3
,
'goto_position'
,
self
.
location
,
self
.
course_id
),
HttpResponse
)
self
.
location
,
self
.
course_id
),
HttpResponse
)
def
test_get_score_bucket
(
self
):
def
test_get_score_bucket
(
self
):
self
.
assertEquals
(
render
.
get_score_bucket
(
0
,
10
),
'incorrect'
)
self
.
assertEquals
(
render
.
get_score_bucket
(
0
,
10
),
'incorrect'
)
self
.
assertEquals
(
render
.
get_score_bucket
(
1
,
10
),
'partial'
)
self
.
assertEquals
(
render
.
get_score_bucket
(
1
,
10
),
'partial'
)
...
@@ -113,6 +116,7 @@ class ModuleRenderTestCase(PageLoader):
...
@@ -113,6 +116,7 @@ class ModuleRenderTestCase(PageLoader):
self
.
assertEquals
(
render
.
get_score_bucket
(
11
,
10
),
'incorrect'
)
self
.
assertEquals
(
render
.
get_score_bucket
(
11
,
10
),
'incorrect'
)
self
.
assertEquals
(
render
.
get_score_bucket
(
-
1
,
10
),
'incorrect'
)
self
.
assertEquals
(
render
.
get_score_bucket
(
-
1
,
10
),
'incorrect'
)
@override_settings
(
MODULESTORE
=
TEST_DATA_XML_MODULESTORE
)
@override_settings
(
MODULESTORE
=
TEST_DATA_XML_MODULESTORE
)
class
TestTOC
(
TestCase
):
class
TestTOC
(
TestCase
):
"""Check the Table of Contents for a course"""
"""Check the Table of Contents for a course"""
...
@@ -130,19 +134,19 @@ class TestTOC(TestCase):
...
@@ -130,19 +134,19 @@ class TestTOC(TestCase):
factory
=
RequestFactory
()
factory
=
RequestFactory
()
request
=
factory
.
get
(
chapter_url
)
request
=
factory
.
get
(
chapter_url
)
expected
=
([{
'active'
:
True
,
'sections'
:
expected
=
([{
'active'
:
True
,
'sections'
:
[{
'url_name'
:
'Toy_Videos'
,
'display_name'
:
u'Toy Videos'
,
'graded'
:
True
,
[{
'url_name'
:
'Toy_Videos'
,
'display_name'
:
u'Toy Videos'
,
'graded'
:
True
,
'format'
:
u'Lecture Sequence'
,
'due'
:
''
,
'active'
:
False
},
'format'
:
u'Lecture Sequence'
,
'due'
:
''
,
'active'
:
False
},
{
'url_name'
:
'Welcome'
,
'display_name'
:
u'Welcome'
,
'graded'
:
True
,
{
'url_name'
:
'Welcome'
,
'display_name'
:
u'Welcome'
,
'graded'
:
True
,
'format'
:
''
,
'due'
:
''
,
'active'
:
False
},
'format'
:
''
,
'due'
:
''
,
'active'
:
False
},
{
'url_name'
:
'video_123456789012'
,
'display_name'
:
'video 123456789012'
,
'graded'
:
True
,
{
'url_name'
:
'video_123456789012'
,
'display_name'
:
'video 123456789012'
,
'graded'
:
True
,
'format'
:
''
,
'due'
:
''
,
'active'
:
False
},
'format'
:
''
,
'due'
:
''
,
'active'
:
False
},
{
'url_name'
:
'video_4f66f493ac8f'
,
'display_name'
:
'video 4f66f493ac8f'
,
'graded'
:
True
,
{
'url_name'
:
'video_4f66f493ac8f'
,
'display_name'
:
'video 4f66f493ac8f'
,
'graded'
:
True
,
'format'
:
''
,
'due'
:
''
,
'active'
:
False
}],
'format'
:
''
,
'due'
:
''
,
'active'
:
False
}],
'url_name'
:
'Overview'
,
'display_name'
:
u'Overview'
},
'url_name'
:
'Overview'
,
'display_name'
:
u'Overview'
},
{
'active'
:
False
,
'sections'
:
{
'active'
:
False
,
'sections'
:
[{
'url_name'
:
'toyvideo'
,
'display_name'
:
'toyvideo'
,
'graded'
:
True
,
[{
'url_name'
:
'toyvideo'
,
'display_name'
:
'toyvideo'
,
'graded'
:
True
,
'format'
:
''
,
'due'
:
''
,
'active'
:
False
}],
'format'
:
''
,
'due'
:
''
,
'active'
:
False
}],
'url_name'
:
'secret:magic'
,
'display_name'
:
'secret:magic'
}])
'url_name'
:
'secret:magic'
,
'display_name'
:
'secret:magic'
}])
actual
=
render
.
toc_for_course
(
self
.
portal_user
,
request
,
self
.
toy_course
,
chapter
,
None
)
actual
=
render
.
toc_for_course
(
self
.
portal_user
,
request
,
self
.
toy_course
,
chapter
,
None
)
...
@@ -155,21 +159,20 @@ class TestTOC(TestCase):
...
@@ -155,21 +159,20 @@ class TestTOC(TestCase):
factory
=
RequestFactory
()
factory
=
RequestFactory
()
request
=
factory
.
get
(
chapter_url
)
request
=
factory
.
get
(
chapter_url
)
expected
=
([{
'active'
:
True
,
'sections'
:
expected
=
([{
'active'
:
True
,
'sections'
:
[{
'url_name'
:
'Toy_Videos'
,
'display_name'
:
u'Toy Videos'
,
'graded'
:
True
,
[{
'url_name'
:
'Toy_Videos'
,
'display_name'
:
u'Toy Videos'
,
'graded'
:
True
,
'format'
:
u'Lecture Sequence'
,
'due'
:
''
,
'active'
:
False
},
'format'
:
u'Lecture Sequence'
,
'due'
:
''
,
'active'
:
False
},
{
'url_name'
:
'Welcome'
,
'display_name'
:
u'Welcome'
,
'graded'
:
True
,
{
'url_name'
:
'Welcome'
,
'display_name'
:
u'Welcome'
,
'graded'
:
True
,
'format'
:
''
,
'due'
:
''
,
'active'
:
True
},
'format'
:
''
,
'due'
:
''
,
'active'
:
True
},
{
'url_name'
:
'video_123456789012'
,
'display_name'
:
'video 123456789012'
,
'graded'
:
True
,
{
'url_name'
:
'video_123456789012'
,
'display_name'
:
'video 123456789012'
,
'graded'
:
True
,
'format'
:
''
,
'due'
:
''
,
'active'
:
False
},
'format'
:
''
,
'due'
:
''
,
'active'
:
False
},
{
'url_name'
:
'video_4f66f493ac8f'
,
'display_name'
:
'video 4f66f493ac8f'
,
'graded'
:
True
,
{
'url_name'
:
'video_4f66f493ac8f'
,
'display_name'
:
'video 4f66f493ac8f'
,
'graded'
:
True
,
'format'
:
''
,
'due'
:
''
,
'active'
:
False
}],
'format'
:
''
,
'due'
:
''
,
'active'
:
False
}],
'url_name'
:
'Overview'
,
'display_name'
:
u'Overview'
},
'url_name'
:
'Overview'
,
'display_name'
:
u'Overview'
},
{
'active'
:
False
,
'sections'
:
{
'active'
:
False
,
'sections'
:
[{
'url_name'
:
'toyvideo'
,
'display_name'
:
'toyvideo'
,
'graded'
:
True
,
[{
'url_name'
:
'toyvideo'
,
'display_name'
:
'toyvideo'
,
'graded'
:
True
,
'format'
:
''
,
'due'
:
''
,
'active'
:
False
}],
'format'
:
''
,
'due'
:
''
,
'active'
:
False
}],
'url_name'
:
'secret:magic'
,
'display_name'
:
'secret:magic'
}])
'url_name'
:
'secret:magic'
,
'display_name'
:
'secret:magic'
}])
actual
=
render
.
toc_for_course
(
self
.
portal_user
,
request
,
self
.
toy_course
,
chapter
,
section
)
actual
=
render
.
toc_for_course
(
self
.
portal_user
,
request
,
self
.
toy_course
,
chapter
,
section
)
self
.
assertEqual
(
expected
,
actual
)
self
.
assertEqual
(
expected
,
actual
)
lms/djangoapps/courseware/tests/test_progress.py
View file @
b0a01819
from
django.test
import
TestCase
from
django.test
import
TestCase
from
courseware
import
progress
from
courseware
import
progress
from
mock
import
MagicMock
from
mock
import
MagicMock
class
ProgessTests
(
TestCase
):
class
ProgessTests
(
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
d
=
dict
({
'duration_total'
:
0
,
self
.
d
=
dict
({
'duration_total'
:
0
,
'duration_watched'
:
0
,
'duration_watched'
:
0
,
'done'
:
True
,
'done'
:
True
,
'questions_correct'
:
4
,
'questions_correct'
:
4
,
'questions_incorrect'
:
0
,
'questions_incorrect'
:
0
,
'questions_total'
:
0
})
'questions_total'
:
0
})
self
.
c
=
progress
.
completion
()
self
.
c
=
progress
.
completion
()
self
.
c2
=
progress
.
completion
()
self
.
c2
=
progress
.
completion
()
self
.
c2
.
dict
=
dict
({
'duration_total'
:
0
,
self
.
c2
.
dict
=
dict
({
'duration_total'
:
0
,
'duration_watched'
:
0
,
'duration_watched'
:
0
,
'done'
:
True
,
'done'
:
True
,
'questions_correct'
:
2
,
'questions_correct'
:
2
,
'questions_incorrect'
:
1
,
'questions_incorrect'
:
1
,
'questions_total'
:
0
})
'questions_total'
:
0
})
self
.
cplusc2
=
dict
({
'duration_total'
:
0
,
self
.
cplusc2
=
dict
({
'duration_total'
:
0
,
'duration_watched'
:
0
,
'duration_watched'
:
0
,
'done'
:
True
,
'done'
:
True
,
'questions_correct'
:
2
,
'questions_correct'
:
2
,
'questions_incorrect'
:
1
,
'questions_incorrect'
:
1
,
'questions_total'
:
0
})
'questions_total'
:
0
})
self
.
oth
=
dict
({
'duration_total'
:
0
,
self
.
oth
=
dict
({
'duration_total'
:
0
,
'duration_watched'
:
0
,
'duration_watched'
:
0
,
'done'
:
True
,
'done'
:
True
,
'questions_correct'
:
4
,
'questions_correct'
:
4
,
'questions_incorrect'
:
0
,
'questions_incorrect'
:
0
,
'questions_total'
:
7
})
'questions_total'
:
7
})
self
.
x
=
MagicMock
()
self
.
x
=
MagicMock
()
self
.
x
.
dict
=
self
.
oth
self
.
x
.
dict
=
self
.
oth
self
.
d_oth
=
{
'duration_total'
:
0
,
self
.
d_oth
=
{
'duration_total'
:
0
,
'duration_watched'
:
0
,
'duration_watched'
:
0
,
'done'
:
True
,
'done'
:
True
,
'questions_correct'
:
4
,
'questions_correct'
:
4
,
'questions_incorrect'
:
0
,
'questions_incorrect'
:
0
,
'questions_total'
:
7
}
'questions_total'
:
7
}
def
test_getitem
(
self
):
def
test_getitem
(
self
):
self
.
assertEqual
(
self
.
c
.
__getitem__
(
'duration_watched'
),
0
)
self
.
assertEqual
(
self
.
c
.
__getitem__
(
'duration_watched'
),
0
)
def
test_setitem
(
self
):
def
test_setitem
(
self
):
self
.
c
.
__setitem__
(
'questions_correct'
,
4
)
self
.
c
.
__setitem__
(
'questions_correct'
,
4
)
self
.
assertEqual
(
str
(
self
.
c
),
str
(
self
.
d
))
self
.
assertEqual
(
str
(
self
.
c
),
str
(
self
.
d
))
def
test_repr
(
self
):
def
test_repr
(
self
):
self
.
assertEqual
(
self
.
c
.
__repr__
(),
str
(
progress
.
completion
()))
self
.
assertEqual
(
self
.
c
.
__repr__
(),
str
(
progress
.
completion
()))
lms/djangoapps/courseware/tests/test_views.py
View file @
b0a01819
...
@@ -15,12 +15,13 @@ from django.test.client import RequestFactory
...
@@ -15,12 +15,13 @@ from django.test.client import RequestFactory
from
student.models
import
CourseEnrollment
from
student.models
import
CourseEnrollment
from
xmodule.modulestore.django
import
modulestore
,
_MODULESTORES
from
xmodule.modulestore.django
import
modulestore
,
_MODULESTORES
from
xmodule.modulestore.exceptions
import
InvalidLocationError
,
\
from
xmodule.modulestore.exceptions
import
InvalidLocationError
,
\
ItemNotFoundError
,
NoPathToItem
ItemNotFoundError
,
NoPathToItem
import
courseware.views
as
views
import
courseware.views
as
views
from
xmodule.modulestore
import
Location
from
xmodule.modulestore
import
Location
from
factories
import
UserFactory
from
factories
import
UserFactory
class
Stub
():
class
Stub
():
pass
pass
...
@@ -28,18 +29,19 @@ class Stub():
...
@@ -28,18 +29,19 @@ class Stub():
# This part is required for modulestore() to work properly
# This part is required for modulestore() to work properly
def
xml_store_config
(
data_dir
):
def
xml_store_config
(
data_dir
):
return
{
return
{
'default'
:
{
'default'
:
{
'ENGINE'
:
'xmodule.modulestore.xml.XMLModuleStore'
,
'ENGINE'
:
'xmodule.modulestore.xml.XMLModuleStore'
,
'OPTIONS'
:
{
'OPTIONS'
:
{
'data_dir'
:
data_dir
,
'data_dir'
:
data_dir
,
'default_class'
:
'xmodule.hidden_module.HiddenDescriptor'
,
'default_class'
:
'xmodule.hidden_module.HiddenDescriptor'
,
}
}
}
}
}
}
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
)
@override_settings
(
MODULESTORE
=
TEST_DATA_XML_MODULESTORE
)
class
TestJumpTo
(
TestCase
):
class
TestJumpTo
(
TestCase
):
"""Check the jumpto link for a course"""
"""Check the jumpto link for a course"""
...
@@ -64,15 +66,16 @@ class TestJumpTo(TestCase):
...
@@ -64,15 +66,16 @@ class TestJumpTo(TestCase):
response
=
self
.
client
.
get
(
jumpto_url
)
response
=
self
.
client
.
get
(
jumpto_url
)
self
.
assertRedirects
(
response
,
expected
,
status_code
=
302
,
target_status_code
=
302
)
self
.
assertRedirects
(
response
,
expected
,
status_code
=
302
,
target_status_code
=
302
)
class
ViewsTestCase
(
TestCase
):
class
ViewsTestCase
(
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
user
=
User
.
objects
.
create
(
username
=
'dummy'
,
password
=
'123456'
,
self
.
user
=
User
.
objects
.
create
(
username
=
'dummy'
,
password
=
'123456'
,
email
=
'test@mit.edu'
)
email
=
'test@mit.edu'
)
self
.
date
=
datetime
.
datetime
(
2013
,
1
,
22
)
self
.
date
=
datetime
.
datetime
(
2013
,
1
,
22
)
self
.
course_id
=
'edX/toy/2012_Fall'
self
.
course_id
=
'edX/toy/2012_Fall'
self
.
enrollment
=
CourseEnrollment
.
objects
.
get_or_create
(
user
=
self
.
user
,
self
.
enrollment
=
CourseEnrollment
.
objects
.
get_or_create
(
user
=
self
.
user
,
course_id
=
self
.
course_id
,
course_id
=
self
.
course_id
,
created
=
self
.
date
)[
0
]
created
=
self
.
date
)[
0
]
self
.
location
=
[
'tag'
,
'org'
,
'course'
,
'category'
,
'name'
]
self
.
location
=
[
'tag'
,
'org'
,
'course'
,
'category'
,
'name'
]
self
.
_MODULESTORES
=
{}
self
.
_MODULESTORES
=
{}
# This is a CourseDescriptor object
# This is a CourseDescriptor object
...
@@ -85,13 +88,13 @@ class ViewsTestCase(TestCase):
...
@@ -85,13 +88,13 @@ class ViewsTestCase(TestCase):
# depreciated function
# depreciated function
mock_user
=
MagicMock
()
mock_user
=
MagicMock
()
mock_user
.
is_authenticated
.
return_value
=
False
mock_user
.
is_authenticated
.
return_value
=
False
self
.
assertEquals
(
views
.
user_groups
(
mock_user
),[])
self
.
assertEquals
(
views
.
user_groups
(
mock_user
),
[])
def
test_get_current_child
(
self
):
def
test_get_current_child
(
self
):
self
.
assertIsNone
(
views
.
get_current_child
(
Stub
()))
self
.
assertIsNone
(
views
.
get_current_child
(
Stub
()))
mock_xmodule
=
MagicMock
()
mock_xmodule
=
MagicMock
()
mock_xmodule
.
position
=
-
1
mock_xmodule
.
position
=
-
1
mock_xmodule
.
get_display_items
.
return_value
=
[
'one'
,
'two'
]
mock_xmodule
.
get_display_items
.
return_value
=
[
'one'
,
'two'
]
self
.
assertEquals
(
views
.
get_current_child
(
mock_xmodule
),
'one'
)
self
.
assertEquals
(
views
.
get_current_child
(
mock_xmodule
),
'one'
)
mock_xmodule_2
=
MagicMock
()
mock_xmodule_2
=
MagicMock
()
mock_xmodule_2
.
position
=
3
mock_xmodule_2
.
position
=
3
...
...
lms/djangoapps/courseware/tests/tests.py
View file @
b0a01819
...
@@ -53,46 +53,46 @@ def registration(email):
...
@@ -53,46 +53,46 @@ def registration(email):
def
mongo_store_config
(
data_dir
):
def
mongo_store_config
(
data_dir
):
return
{
return
{
'default'
:
{
'default'
:
{
'ENGINE'
:
'xmodule.modulestore.mongo.MongoModuleStore'
,
'ENGINE'
:
'xmodule.modulestore.mongo.MongoModuleStore'
,
'OPTIONS'
:
{
'OPTIONS'
:
{
'default_class'
:
'xmodule.raw_module.RawDescriptor'
,
'default_class'
:
'xmodule.raw_module.RawDescriptor'
,
'host'
:
'localhost'
,
'host'
:
'localhost'
,
'db'
:
'test_xmodule'
,
'db'
:
'test_xmodule'
,
'collection'
:
'modulestore'
,
'collection'
:
'modulestore'
,
'fs_root'
:
data_dir
,
'fs_root'
:
data_dir
,
'render_template'
:
'mitxmako.shortcuts.render_to_string'
,
'render_template'
:
'mitxmako.shortcuts.render_to_string'
,
}
}
}
}
}
}
def
draft_mongo_store_config
(
data_dir
):
def
draft_mongo_store_config
(
data_dir
):
return
{
return
{
'default'
:
{
'default'
:
{
'ENGINE'
:
'xmodule.modulestore.mongo.DraftMongoModuleStore'
,
'ENGINE'
:
'xmodule.modulestore.mongo.DraftMongoModuleStore'
,
'OPTIONS'
:
{
'OPTIONS'
:
{
'default_class'
:
'xmodule.raw_module.RawDescriptor'
,
'default_class'
:
'xmodule.raw_module.RawDescriptor'
,
'host'
:
'localhost'
,
'host'
:
'localhost'
,
'db'
:
'test_xmodule'
,
'db'
:
'test_xmodule'
,
'collection'
:
'modulestore'
,
'collection'
:
'modulestore'
,
'fs_root'
:
data_dir
,
'fs_root'
:
data_dir
,
'render_template'
:
'mitxmako.shortcuts.render_to_string'
,
'render_template'
:
'mitxmako.shortcuts.render_to_string'
,
}
}
}
}
}
}
def
xml_store_config
(
data_dir
):
def
xml_store_config
(
data_dir
):
return
{
return
{
'default'
:
{
'default'
:
{
'ENGINE'
:
'xmodule.modulestore.xml.XMLModuleStore'
,
'ENGINE'
:
'xmodule.modulestore.xml.XMLModuleStore'
,
'OPTIONS'
:
{
'OPTIONS'
:
{
'data_dir'
:
data_dir
,
'data_dir'
:
data_dir
,
'default_class'
:
'xmodule.hidden_module.HiddenDescriptor'
,
'default_class'
:
'xmodule.hidden_module.HiddenDescriptor'
,
}
}
}
}
}
}
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
)
...
@@ -115,8 +115,7 @@ class ActivateLoginTestCase(TestCase):
...
@@ -115,8 +115,7 @@ class ActivateLoginTestCase(TestCase):
'Response status code was {0} instead of 302'
.
format
(
response
.
status_code
))
'Response status code was {0} instead of 302'
.
format
(
response
.
status_code
))
url
=
response
[
'Location'
]
url
=
response
[
'Location'
]
e_scheme
,
e_netloc
,
e_path
,
e_query
,
e_fragment
=
urlsplit
(
e_scheme
,
e_netloc
,
e_path
,
e_query
,
e_fragment
=
urlsplit
(
expected_url
)
expected_url
)
if
not
(
e_scheme
or
e_netloc
):
if
not
(
e_scheme
or
e_netloc
):
expected_url
=
urlunsplit
((
'http'
,
'testserver'
,
e_path
,
expected_url
=
urlunsplit
((
'http'
,
'testserver'
,
e_path
,
e_query
,
e_fragment
))
e_query
,
e_fragment
))
...
@@ -211,7 +210,7 @@ class PageLoader(ActivateLoginTestCase):
...
@@ -211,7 +210,7 @@ class PageLoader(ActivateLoginTestCase):
resp
=
self
.
client
.
post
(
'/change_enrollment'
,
{
resp
=
self
.
client
.
post
(
'/change_enrollment'
,
{
'enrollment_action'
:
'enroll'
,
'enrollment_action'
:
'enroll'
,
'course_id'
:
course
.
id
,
'course_id'
:
course
.
id
,
})
})
return
parse_json
(
resp
)
return
parse_json
(
resp
)
def
try_enroll
(
self
,
course
):
def
try_enroll
(
self
,
course
):
...
@@ -230,11 +229,10 @@ class PageLoader(ActivateLoginTestCase):
...
@@ -230,11 +229,10 @@ class PageLoader(ActivateLoginTestCase):
resp
=
self
.
client
.
post
(
'/change_enrollment'
,
{
resp
=
self
.
client
.
post
(
'/change_enrollment'
,
{
'enrollment_action'
:
'unenroll'
,
'enrollment_action'
:
'unenroll'
,
'course_id'
:
course
.
id
,
'course_id'
:
course
.
id
,
})
})
data
=
parse_json
(
resp
)
data
=
parse_json
(
resp
)
self
.
assertTrue
(
data
[
'success'
])
self
.
assertTrue
(
data
[
'success'
])
def
check_for_get_code
(
self
,
code
,
url
):
def
check_for_get_code
(
self
,
code
,
url
):
"""
"""
Check that we got the expected code when accessing url via GET.
Check that we got the expected code when accessing url via GET.
...
@@ -246,7 +244,6 @@ class PageLoader(ActivateLoginTestCase):
...
@@ -246,7 +244,6 @@ class PageLoader(ActivateLoginTestCase):
.
format
(
resp
.
status_code
,
url
,
code
))
.
format
(
resp
.
status_code
,
url
,
code
))
return
resp
return
resp
def
check_for_post_code
(
self
,
code
,
url
,
data
=
{}):
def
check_for_post_code
(
self
,
code
,
url
,
data
=
{}):
"""
"""
Check that we got the expected code when accessing url via POST.
Check that we got the expected code when accessing url via POST.
...
@@ -258,12 +255,8 @@ class PageLoader(ActivateLoginTestCase):
...
@@ -258,12 +255,8 @@ class PageLoader(ActivateLoginTestCase):
.
format
(
resp
.
status_code
,
url
,
code
))
.
format
(
resp
.
status_code
,
url
,
code
))
return
resp
return
resp
def
check_pages_load
(
self
,
module_store
):
def
check_pages_load
(
self
,
module_store
):
"""Make all locations in course load"""
"""Make all locations in course load"""
# enroll in the course before trying to access pages
# enroll in the course before trying to access pages
courses
=
module_store
.
get_courses
()
courses
=
module_store
.
get_courses
()
self
.
assertEqual
(
len
(
courses
),
1
)
self
.
assertEqual
(
len
(
courses
),
1
)
...
@@ -316,7 +309,7 @@ class PageLoader(ActivateLoginTestCase):
...
@@ -316,7 +309,7 @@ class PageLoader(ActivateLoginTestCase):
msg
=
str
(
resp
.
status_code
)
msg
=
str
(
resp
.
status_code
)
if
resp
.
status_code
!=
200
:
if
resp
.
status_code
!=
200
:
msg
=
"ERROR "
+
msg
+
": "
+
descriptor
.
location
.
url
()
msg
=
"ERROR "
+
msg
+
": "
+
descriptor
.
location
.
url
()
all_ok
=
False
all_ok
=
False
num_bad
+=
1
num_bad
+=
1
elif
resp
.
redirect_chain
[
0
][
1
]
!=
302
:
elif
resp
.
redirect_chain
[
0
][
1
]
!=
302
:
...
@@ -344,7 +337,6 @@ class PageLoader(ActivateLoginTestCase):
...
@@ -344,7 +337,6 @@ class PageLoader(ActivateLoginTestCase):
self
.
assertTrue
(
all_ok
)
self
.
assertTrue
(
all_ok
)
@override_settings
(
MODULESTORE
=
TEST_DATA_XML_MODULESTORE
)
@override_settings
(
MODULESTORE
=
TEST_DATA_XML_MODULESTORE
)
class
TestCoursesLoadTestCase_XmlModulestore
(
PageLoader
):
class
TestCoursesLoadTestCase_XmlModulestore
(
PageLoader
):
'''Check that all pages in test courses load properly'''
'''Check that all pages in test courses load properly'''
...
@@ -355,21 +347,21 @@ class TestCoursesLoadTestCase_XmlModulestore(PageLoader):
...
@@ -355,21 +347,21 @@ class TestCoursesLoadTestCase_XmlModulestore(PageLoader):
def
test_toy_course_loads
(
self
):
def
test_toy_course_loads
(
self
):
module_store
=
XMLModuleStore
(
module_store
=
XMLModuleStore
(
TEST_DATA_DIR
,
TEST_DATA_DIR
,
default_class
=
'xmodule.hidden_module.HiddenDescriptor'
,
default_class
=
'xmodule.hidden_module.HiddenDescriptor'
,
course_dirs
=
[
'toy'
],
course_dirs
=
[
'toy'
],
load_error_modules
=
True
,
load_error_modules
=
True
,
)
)
self
.
check_pages_load
(
module_store
)
self
.
check_pages_load
(
module_store
)
def
test_full_course_loads
(
self
):
def
test_full_course_loads
(
self
):
module_store
=
XMLModuleStore
(
module_store
=
XMLModuleStore
(
TEST_DATA_DIR
,
TEST_DATA_DIR
,
default_class
=
'xmodule.hidden_module.HiddenDescriptor'
,
default_class
=
'xmodule.hidden_module.HiddenDescriptor'
,
course_dirs
=
[
'full'
],
course_dirs
=
[
'full'
],
load_error_modules
=
True
,
load_error_modules
=
True
,
)
)
self
.
check_pages_load
(
module_store
)
self
.
check_pages_load
(
module_store
)
...
@@ -525,7 +517,6 @@ class TestViewAuth(PageLoader):
...
@@ -525,7 +517,6 @@ class TestViewAuth(PageLoader):
print
'checking for 404 on {0}'
.
format
(
url
)
print
'checking for 404 on {0}'
.
format
(
url
)
self
.
check_for_get_code
(
404
,
url
)
self
.
check_for_get_code
(
404
,
url
)
# now also make the instructor staff
# now also make the instructor staff
u
=
user
(
self
.
instructor
)
u
=
user
(
self
.
instructor
)
u
.
is_staff
=
True
u
.
is_staff
=
True
...
@@ -536,7 +527,6 @@ class TestViewAuth(PageLoader):
...
@@ -536,7 +527,6 @@ class TestViewAuth(PageLoader):
print
'checking for 200 on {0}'
.
format
(
url
)
print
'checking for 200 on {0}'
.
format
(
url
)
self
.
check_for_get_code
(
200
,
url
)
self
.
check_for_get_code
(
200
,
url
)
def
run_wrapped
(
self
,
test
):
def
run_wrapped
(
self
,
test
):
"""
"""
test.py turns off start dates. Enable them.
test.py turns off start dates. Enable them.
...
@@ -552,7 +542,6 @@ class TestViewAuth(PageLoader):
...
@@ -552,7 +542,6 @@ class TestViewAuth(PageLoader):
finally
:
finally
:
settings
.
MITX_FEATURES
[
'DISABLE_START_DATES'
]
=
oldDSD
settings
.
MITX_FEATURES
[
'DISABLE_START_DATES'
]
=
oldDSD
def
test_dark_launch
(
self
):
def
test_dark_launch
(
self
):
"""Make sure that before course start, students can't access course
"""Make sure that before course start, students can't access course
pages, but instructors can"""
pages, but instructors can"""
...
@@ -646,7 +635,6 @@ class TestViewAuth(PageLoader):
...
@@ -646,7 +635,6 @@ class TestViewAuth(PageLoader):
url
=
reverse_urls
([
'courseware'
],
course
)[
0
]
url
=
reverse_urls
([
'courseware'
],
course
)[
0
]
self
.
check_for_get_code
(
302
,
url
)
self
.
check_for_get_code
(
302
,
url
)
# First, try with an enrolled student
# First, try with an enrolled student
print
'=== Testing student access....'
print
'=== Testing student access....'
self
.
login
(
self
.
student
,
self
.
password
)
self
.
login
(
self
.
student
,
self
.
password
)
...
@@ -761,7 +749,6 @@ class TestViewAuth(PageLoader):
...
@@ -761,7 +749,6 @@ class TestViewAuth(PageLoader):
self
.
assertTrue
(
has_access
(
student_user
,
self
.
toy
,
'load'
))
self
.
assertTrue
(
has_access
(
student_user
,
self
.
toy
,
'load'
))
@override_settings
(
MODULESTORE
=
TEST_DATA_XML_MODULESTORE
)
@override_settings
(
MODULESTORE
=
TEST_DATA_XML_MODULESTORE
)
class
TestCourseGrader
(
PageLoader
):
class
TestCourseGrader
(
PageLoader
):
"""Check that a course gets graded properly"""
"""Check that a course gets graded properly"""
...
@@ -832,13 +819,12 @@ class TestCourseGrader(PageLoader):
...
@@ -832,13 +819,12 @@ class TestCourseGrader(PageLoader):
kwargs
=
{
kwargs
=
{
'course_id'
:
self
.
graded_course
.
id
,
'course_id'
:
self
.
graded_course
.
id
,
'location'
:
problem_location
,
'location'
:
problem_location
,
'dispatch'
:
'problem_check'
,
}
'dispatch'
:
'problem_check'
,
})
)
resp
=
self
.
client
.
post
(
modx_url
,
{
resp
=
self
.
client
.
post
(
modx_url
,
{
'input_i4x-edX-graded-problem-{0}_2_1'
.
format
(
problem_url_name
):
responses
[
0
],
'input_i4x-edX-graded-problem-{0}_2_1'
.
format
(
problem_url_name
):
responses
[
0
],
'input_i4x-edX-graded-problem-{0}_2_2'
.
format
(
problem_url_name
):
responses
[
1
],
'input_i4x-edX-graded-problem-{0}_2_2'
.
format
(
problem_url_name
):
responses
[
1
],
})
})
print
"modx_url"
,
modx_url
,
"responses"
,
responses
print
"modx_url"
,
modx_url
,
"responses"
,
responses
print
"resp"
,
resp
print
"resp"
,
resp
...
@@ -854,8 +840,7 @@ class TestCourseGrader(PageLoader):
...
@@ -854,8 +840,7 @@ class TestCourseGrader(PageLoader):
kwargs
=
{
kwargs
=
{
'course_id'
:
self
.
graded_course
.
id
,
'course_id'
:
self
.
graded_course
.
id
,
'location'
:
problem_location
,
'location'
:
problem_location
,
'dispatch'
:
'problem_reset'
,
}
'dispatch'
:
'problem_reset'
,
})
)
resp
=
self
.
client
.
post
(
modx_url
)
resp
=
self
.
client
.
post
(
modx_url
)
return
resp
return
resp
...
...
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