Commit 572ea256 by Bill DeRusha

Convert segment country to unicode.

parent 1804ee77
"""Tests for account creation""" """Tests for account creation"""
from datetime import datetime
import json import json
import unittest
import ddt import ddt
import unittest
from django.contrib.auth.models import User
from django.test.client import RequestFactory
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User, AnonymousUser
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.contrib.auth.models import AnonymousUser
from django.utils.importlib import import_module
from django.test import TestCase, TransactionTestCase from django.test import TestCase, TransactionTestCase
from django.test.client import RequestFactory
from django.test.utils import override_settings from django.test.utils import override_settings
from django.utils.importlib import import_module
import mock import mock
from openedx.core.djangoapps.user_api.preferences.api import get_user_preference from openedx.core.djangoapps.user_api.preferences.api import get_user_preference
from lang_pref import LANGUAGE_KEY from lang_pref import LANGUAGE_KEY
from notification_prefs import NOTIFICATION_PREF_KEY from notification_prefs import NOTIFICATION_PREF_KEY
from edxmako.tests import mako_middleware_process_request from edxmako.tests import mako_middleware_process_request
from external_auth.models import ExternalAuthMap from external_auth.models import ExternalAuthMap
import student import student
...@@ -115,6 +113,42 @@ class TestCreateAccount(TestCase): ...@@ -115,6 +113,42 @@ class TestCreateAccount(TestCase):
"microsite_configuration.middleware.MicrositeMiddleware" in settings.MIDDLEWARE_CLASSES, "microsite_configuration.middleware.MicrositeMiddleware" in settings.MIDDLEWARE_CLASSES,
"Microsites not implemented in this environment" "Microsites not implemented in this environment"
) )
@override_settings(LMS_SEGMENT_KEY="testkey")
@mock.patch('student.views.analytics.track')
@mock.patch('student.views.analytics.identify')
def test_segment_tracking(self, mock_segment_identify, _):
year = datetime.now().year
self.params.update({
"level_of_education": "a",
"gender": "o",
"mailing_address": "123 Example Rd",
"city": "Exampleton",
"country": "US",
"goals": "To test this feature",
"year_of_birth": str(year),
"extra1": "extra_value1",
"extra2": "extra_value2",
})
expected_payload = {
'email': self.params['email'],
'username': self.params['username'],
'name': self.params['name'],
'age': 0,
'education': 'Associate degree',
'address': self.params['mailing_address'],
'gender': 'Other/Prefer Not to Say',
'country': self.params['country'],
}
self.create_account_and_fetch_profile()
mock_segment_identify.assert_called_with(1, expected_payload)
@unittest.skipUnless(
"microsite_configuration.middleware.MicrositeMiddleware" in settings.MIDDLEWARE_CLASSES,
"Microsites not implemented in this environment"
)
def test_profile_saved_all_optional_fields(self): def test_profile_saved_all_optional_fields(self):
self.params.update({ self.params.update({
"level_of_education": "a", "level_of_education": "a",
......
...@@ -1632,7 +1632,7 @@ def create_account_with_params(request, params): ...@@ -1632,7 +1632,7 @@ def create_account_with_params(request, params):
'education': profile.level_of_education_display, 'education': profile.level_of_education_display,
'address': profile.mailing_address, 'address': profile.mailing_address,
'gender': profile.gender_display, 'gender': profile.gender_display,
'country': profile.country, 'country': unicode(profile.country),
} }
] ]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment