fixing merge conflict from release
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import json
|
||||
import django.db
|
||||
import unittest
|
||||
|
||||
from student.tests.factories import UserFactory, RegistrationFactory, PendingEmailChangeFactory
|
||||
from student.views import reactivation_email_for_user, change_email_request, confirm_email_change
|
||||
@@ -11,6 +12,9 @@ from mock import Mock, patch
|
||||
from django.http import Http404, HttpResponse
|
||||
from django.conf import settings
|
||||
from nose.plugins.skip import SkipTest
|
||||
from edxmako.shortcuts import render_to_string
|
||||
from util.request import safe_get_host
|
||||
from textwrap import dedent
|
||||
|
||||
|
||||
class TestException(Exception):
|
||||
@@ -50,6 +54,11 @@ class EmailTestMixin(object):
|
||||
settings.DEFAULT_FROM_EMAIL
|
||||
)
|
||||
|
||||
def append_allowed_hosts(self, hostname):
|
||||
""" Append hostname to settings.ALLOWED_HOSTS """
|
||||
settings.ALLOWED_HOSTS.append(hostname)
|
||||
self.addCleanup(settings.ALLOWED_HOSTS.pop)
|
||||
|
||||
|
||||
@patch('student.views.render_to_string', Mock(side_effect=mock_render_to_string, autospec=True))
|
||||
@patch('django.contrib.auth.models.User.email_user')
|
||||
@@ -83,6 +92,16 @@ class ReactivationEmailTests(EmailTestMixin, TestCase):
|
||||
context
|
||||
)
|
||||
|
||||
# Thorough tests for safe_get_host are elsewhere; here we just want a quick URL sanity check
|
||||
request = RequestFactory().post('unused_url')
|
||||
request.META['HTTP_HOST'] = "aGenericValidHostName"
|
||||
self.append_allowed_hosts("aGenericValidHostName")
|
||||
|
||||
body = render_to_string('emails/activation_email.txt', context)
|
||||
host = safe_get_host(request)
|
||||
|
||||
self.assertIn(host, body)
|
||||
|
||||
def test_reactivation_email_failure(self, email_user):
|
||||
self.user.email_user.side_effect = Exception
|
||||
response_data = self.reactivation_email(self.user)
|
||||
@@ -227,6 +246,16 @@ class EmailChangeConfirmationTests(EmailTestMixin, TransactionTestCase):
|
||||
context
|
||||
)
|
||||
|
||||
# Thorough tests for safe_get_host are elsewhere; here we just want a quick URL sanity check
|
||||
request = RequestFactory().post('unused_url')
|
||||
request.META['HTTP_HOST'] = "aGenericValidHostName"
|
||||
self.append_allowed_hosts("aGenericValidHostName")
|
||||
|
||||
body = render_to_string('emails/confirm_email_change.txt', context)
|
||||
url = safe_get_host(request)
|
||||
|
||||
self.assertIn(url, body)
|
||||
|
||||
def test_not_pending(self, email_user):
|
||||
self.key = 'not_a_key'
|
||||
self.check_confirm_email_change('invalid_email_key.html', {})
|
||||
@@ -237,6 +266,9 @@ class EmailChangeConfirmationTests(EmailTestMixin, TransactionTestCase):
|
||||
self.check_confirm_email_change('email_exists.html', {})
|
||||
self.assertFailedBeforeEmailing(email_user)
|
||||
|
||||
@unittest.skipIf(settings.FEATURES.get('DISABLE_RESET_EMAIL_TEST', False),
|
||||
dedent("""Skipping Test because CMS has not provided necessary templates for email reset.
|
||||
If LMS tests print this message, that needs to be fixed."""))
|
||||
def test_old_email_fails(self, email_user):
|
||||
email_user.side_effect = [Exception, None]
|
||||
self.check_confirm_email_change('email_change_failed.html', {
|
||||
@@ -245,6 +277,9 @@ class EmailChangeConfirmationTests(EmailTestMixin, TransactionTestCase):
|
||||
self.assertRolledBack()
|
||||
self.assertChangeEmailSent(email_user)
|
||||
|
||||
@unittest.skipIf(settings.FEATURES.get('DISABLE_RESET_EMAIL_TEST', False),
|
||||
dedent("""Skipping Test because CMS has not provided necessary templates for email reset.
|
||||
If LMS tests print this message, that needs to be fixed."""))
|
||||
def test_new_email_fails(self, email_user):
|
||||
email_user.side_effect = [None, Exception]
|
||||
self.check_confirm_email_change('email_change_failed.html', {
|
||||
@@ -253,6 +288,9 @@ class EmailChangeConfirmationTests(EmailTestMixin, TransactionTestCase):
|
||||
self.assertRolledBack()
|
||||
self.assertChangeEmailSent(email_user)
|
||||
|
||||
@unittest.skipIf(settings.FEATURES.get('DISABLE_RESET_EMAIL_TEST', False),
|
||||
dedent("""Skipping Test because CMS has not provided necessary templates for email reset.
|
||||
If LMS tests print this message, that needs to be fixed."""))
|
||||
def test_successful_email_change(self, email_user):
|
||||
self.check_confirm_email_change('email_change_successful.html', {
|
||||
'old_email': self.user.email,
|
||||
|
||||
@@ -82,7 +82,7 @@ class ResetPasswordTests(TestCase):
|
||||
self.assertEquals(bad_email_resp.content, json.dumps({'success': True,
|
||||
'value': "('registration/password_reset_done.html', [])"}))
|
||||
|
||||
@unittest.skipUnless(not settings.FEATURES.get('DISABLE_PASSWORD_RESET_EMAIL_TEST', False),
|
||||
@unittest.skipIf(settings.FEATURES.get('DISABLE_RESET_EMAIL_TEST', False),
|
||||
dedent("""Skipping Test because CMS has not provided necessary templates for password reset.
|
||||
If LMS tests print this message, that needs to be fixed."""))
|
||||
@patch('django.core.mail.send_mail')
|
||||
|
||||
Reference in New Issue
Block a user