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
6b1a7dc2
Commit
6b1a7dc2
authored
Jun 19, 2014
by
Adam Palay
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevents students from accidentally changing their enrollment on login (LMS-2773)
skip tests if not run in lms
parent
844eaeff
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
0 deletions
+88
-0
common/djangoapps/student/tests/tests.py
+82
-0
common/djangoapps/student/views.py
+6
-0
No files found.
common/djangoapps/student/tests/tests.py
View file @
6b1a7dc2
...
...
@@ -431,6 +431,88 @@ class EnrollInCourseTest(TestCase):
@override_settings
(
MODULESTORE
=
TEST_DATA_MIXED_MODULESTORE
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
class
ChangeEnrollmentViewTest
(
ModuleStoreTestCase
):
"""Tests the student.views.change_enrollment view"""
def
setUp
(
self
):
super
(
ChangeEnrollmentViewTest
,
self
)
.
setUp
()
self
.
course
=
CourseFactory
.
create
()
self
.
user
=
UserFactory
.
create
(
password
=
'secret'
)
self
.
client
.
login
(
username
=
self
.
user
.
username
,
password
=
'secret'
)
self
.
url
=
reverse
(
'change_enrollment'
)
def
enroll_through_view
(
self
,
course
):
response
=
self
.
client
.
post
(
reverse
(
'change_enrollment'
),
{
'course_id'
:
course
.
id
.
to_deprecated_string
(),
'enrollment_action'
:
'enroll'
}
)
return
response
def
test_enroll_as_honor
(
self
):
"""Tests that a student can successfully enroll through this view"""
response
=
self
.
enroll_through_view
(
self
.
course
)
self
.
assertEqual
(
response
.
status_code
,
200
)
enrollment_mode
,
is_active
=
CourseEnrollment
.
enrollment_mode_for_user
(
self
.
user
,
self
.
course
.
id
)
self
.
assertTrue
(
is_active
)
self
.
assertEqual
(
enrollment_mode
,
u'honor'
)
def
test_cannot_enroll_if_already_enrolled
(
self
):
"""
Tests that a student will not be able to enroll through this view if
they are already enrolled in the course
"""
CourseEnrollment
.
enroll
(
self
.
user
,
self
.
course
.
id
)
self
.
assertTrue
(
CourseEnrollment
.
is_enrolled
(
self
.
user
,
self
.
course
.
id
))
# now try to enroll that student
response
=
self
.
enroll_through_view
(
self
.
course
)
self
.
assertEqual
(
response
.
status_code
,
400
)
def
test_change_to_honor_if_verified
(
self
):
"""
Tests that a student that is a currently enrolled verified student cannot
accidentally change their enrollment to verified
"""
CourseEnrollment
.
enroll
(
self
.
user
,
self
.
course
.
id
,
mode
=
u'verified'
)
self
.
assertTrue
(
CourseEnrollment
.
is_enrolled
(
self
.
user
,
self
.
course
.
id
))
# now try to enroll the student in the honor mode:
response
=
self
.
enroll_through_view
(
self
.
course
)
self
.
assertEqual
(
response
.
status_code
,
400
)
enrollment_mode
,
is_active
=
CourseEnrollment
.
enrollment_mode_for_user
(
self
.
user
,
self
.
course
.
id
)
self
.
assertTrue
(
is_active
)
self
.
assertEqual
(
enrollment_mode
,
u'verified'
)
def
test_change_to_honor_if_verified_not_active
(
self
):
"""
Tests that one can renroll for a course if one has already unenrolled
"""
# enroll student
CourseEnrollment
.
enroll
(
self
.
user
,
self
.
course
.
id
,
mode
=
u'verified'
)
# now unenroll student:
CourseEnrollment
.
unenroll
(
self
.
user
,
self
.
course
.
id
)
# check that they are verified but inactive
enrollment_mode
,
is_active
=
CourseEnrollment
.
enrollment_mode_for_user
(
self
.
user
,
self
.
course
.
id
)
self
.
assertFalse
(
is_active
)
self
.
assertEqual
(
enrollment_mode
,
u'verified'
)
# now enroll them through the view:
response
=
self
.
enroll_through_view
(
self
.
course
)
self
.
assertEqual
(
response
.
status_code
,
200
)
enrollment_mode
,
is_active
=
CourseEnrollment
.
enrollment_mode_for_user
(
self
.
user
,
self
.
course
.
id
)
self
.
assertTrue
(
is_active
)
self
.
assertEqual
(
enrollment_mode
,
u'honor'
)
@override_settings
(
MODULESTORE
=
TEST_DATA_MIXED_MODULESTORE
)
class
PaidRegistrationTest
(
ModuleStoreTestCase
):
"""
Tests for paid registration functionality (not verified student), involves shoppingcart
...
...
common/djangoapps/student/views.py
View file @
6b1a7dc2
...
...
@@ -613,6 +613,12 @@ def change_enrollment(request):
if
is_course_full
:
return
HttpResponseBadRequest
(
_
(
"Course is full"
))
# check to see if user is currently enrolled in that course
if
CourseEnrollment
.
is_enrolled
(
user
,
course_id
):
return
HttpResponseBadRequest
(
_
(
"Student is already enrolled"
)
)
# If this course is available in multiple modes, redirect them to a page
# where they can choose which mode they want.
available_modes
=
CourseMode
.
modes_for_course
(
course_id
)
...
...
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