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
38813977
Commit
38813977
authored
Feb 11, 2015
by
Akiva Leffert
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add optional email_opt_in parameter to enrollment end point.
JIRA: MA-286
parent
eb2d8c4e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
12 deletions
+47
-12
common/djangoapps/enrollment/tests/test_views.py
+35
-11
common/djangoapps/enrollment/views.py
+12
-1
No files found.
common/djangoapps/enrollment/tests/test_views.py
View file @
38813977
...
...
@@ -15,6 +15,7 @@ from xmodule.modulestore.tests.factories import CourseFactory
from
util.testing
import
UrlResetMixin
from
enrollment
import
api
from
enrollment.errors
import
CourseEnrollmentError
from
openedx.core.djangoapps.user_api.models
import
UserOrgTag
from
student.tests.factories
import
UserFactory
,
CourseModeFactory
from
student.models
import
CourseEnrollment
from
embargo.test_utils
import
restrict_course
...
...
@@ -82,6 +83,30 @@ class EnrollmentTest(ModuleStoreTestCase, APITestCase):
self
.
assertEqual
(
'honor'
,
data
[
'mode'
])
self
.
assertTrue
(
data
[
'is_active'
])
@ddt.data
(
(
True
,
u"True"
),
(
False
,
u"False"
),
(
None
,
None
)
)
@ddt.unpack
def
test_email_opt_in_true
(
self
,
opt_in
,
pref_value
):
"""
Verify that the email_opt_in parameter sets the underlying flag.
And that if the argument is not present, then it does not affect the flag
"""
def
_assert_no_opt_in_set
():
""" Check the tag doesn't exit"""
with
self
.
assertRaises
(
UserOrgTag
.
DoesNotExist
):
UserOrgTag
.
objects
.
get
(
user
=
self
.
user
,
org
=
self
.
course
.
id
.
org
,
key
=
"email-optin"
)
_assert_no_opt_in_set
()
self
.
_create_enrollment
(
email_opt_in
=
opt_in
)
if
opt_in
is
None
:
_assert_no_opt_in_set
()
else
:
preference
=
UserOrgTag
.
objects
.
get
(
user
=
self
.
user
,
org
=
self
.
course
.
id
.
org
,
key
=
"email-optin"
)
self
.
assertEquals
(
preference
.
value
,
pref_value
)
def
test_enroll_prof_ed
(
self
):
# Create the prod ed mode.
CourseModeFactory
.
create
(
...
...
@@ -207,21 +232,20 @@ class EnrollmentTest(ModuleStoreTestCase, APITestCase):
)
self
.
assertEqual
(
resp
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
def
_create_enrollment
(
self
,
course_id
=
None
,
username
=
None
,
expected_status
=
status
.
HTTP_200_OK
):
def
_create_enrollment
(
self
,
course_id
=
None
,
username
=
None
,
expected_status
=
status
.
HTTP_200_OK
,
email_opt_in
=
None
):
"""Enroll in the course and verify the URL we are sent to. """
course_id
=
unicode
(
self
.
course
.
id
)
if
course_id
is
None
else
course_id
username
=
self
.
user
.
username
if
username
is
None
else
username
"""Enroll in the course and verify the URL we are sent to. """
resp
=
self
.
client
.
post
(
reverse
(
'courseenrollments'
),
{
'course_details'
:
{
'course_id'
:
course_id
},
'user'
:
username
params
=
{
'course_details'
:
{
'course_id'
:
course_id
},
format
=
'json'
)
'user'
:
username
}
if
email_opt_in
is
not
None
:
params
[
'email_opt_in'
]
=
email_opt_in
resp
=
self
.
client
.
post
(
reverse
(
'courseenrollments'
),
params
,
format
=
'json'
)
self
.
assertEqual
(
resp
.
status_code
,
expected_status
)
if
expected_status
==
status
.
HTTP_200_OK
:
...
...
common/djangoapps/enrollment/views.py
View file @
38813977
...
...
@@ -5,6 +5,9 @@ consist primarily of authentication, request validation, and serialization.
"""
from
ipware.ip
import
get_ip
from
django.conf
import
settings
from
opaque_keys
import
InvalidKeyError
from
opaque_keys.edx.locator
import
CourseLocator
from
openedx.core.djangoapps.user_api
import
api
as
user_api
from
rest_framework
import
status
from
rest_framework.authentication
import
OAuth2Authentication
from
rest_framework
import
permissions
...
...
@@ -204,6 +207,9 @@ class EnrollmentListView(APIView):
* course_id: The unique identifier for the course.
* email_opt_in: A boolean indicating whether the user
wishes to opt into email from the organization running this course. Optional
**Response Values**
A collection of course enrollments for the user, or for the newly created enrollment. Each course enrollment contains:
...
...
@@ -311,7 +317,12 @@ class EnrollmentListView(APIView):
)
try
:
return
Response
(
api
.
add_enrollment
(
user
,
unicode
(
course_id
)))
response
=
api
.
add_enrollment
(
user
,
unicode
(
course_id
))
email_opt_in
=
request
.
DATA
.
get
(
'email_opt_in'
,
None
)
if
email_opt_in
is
not
None
:
org
=
course_id
.
org
user_api
.
profile
.
update_email_opt_in
(
request
.
user
,
org
,
email_opt_in
)
return
Response
(
response
)
except
CourseModeNotFoundError
as
error
:
return
Response
(
status
=
status
.
HTTP_400_BAD_REQUEST
,
...
...
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