Add email opt in to old login and register pages
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""Tests for the login and registration form rendering. """
|
||||
import urllib
|
||||
import unittest
|
||||
from collections import OrderedDict
|
||||
from mock import patch
|
||||
from django.conf import settings
|
||||
from django.core.urlresolvers import reverse
|
||||
@@ -125,6 +126,29 @@ class LoginFormTest(ModuleStoreTestCase):
|
||||
)
|
||||
self.assertContains(response, expected_url)
|
||||
|
||||
@ddt.data(None, "true", "false")
|
||||
def test_email_opt_in(self, opt_in_value):
|
||||
params = {
|
||||
'course_id': self.course_id,
|
||||
'enrollment_action': 'enroll'
|
||||
}
|
||||
|
||||
if opt_in_value is not None:
|
||||
params['email_opt_in'] = opt_in_value
|
||||
|
||||
# Get the login page
|
||||
response = self.client.get(self.url, params)
|
||||
|
||||
# Verify that the hidden parameter is set correctly
|
||||
hidden_param = '<input type="hidden" name="email_opt_in" value="{val}"'.format(
|
||||
val=opt_in_value
|
||||
)
|
||||
|
||||
if opt_in_value is not None:
|
||||
self.assertContains(response, hidden_param)
|
||||
else:
|
||||
self.assertNotContains(response, hidden_param)
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
@override_settings(MODULESTORE=MODULESTORE_CONFIG)
|
||||
@@ -182,3 +206,32 @@ class RegisterFormTest(ModuleStoreTestCase):
|
||||
redirect_url=reverse("shoppingcart.views.show_cart")
|
||||
)
|
||||
self.assertContains(response, expected_url)
|
||||
|
||||
@ddt.data(None, "true", "false")
|
||||
def test_email_opt_in(self, opt_in_value):
|
||||
params = OrderedDict()
|
||||
params['course_id'] = self.course_id
|
||||
params['enrollment_action'] = 'enroll'
|
||||
|
||||
if opt_in_value is not None:
|
||||
params['email_opt_in'] = opt_in_value
|
||||
|
||||
# Get the login page
|
||||
response = self.client.get(self.url, params)
|
||||
|
||||
# Verify that the hidden parameter is set correctly
|
||||
hidden_param = '<input type="hidden" name="email_opt_in" value="{val}"'.format(
|
||||
val=opt_in_value
|
||||
)
|
||||
|
||||
if opt_in_value is not None:
|
||||
self.assertContains(response, hidden_param)
|
||||
else:
|
||||
self.assertNotContains(response, hidden_param)
|
||||
|
||||
# Verify that the login link preserves the querystring params
|
||||
login_link = u"{url}?{params}".format(
|
||||
url=reverse('signin_user'),
|
||||
params=urllib.urlencode(params)
|
||||
)
|
||||
self.assertContains(response, login_link)
|
||||
|
||||
@@ -364,8 +364,10 @@ def signin_user(request):
|
||||
return redirect(reverse('dashboard'))
|
||||
|
||||
course_id = request.GET.get('course_id')
|
||||
email_opt_in = request.GET.get('email_opt_in')
|
||||
context = {
|
||||
'course_id': course_id,
|
||||
'email_opt_in': email_opt_in,
|
||||
'enrollment_action': request.GET.get('enrollment_action'),
|
||||
# Bool injected into JS to submit form if we're inside a running third-
|
||||
# party auth pipeline; distinct from the actual instance of the running
|
||||
@@ -394,9 +396,11 @@ def register_user(request, extra_context=None):
|
||||
return external_auth.views.redirect_with_get('root', request.GET)
|
||||
|
||||
course_id = request.GET.get('course_id')
|
||||
email_opt_in = request.GET.get('email_opt_in')
|
||||
|
||||
context = {
|
||||
'course_id': course_id,
|
||||
'email_opt_in': email_opt_in,
|
||||
'email': '',
|
||||
'enrollment_action': request.GET.get('enrollment_action'),
|
||||
'name': '',
|
||||
|
||||
@@ -198,6 +198,10 @@
|
||||
<input type="hidden" name="course_id" value="${course_id | h}" />
|
||||
% endif
|
||||
|
||||
% if email_opt_in:
|
||||
<input type="hidden" name="email_opt_in" value="${email_opt_in | h}" />
|
||||
% endif
|
||||
|
||||
<div class="form-actions">
|
||||
<button name="submit" type="submit" id="submit" class="action action-primary action-update login-button"></button>
|
||||
</div>
|
||||
|
||||
@@ -158,8 +158,12 @@
|
||||
</html>
|
||||
|
||||
<%def name="login_query()">${
|
||||
u"?course_id={0}&enrollment_action={1}".format(
|
||||
u"?course_id={0}&enrollment_action={1}{email_opt_in}".format(
|
||||
urlquote_plus(course_id),
|
||||
urlquote_plus(enrollment_action)
|
||||
urlquote_plus(enrollment_action),
|
||||
email_opt_in=(
|
||||
u"&email_opt_in=" + urlquote_plus(email_opt_in)
|
||||
if email_opt_in else ""
|
||||
)
|
||||
) if course_id and enrollment_action else ""
|
||||
}</%def>
|
||||
|
||||
@@ -361,6 +361,10 @@
|
||||
<input type="hidden" name="course_id" value="${course_id | h}" />
|
||||
% endif
|
||||
|
||||
% if email_opt_in:
|
||||
<input type="hidden" name="email_opt_in" value="${email_opt_in | h }" />
|
||||
% endif
|
||||
|
||||
<div class="form-actions">
|
||||
<button name="submit" type="submit" id="submit" class="action action-primary action-update register-button">${_('Register')} <span class="orn-plus">+</span> ${_('Create My Account')}</button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user