mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
tests: Add direct coverage to validate_email().
These direct tests add some line coverage.
This commit is contained in:
@@ -30,6 +30,7 @@ from zerver.lib.actions import (
|
|||||||
do_reactivate_user,
|
do_reactivate_user,
|
||||||
do_set_realm_authentication_methods,
|
do_set_realm_authentication_methods,
|
||||||
ensure_stream,
|
ensure_stream,
|
||||||
|
validate_email,
|
||||||
)
|
)
|
||||||
from zerver.lib.mobile_auth_otp import otp_decrypt_api_key
|
from zerver.lib.mobile_auth_otp import otp_decrypt_api_key
|
||||||
from zerver.lib.validator import validate_login_email, \
|
from zerver.lib.validator import validate_login_email, \
|
||||||
@@ -2512,7 +2513,7 @@ class TestAdminSetBackends(ZulipTestCase):
|
|||||||
self.assertTrue(dev_auth_enabled(realm))
|
self.assertTrue(dev_auth_enabled(realm))
|
||||||
self.assertFalse(password_auth_enabled(realm))
|
self.assertFalse(password_auth_enabled(realm))
|
||||||
|
|
||||||
class LoginEmailValidatorTestCase(ZulipTestCase):
|
class EmailValidatorTestCase(ZulipTestCase):
|
||||||
def test_valid_email(self) -> None:
|
def test_valid_email(self) -> None:
|
||||||
validate_login_email(self.example_email("hamlet"))
|
validate_login_email(self.example_email("hamlet"))
|
||||||
|
|
||||||
@@ -2520,6 +2521,25 @@ class LoginEmailValidatorTestCase(ZulipTestCase):
|
|||||||
with self.assertRaises(JsonableError):
|
with self.assertRaises(JsonableError):
|
||||||
validate_login_email(u'hamlet')
|
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):
|
class LDAPBackendTest(ZulipTestCase):
|
||||||
@override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipLDAPAuthBackend',))
|
@override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipLDAPAuthBackend',))
|
||||||
def test_non_existing_realm(self) -> None:
|
def test_non_existing_realm(self) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user