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
39b5eccf
Commit
39b5eccf
authored
Dec 21, 2015
by
Bill DeRusha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update isActive column in mailchimp upon activation
parent
99b02996
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
99 additions
and
0 deletions
+99
-0
common/djangoapps/student/models.py
+21
-0
common/djangoapps/student/tests/test_activate_account.py
+78
-0
No files found.
common/djangoapps/student/models.py
View file @
39b5eccf
...
...
@@ -504,8 +504,29 @@ class Registration(models.Model):
def
activate
(
self
):
self
.
user
.
is_active
=
True
self
.
_track_activation
()
self
.
user
.
save
()
def
_track_activation
(
self
):
""" Update the isActive flag in mailchimp for activated users."""
has_segment_key
=
getattr
(
settings
,
'LMS_SEGMENT_KEY'
,
None
)
has_mailchimp_id
=
hasattr
(
settings
,
'MAILCHIMP_NEW_USER_LIST_ID'
)
if
has_segment_key
and
has_mailchimp_id
:
identity_args
=
[
self
.
user
.
id
,
# pylint: disable=no-member
{
'email'
:
self
.
user
.
email
,
'username'
:
self
.
user
.
username
,
'activated'
:
1
,
},
{
"MailChimp"
:
{
"listId"
:
settings
.
MAILCHIMP_NEW_USER_LIST_ID
}
}
]
analytics
.
identify
(
*
identity_args
)
class
PendingNameChange
(
models
.
Model
):
user
=
models
.
OneToOneField
(
User
,
unique
=
True
,
db_index
=
True
)
...
...
common/djangoapps/student/tests/test_activate_account.py
0 → 100644
View file @
39b5eccf
"""Tests for account activation"""
from
mock
import
patch
import
unittest
from
django.conf
import
settings
from
django.contrib.auth.models
import
User
from
django.test
import
TestCase
,
override_settings
from
student.models
import
Registration
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
class
TestActivateAccount
(
TestCase
):
"""Tests for account creation"""
def
setUp
(
self
):
super
(
TestActivateAccount
,
self
)
.
setUp
()
self
.
username
=
"jack"
self
.
email
=
"jack@fake.edx.org"
self
.
user
=
User
.
objects
.
create
(
username
=
self
.
username
,
email
=
self
.
email
,
is_active
=
False
)
# Set Up Registration
self
.
registration
=
Registration
()
self
.
registration
.
register
(
self
.
user
)
self
.
registration
.
save
()
def
assert_no_tracking
(
self
,
mock_segment_identify
):
""" Assert that activate sets the flag but does not call segment. """
# Ensure that the user starts inactive
self
.
assertFalse
(
self
.
user
.
is_active
)
# Until you explicitly activate it
self
.
registration
.
activate
()
self
.
assertTrue
(
self
.
user
.
is_active
)
self
.
assertFalse
(
mock_segment_identify
.
called
)
@override_settings
(
LMS_SEGMENT_KEY
=
"testkey"
,
MAILCHIMP_NEW_USER_LIST_ID
=
"listid"
)
@patch
(
'student.models.analytics.identify'
)
def
test_activation_with_keys
(
self
,
mock_segment_identify
):
expected_segment_payload
=
{
'email'
:
self
.
email
,
'username'
:
self
.
username
,
'activated'
:
1
,
}
expected_segment_mailchimp_list
=
{
"MailChimp"
:
{
"listId"
:
settings
.
MAILCHIMP_NEW_USER_LIST_ID
}
}
# Ensure that the user starts inactive
self
.
assertFalse
(
self
.
user
.
is_active
)
# Until you explicitly activate it
self
.
registration
.
activate
()
self
.
assertTrue
(
self
.
user
.
is_active
)
mock_segment_identify
.
assert_called_with
(
self
.
user
.
id
,
expected_segment_payload
,
expected_segment_mailchimp_list
)
@override_settings
(
LMS_SEGMENT_KEY
=
"testkey"
)
@patch
(
'student.models.analytics.identify'
)
def
test_activation_without_mailchimp_key
(
self
,
mock_segment_identify
):
self
.
assert_no_tracking
(
mock_segment_identify
)
@override_settings
(
MAILCHIMP_NEW_USER_LIST_ID
=
"listid"
)
@patch
(
'student.models.analytics.identify'
)
def
test_activation_without_segment_key
(
self
,
mock_segment_identify
):
self
.
assert_no_tracking
(
mock_segment_identify
)
@patch
(
'student.models.analytics.identify'
)
def
test_activation_without_keys
(
self
,
mock_segment_identify
):
self
.
assert_no_tracking
(
mock_segment_identify
)
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