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
7f017d0c
Commit
7f017d0c
authored
Jun 26, 2013
by
Jean Manuel Nater
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Addressed pull request feedback
parent
c4c68f51
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
50 additions
and
74 deletions
+50
-74
common/djangoapps/student/views.py
+1
-1
common/lib/xmodule/xmodule/modulestore/tests/django_utils.py
+20
-26
common/lib/xmodule/xmodule/modulestore/tests/factories.py
+4
-4
lms/djangoapps/courseware/access.py
+0
-1
lms/djangoapps/courseware/tests/helpers.py
+7
-20
lms/djangoapps/courseware/tests/modulestore_config.py
+13
-17
lms/djangoapps/courseware/tests/test_navigation.py
+5
-5
lms/djangoapps/courseware/tests/test_view_authentication.py
+0
-0
No files found.
common/djangoapps/student/views.py
View file @
7f017d0c
...
@@ -357,7 +357,6 @@ def change_enrollment(request):
...
@@ -357,7 +357,6 @@ def change_enrollment(request):
return
HttpResponseBadRequest
(
"Course id not specified"
)
return
HttpResponseBadRequest
(
"Course id not specified"
)
if
action
==
"enroll"
:
if
action
==
"enroll"
:
# Make sure the course exists
# Make sure the course exists
# We don't do this check on unenroll, or a bad course id can't be unenrolled from
# We don't do this check on unenroll, or a bad course id can't be unenrolled from
try
:
try
:
...
@@ -366,6 +365,7 @@ def change_enrollment(request):
...
@@ -366,6 +365,7 @@ def change_enrollment(request):
log
.
warning
(
"User {0} tried to enroll in non-existent course {1}"
log
.
warning
(
"User {0} tried to enroll in non-existent course {1}"
.
format
(
user
.
username
,
course_id
))
.
format
(
user
.
username
,
course_id
))
return
HttpResponseBadRequest
(
"Course id is invalid"
)
return
HttpResponseBadRequest
(
"Course id is invalid"
)
if
not
has_access
(
user
,
course
,
'enroll'
):
if
not
has_access
(
user
,
course
,
'enroll'
):
return
HttpResponseBadRequest
(
"Enrollment is closed"
)
return
HttpResponseBadRequest
(
"Enrollment is closed"
)
...
...
common/lib/xmodule/xmodule/modulestore/tests/django_utils.py
View file @
7f017d0c
...
@@ -17,30 +17,24 @@ class ModuleStoreTestCase(TestCase):
...
@@ -17,30 +17,24 @@ class ModuleStoreTestCase(TestCase):
@staticmethod
@staticmethod
def
update_course
(
course
,
data
):
def
update_course
(
course
,
data
):
"""
"""
Updates the version of course in the mo
ngo mo
dulestore
Updates the version of course in the modulestore
with the metadata in
data
and returns the updated version.
with the metadata in
'data'
and returns the updated version.
'course' is an instance of CourseDescriptor for which we want
'course' is an instance of CourseDescriptor for which we want
to update metadata.
to update metadata.
'data' is a dictionary with an entry for each CourseField we want to update.
'data' is a dictionary with an entry for each CourseField we want to update.
"""
"""
store
=
xmodule
.
modulestore
.
django
.
modulestore
()
store
=
xmodule
.
modulestore
.
django
.
modulestore
()
store
.
update_item
(
course
.
location
,
data
)
store
.
update_metadata
(
course
.
location
,
data
)
store
.
update_metadata
(
course
.
location
,
data
)
updated_course
=
store
.
get_instance
(
course
.
id
,
course
.
location
)
updated_course
=
store
.
get_instance
(
course
.
id
,
course
.
location
)
return
updated_course
return
updated_course
@staticmethod
@staticmethod
def
flush_mongo_except_templates
():
def
flush_mongo_except_templates
():
'''
"""
Delete everything in the module store except templates
Delete everything in the module store except templates
.
'''
"""
modulestore
=
xmodule
.
modulestore
.
django
.
modulestore
()
modulestore
=
xmodule
.
modulestore
.
django
.
modulestore
()
# This query means: every item in the collection
# This query means: every item in the collection
...
@@ -52,11 +46,11 @@ class ModuleStoreTestCase(TestCase):
...
@@ -52,11 +46,11 @@ class ModuleStoreTestCase(TestCase):
@staticmethod
@staticmethod
def
load_templates_if_necessary
():
def
load_templates_if_necessary
():
'''
"""
Load templates into the direct modulestore only if they do not already exist.
Load templates into the direct modulestore only if they do not already exist.
We need the templates, because they are copied to create
We need the templates, because they are copied to create
XModules such as sections and problems
XModules such as sections and problems
.
'''
"""
modulestore
=
xmodule
.
modulestore
.
django
.
modulestore
(
'direct'
)
modulestore
=
xmodule
.
modulestore
.
django
.
modulestore
(
'direct'
)
# Count the number of templates
# Count the number of templates
...
@@ -68,9 +62,9 @@ class ModuleStoreTestCase(TestCase):
...
@@ -68,9 +62,9 @@ class ModuleStoreTestCase(TestCase):
@classmethod
@classmethod
def
setUpClass
(
cls
):
def
setUpClass
(
cls
):
'''
"""
Flush the mongo store and set up templates
Flush the mongo store and set up templates
.
'''
"""
# Use a uuid to differentiate
# Use a uuid to differentiate
# the mongo collections on jenkins.
# the mongo collections on jenkins.
...
@@ -88,9 +82,9 @@ class ModuleStoreTestCase(TestCase):
...
@@ -88,9 +82,9 @@ class ModuleStoreTestCase(TestCase):
@classmethod
@classmethod
def
tearDownClass
(
cls
):
def
tearDownClass
(
cls
):
'''
"""
Revert to the old modulestore settings
Revert to the old modulestore settings
.
'''
"""
# Clean up by dropping the collection
# Clean up by dropping the collection
modulestore
=
xmodule
.
modulestore
.
django
.
modulestore
()
modulestore
=
xmodule
.
modulestore
.
django
.
modulestore
()
...
@@ -102,9 +96,9 @@ class ModuleStoreTestCase(TestCase):
...
@@ -102,9 +96,9 @@ class ModuleStoreTestCase(TestCase):
settings
.
MODULESTORE
=
cls
.
orig_modulestore
settings
.
MODULESTORE
=
cls
.
orig_modulestore
def
_pre_setup
(
self
):
def
_pre_setup
(
self
):
'''
"""
Remove everything but the templates before each test
Remove everything but the templates before each test
.
'''
"""
# Flush anything that is not a template
# Flush anything that is not a template
ModuleStoreTestCase
.
flush_mongo_except_templates
()
ModuleStoreTestCase
.
flush_mongo_except_templates
()
...
@@ -116,9 +110,9 @@ class ModuleStoreTestCase(TestCase):
...
@@ -116,9 +110,9 @@ class ModuleStoreTestCase(TestCase):
super
(
ModuleStoreTestCase
,
self
)
.
_pre_setup
()
super
(
ModuleStoreTestCase
,
self
)
.
_pre_setup
()
def
_post_teardown
(
self
):
def
_post_teardown
(
self
):
'''
"""
Flush everything we created except the templates
Flush everything we created except the templates
.
'''
"""
# Flush anything that is not a template
# Flush anything that is not a template
ModuleStoreTestCase
.
flush_mongo_except_templates
()
ModuleStoreTestCase
.
flush_mongo_except_templates
()
...
...
common/lib/xmodule/xmodule/modulestore/tests/factories.py
View file @
7f017d0c
...
@@ -60,8 +60,8 @@ class XModuleCourseFactory(Factory):
...
@@ -60,8 +60,8 @@ class XModuleCourseFactory(Factory):
if
data
is
not
None
:
if
data
is
not
None
:
store
.
update_item
(
new_course
.
location
,
data
)
store
.
update_item
(
new_course
.
location
,
data
)
#update_item updates the the course as it exists in the modulestore, but doesn't
#
update_item updates the the course as it exists in the modulestore, but doesn't
#update the instance we are working with, so have to refetch the course after updating it.
#
update the instance we are working with, so have to refetch the course after updating it.
new_course
=
store
.
get_instance
(
new_course
.
id
,
new_course
.
location
)
new_course
=
store
.
get_instance
(
new_course
.
id
,
new_course
.
location
)
return
new_course
return
new_course
...
@@ -152,8 +152,8 @@ class XModuleItemFactory(Factory):
...
@@ -152,8 +152,8 @@ class XModuleItemFactory(Factory):
if
new_item
.
location
.
category
not
in
DETACHED_CATEGORIES
:
if
new_item
.
location
.
category
not
in
DETACHED_CATEGORIES
:
store
.
update_children
(
parent_location
,
parent
.
children
+
[
new_item
.
location
.
url
()])
store
.
update_children
(
parent_location
,
parent
.
children
+
[
new_item
.
location
.
url
()])
#update_children updates the the item as it exists in the modulestore, but doesn't
#
update_children updates the the item as it exists in the modulestore, but doesn't
#update the instance we are working with, so have to refetch the item after updating it.
#
update the instance we are working with, so have to refetch the item after updating it.
new_item
=
store
.
get_item
(
new_item
.
location
)
new_item
=
store
.
get_item
(
new_item
.
location
)
return
new_item
return
new_item
...
...
lms/djangoapps/courseware/access.py
View file @
7f017d0c
...
@@ -526,7 +526,6 @@ def _adjust_start_date_for_beta_testers(user, descriptor):
...
@@ -526,7 +526,6 @@ def _adjust_start_date_for_beta_testers(user, descriptor):
start_as_datetime
=
descriptor
.
lms
.
start
start_as_datetime
=
descriptor
.
lms
.
start
delta
=
timedelta
(
descriptor
.
lms
.
days_early_for_beta
)
delta
=
timedelta
(
descriptor
.
lms
.
days_early_for_beta
)
effective
=
start_as_datetime
-
delta
effective
=
start_as_datetime
-
delta
# ...and back to time_struct
# ...and back to time_struct
return
effective
return
effective
...
...
lms/djangoapps/courseware/tests/helpers.py
View file @
7f017d0c
...
@@ -48,7 +48,6 @@ class LoginEnrollmentTestCase(TestCase):
...
@@ -48,7 +48,6 @@ class LoginEnrollmentTestCase(TestCase):
Provides support for user creation,
Provides support for user creation,
activation, login, and course enrollment.
activation, login, and course enrollment.
"""
"""
def
setup_user
(
self
):
def
setup_user
(
self
):
"""
"""
Create a user account, activate, and log in.
Create a user account, activate, and log in.
...
@@ -67,8 +66,8 @@ class LoginEnrollmentTestCase(TestCase):
...
@@ -67,8 +66,8 @@ class LoginEnrollmentTestCase(TestCase):
"""
"""
Login, check that the corresponding view's response has a 200 status code.
Login, check that the corresponding view's response has a 200 status code.
"""
"""
resp
=
resp
=
self
.
client
.
post
(
reverse
(
'login'
),
resp
=
self
.
client
.
post
(
reverse
(
'login'
),
{
'email'
:
email
,
'password'
:
password
})
{
'email'
:
email
,
'password'
:
password
})
self
.
assertEqual
(
resp
.
status_code
,
200
)
self
.
assertEqual
(
resp
.
status_code
,
200
)
data
=
json
.
loads
(
resp
.
content
)
data
=
json
.
loads
(
resp
.
content
)
self
.
assertTrue
(
data
[
'success'
])
self
.
assertTrue
(
data
[
'success'
])
...
@@ -78,15 +77,14 @@ class LoginEnrollmentTestCase(TestCase):
...
@@ -78,15 +77,14 @@ class LoginEnrollmentTestCase(TestCase):
Logout; check that the HTTP response code indicates redirection
Logout; check that the HTTP response code indicates redirection
as expected.
as expected.
"""
"""
resp
=
self
.
client
.
get
(
reverse
(
'logout'
),
{})
# should redirect
# should redirect
self
.
assertEqual
(
resp
.
status_code
,
302
)
check_for_get_code
(
self
,
302
,
reverse
(
'logout'
)
)
def
create_account
(
self
,
username
,
email
,
password
):
def
create_account
(
self
,
username
,
email
,
password
):
"""
"""
Create the account and check that it worked.
Create the account and check that it worked.
"""
"""
resp
=
self
.
client
.
post
(
reverse
(
'create_account'
),
{
resp
=
check_for_post_code
(
self
,
200
,
reverse
(
'create_account'
),
{
'username'
:
username
,
'username'
:
username
,
'email'
:
email
,
'email'
:
email
,
'password'
:
password
,
'password'
:
password
,
...
@@ -94,10 +92,8 @@ class LoginEnrollmentTestCase(TestCase):
...
@@ -94,10 +92,8 @@ class LoginEnrollmentTestCase(TestCase):
'terms_of_service'
:
'true'
,
'terms_of_service'
:
'true'
,
'honor_code'
:
'true'
,
'honor_code'
:
'true'
,
})
})
self
.
assertEqual
(
resp
.
status_code
,
200
)
data
=
json
.
loads
(
resp
.
content
)
data
=
json
.
loads
(
resp
.
content
)
self
.
assertEqual
(
data
[
'success'
],
True
)
self
.
assertEqual
(
data
[
'success'
],
True
)
# Check both that the user is created, and inactive
# Check both that the user is created, and inactive
self
.
assertFalse
(
User
.
objects
.
get
(
email
=
email
)
.
is_active
)
self
.
assertFalse
(
User
.
objects
.
get
(
email
=
email
)
.
is_active
)
...
@@ -107,12 +103,8 @@ class LoginEnrollmentTestCase(TestCase):
...
@@ -107,12 +103,8 @@ class LoginEnrollmentTestCase(TestCase):
No error checking.
No error checking.
"""
"""
activation_key
=
Registration
.
objects
.
get
(
user__email
=
email
)
.
activation_key
activation_key
=
Registration
.
objects
.
get
(
user__email
=
email
)
.
activation_key
# and now we try to activate
# and now we try to activate
url
=
reverse
(
'activate'
,
kwargs
=
{
'key'
:
activation_key
})
check_for_get_code
(
self
,
200
,
reverse
(
'activate'
,
kwargs
=
{
'key'
:
activation_key
}))
resp
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
resp
.
status_code
,
200
)
# Now make sure that the user is now actually activated
# Now make sure that the user is now actually activated
self
.
assertTrue
(
User
.
objects
.
get
(
email
=
email
)
.
is_active
)
self
.
assertTrue
(
User
.
objects
.
get
(
email
=
email
)
.
is_active
)
...
@@ -128,8 +120,6 @@ class LoginEnrollmentTestCase(TestCase):
...
@@ -128,8 +120,6 @@ class LoginEnrollmentTestCase(TestCase):
'enrollment_action'
:
'enroll'
,
'enrollment_action'
:
'enroll'
,
'course_id'
:
course
.
id
,
'course_id'
:
course
.
id
,
})
})
print
(
'Enrollment in
%
s result status code:
%
s'
%
(
course
.
location
.
url
(),
str
(
resp
.
status_code
)))
result
=
resp
.
status_code
==
200
result
=
resp
.
status_code
==
200
if
verify
:
if
verify
:
self
.
assertTrue
(
result
)
self
.
assertTrue
(
result
)
...
@@ -140,8 +130,5 @@ class LoginEnrollmentTestCase(TestCase):
...
@@ -140,8 +130,5 @@ class LoginEnrollmentTestCase(TestCase):
Unenroll the currently logged-in user, and check that it worked.
Unenroll the currently logged-in user, and check that it worked.
`course` is an instance of CourseDescriptor.
`course` is an instance of CourseDescriptor.
"""
"""
resp
=
self
.
client
.
post
(
reverse
(
'change_enrollment'
),
{
check_for_post_code
(
self
,
200
,
reverse
(
'change_enrollment'
),
{
'enrollment_action'
:
'unenroll'
,
'enrollment_action'
:
'unenroll'
,
'course_id'
:
course
.
id
})
'course_id'
:
course
.
id
,
})
self
.
assertEqual
(
resp
.
status_code
,
200
)
lms/djangoapps/courseware/tests/modulestore_config.py
View file @
7f017d0c
...
@@ -16,7 +16,7 @@ def mongo_store_config(data_dir):
...
@@ -16,7 +16,7 @@ def mongo_store_config(data_dir):
'default_class'
:
'xmodule.raw_module.RawDescriptor'
,
'default_class'
:
'xmodule.raw_module.RawDescriptor'
,
'host'
:
'localhost'
,
'host'
:
'localhost'
,
'db'
:
'test_xmodule'
,
'db'
:
'test_xmodule'
,
'collection'
:
'modulestore
_
%
s'
%
uuid4
()
.
hex
,
'collection'
:
'modulestore
'
,
'fs_root'
:
data_dir
,
'fs_root'
:
data_dir
,
'render_template'
:
'mitxmako.shortcuts.render_to_string'
'render_template'
:
'mitxmako.shortcuts.render_to_string'
}
}
...
@@ -30,28 +30,24 @@ def draft_mongo_store_config(data_dir):
...
@@ -30,28 +30,24 @@ def draft_mongo_store_config(data_dir):
"""
"""
Defines default module store using DraftMongoModuleStore.
Defines default module store using DraftMongoModuleStore.
"""
"""
modulestore_options
=
{
'default_class'
:
'xmodule.raw_module.RawDescriptor'
,
'host'
:
'localhost'
,
'db'
:
'xmodule'
,
'collection'
:
'modulestore_
%
s'
%
uuid4
()
.
hex
,
'fs_root'
:
data_dir
,
'render_template'
:
'mitxmako.shortcuts.render_to_string'
}
return
{
return
{
'default'
:
{
'default'
:
{
'ENGINE'
:
'xmodule.modulestore.mongo.DraftMongoModuleStore'
,
'ENGINE'
:
'xmodule.modulestore.mongo.DraftMongoModuleStore'
,
'OPTIONS'
:
{
'OPTIONS'
:
modulestore_options
'default_class'
:
'xmodule.raw_module.RawDescriptor'
,
'host'
:
'localhost'
,
'db'
:
'test_xmodule'
,
'collection'
:
'modulestore_
%
s'
%
uuid4
()
.
hex
,
'fs_root'
:
data_dir
,
'render_template'
:
'mitxmako.shortcuts.render_to_string'
,
}
},
},
'direct'
:
{
'direct'
:
{
'ENGINE'
:
'xmodule.modulestore.mongo.MongoModuleStore'
,
'ENGINE'
:
'xmodule.modulestore.mongo.MongoModuleStore'
,
'OPTIONS'
:
{
'OPTIONS'
:
modulestore_options
'default_class'
:
'xmodule.raw_module.RawDescriptor'
,
'host'
:
'localhost'
,
'db'
:
'test_xmodule'
,
'collection'
:
'modulestore_
%
s'
%
uuid4
()
.
hex
,
'fs_root'
:
data_dir
,
'render_template'
:
'mitxmako.shortcuts.render_to_string'
,
}
}
}
}
}
...
...
lms/djangoapps/courseware/tests/test_navigation.py
View file @
7f017d0c
...
@@ -20,8 +20,8 @@ class TestNavigation(ModuleStoreTestCase, LoginEnrollmentTestCase):
...
@@ -20,8 +20,8 @@ class TestNavigation(ModuleStoreTestCase, LoginEnrollmentTestCase):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
course
=
CourseFactory
.
create
(
)
self
.
test_course
=
CourseFactory
.
create
(
display_name
=
'Robot_Sub_Course'
)
self
.
full
=
CourseFactory
.
create
(
display_name
=
'Robot_Sub
_Course'
)
self
.
course
=
CourseFactory
.
create
(
display_name
=
'Robot_Super
_Course'
)
self
.
chapter0
=
ItemFactory
.
create
(
parent_location
=
self
.
course
.
location
,
self
.
chapter0
=
ItemFactory
.
create
(
parent_location
=
self
.
course
.
location
,
display_name
=
'Overview'
)
display_name
=
'Overview'
)
self
.
chapter9
=
ItemFactory
.
create
(
parent_location
=
self
.
course
.
location
,
self
.
chapter9
=
ItemFactory
.
create
(
parent_location
=
self
.
course
.
location
,
...
@@ -46,7 +46,7 @@ class TestNavigation(ModuleStoreTestCase, LoginEnrollmentTestCase):
...
@@ -46,7 +46,7 @@ class TestNavigation(ModuleStoreTestCase, LoginEnrollmentTestCase):
email
,
password
=
self
.
STUDENT_INFO
[
0
]
email
,
password
=
self
.
STUDENT_INFO
[
0
]
self
.
login
(
email
,
password
)
self
.
login
(
email
,
password
)
self
.
enroll
(
self
.
course
,
True
)
self
.
enroll
(
self
.
course
,
True
)
self
.
enroll
(
self
.
full
,
True
)
self
.
enroll
(
self
.
test_course
,
True
)
resp
=
self
.
client
.
get
(
reverse
(
'courseware'
,
resp
=
self
.
client
.
get
(
reverse
(
'courseware'
,
kwargs
=
{
'course_id'
:
self
.
course
.
id
}))
kwargs
=
{
'course_id'
:
self
.
course
.
id
}))
...
@@ -64,7 +64,7 @@ class TestNavigation(ModuleStoreTestCase, LoginEnrollmentTestCase):
...
@@ -64,7 +64,7 @@ class TestNavigation(ModuleStoreTestCase, LoginEnrollmentTestCase):
email
,
password
=
self
.
STUDENT_INFO
[
0
]
email
,
password
=
self
.
STUDENT_INFO
[
0
]
self
.
login
(
email
,
password
)
self
.
login
(
email
,
password
)
self
.
enroll
(
self
.
course
,
True
)
self
.
enroll
(
self
.
course
,
True
)
self
.
enroll
(
self
.
full
,
True
)
self
.
enroll
(
self
.
test_course
,
True
)
self
.
client
.
get
(
reverse
(
'courseware_section'
,
kwargs
=
{
'course_id'
:
self
.
course
.
id
,
self
.
client
.
get
(
reverse
(
'courseware_section'
,
kwargs
=
{
'course_id'
:
self
.
course
.
id
,
'chapter'
:
'Overview'
,
'chapter'
:
'Overview'
,
...
@@ -84,7 +84,7 @@ class TestNavigation(ModuleStoreTestCase, LoginEnrollmentTestCase):
...
@@ -84,7 +84,7 @@ class TestNavigation(ModuleStoreTestCase, LoginEnrollmentTestCase):
email
,
password
=
self
.
STUDENT_INFO
[
0
]
email
,
password
=
self
.
STUDENT_INFO
[
0
]
self
.
login
(
email
,
password
)
self
.
login
(
email
,
password
)
self
.
enroll
(
self
.
course
,
True
)
self
.
enroll
(
self
.
course
,
True
)
self
.
enroll
(
self
.
full
,
True
)
self
.
enroll
(
self
.
test_course
,
True
)
# Now we directly navigate to a section in a chapter other than 'Overview'.
# Now we directly navigate to a section in a chapter other than 'Overview'.
check_for_get_code
(
self
,
200
,
reverse
(
'courseware_section'
,
check_for_get_code
(
self
,
200
,
reverse
(
'courseware_section'
,
...
...
lms/djangoapps/courseware/tests/test_view_authentication.py
View file @
7f017d0c
This diff is collapsed.
Click to expand it.
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