From 0322dcc6cf19308c8f212b7dd3a06eb312f9df6d Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Tue, 14 Aug 2018 20:17:23 +0000 Subject: [PATCH] tests: Add direct coverage to validate_email(). These direct tests add some line coverage. --- zerver/tests/test_auth_backends.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.py index d4a2390413..1c684c9b83 100644 --- a/zerver/tests/test_auth_backends.py +++ b/zerver/tests/test_auth_backends.py @@ -30,6 +30,7 @@ from zerver.lib.actions import ( do_reactivate_user, do_set_realm_authentication_methods, ensure_stream, + validate_email, ) from zerver.lib.mobile_auth_otp import otp_decrypt_api_key from zerver.lib.validator import validate_login_email, \ @@ -2512,7 +2513,7 @@ class TestAdminSetBackends(ZulipTestCase): self.assertTrue(dev_auth_enabled(realm)) self.assertFalse(password_auth_enabled(realm)) -class LoginEmailValidatorTestCase(ZulipTestCase): +class EmailValidatorTestCase(ZulipTestCase): def test_valid_email(self) -> None: validate_login_email(self.example_email("hamlet")) @@ -2520,6 +2521,25 @@ class LoginEmailValidatorTestCase(ZulipTestCase): with self.assertRaises(JsonableError): validate_login_email(u'hamlet') + def test_validate_email(self) -> None: + inviter = self.example_user('hamlet') + cordelia = self.example_user('cordelia') + + error, _ = validate_email(inviter, 'fred+5555@zulip.com') + self.assertIn('containing + are not allowed', error) + + _, error = validate_email(inviter, cordelia.email) + self.assertEqual(error, 'Already has an account.') + + cordelia.is_active = False + cordelia.save() + + _, error = validate_email(inviter, cordelia.email) + self.assertEqual(error, 'Already has an account.') + + _, error = validate_email(inviter, 'fred-is-fine@zulip.com') + self.assertEqual(error, None) + class LDAPBackendTest(ZulipTestCase): @override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipLDAPAuthBackend',)) def test_non_existing_realm(self) -> None: