edX-ACE support for email change messages

This commit is contained in:
Omar Al-Ithawi
2018-09-05 18:17:12 +03:00
parent f9488a8502
commit ceacfc8a75
10 changed files with 133 additions and 72 deletions

View File

@@ -17,6 +17,7 @@ from django.test.client import RequestFactory
from mock import Mock, patch
from six import iteritems
from openedx.core.djangoapps.ace_common.tests.mixins import EmailTemplateTagMixin
from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory
from openedx.core.djangoapps.user_api.accounts import PRIVATE_VISIBILITY, USERNAME_MAX_LENGTH
from openedx.core.djangoapps.user_api.accounts.api import (
@@ -64,7 +65,7 @@ def mock_render_to_string(template_name, context):
@attr(shard=2)
@skip_unless_lms
class TestAccountApi(UserSettingsEventTestMixin, RetirementTestCase):
class TestAccountApi(UserSettingsEventTestMixin, EmailTemplateTagMixin, RetirementTestCase):
"""
These tests specifically cover the parts of the API methods that are not covered by test_views.py.
This includes the specific types of error raised, and default behavior when optional arguments
@@ -215,8 +216,10 @@ class TestAccountApi(UserSettingsEventTestMixin, RetirementTestCase):
"name": "Mickey Mouse",
"email": "seems_ok@sample.com"
}
with self.assertRaises(AccountUpdateError) as context_manager:
update_account_settings(self.user, less_naughty_update)
with patch('crum.get_current_request', return_value=self.fake_request):
with self.assertRaises(AccountUpdateError) as context_manager:
update_account_settings(self.user, less_naughty_update)
self.assertIn("Error thrown from do_email_change_request", context_manager.exception.developer_message)
# Verify that the name change happened, even though the attempt to send the email failed.
@@ -229,6 +232,7 @@ class TestAccountApi(UserSettingsEventTestMixin, RetirementTestCase):
Test that email address changes are rejected when ALLOW_EMAIL_ADDRESS_CHANGE is not set.
"""
disabled_update = {"email": "valid@example.com"}
with self.assertRaises(AccountUpdateError) as context_manager:
update_account_settings(self.user, disabled_update)
self.assertIn("Email address changes have been disabled", context_manager.exception.developer_message)