From 572ea25678f758ebc89ed99fda8af5d3abffadd3 Mon Sep 17 00:00:00 2001 From: Bill DeRusha Date: Fri, 30 Oct 2015 14:34:46 -0400 Subject: [PATCH] Convert segment country to unicode. --- .../student/tests/test_create_account.py | 48 ++++++++++++++++--- common/djangoapps/student/views.py | 2 +- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/common/djangoapps/student/tests/test_create_account.py b/common/djangoapps/student/tests/test_create_account.py index e3a4bd959a..8bcf23c911 100644 --- a/common/djangoapps/student/tests/test_create_account.py +++ b/common/djangoapps/student/tests/test_create_account.py @@ -1,23 +1,21 @@ """Tests for account creation""" +from datetime import datetime import json +import unittest import ddt -import unittest -from django.contrib.auth.models import User -from django.test.client import RequestFactory from django.conf import settings +from django.contrib.auth.models import User, AnonymousUser 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.client import RequestFactory from django.test.utils import override_settings - +from django.utils.importlib import import_module import mock from openedx.core.djangoapps.user_api.preferences.api import get_user_preference from lang_pref import LANGUAGE_KEY from notification_prefs import NOTIFICATION_PREF_KEY - from edxmako.tests import mako_middleware_process_request from external_auth.models import ExternalAuthMap import student @@ -111,6 +109,42 @@ class TestCreateAccount(TestCase): ) self.assertIsNone(profile.year_of_birth) + @unittest.skipUnless( + "microsite_configuration.middleware.MicrositeMiddleware" in settings.MIDDLEWARE_CLASSES, + "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" diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index 97df4883e9..550a72e5b4 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -1632,7 +1632,7 @@ def create_account_with_params(request, params): 'education': profile.level_of_education_display, 'address': profile.mailing_address, 'gender': profile.gender_display, - 'country': profile.country, + 'country': unicode(profile.country), } ]