mirror of https://github.com/zulip/zulip.git
signup: Switch active mirror-dummy users to an AssertionError.
Previously, this was a ValidationError, but that doesn't really make sense, since this condition reflects an actual bug in the code. Because this happened to be our only test coverage the ValidationError catch on line 84 of registration.py, we add nocoverage there for now.
This commit is contained in:
parent
b9bc1c2b33
commit
2210f627a5
|
@ -3914,7 +3914,7 @@ def validate_email_for_realm(target_realm, email):
|
||||||
if existing_user_profile is not None and existing_user_profile.is_mirror_dummy:
|
if existing_user_profile is not None and existing_user_profile.is_mirror_dummy:
|
||||||
# Mirror dummy users to be activated must be inactive
|
# Mirror dummy users to be activated must be inactive
|
||||||
if existing_user_profile.is_active:
|
if existing_user_profile.is_active:
|
||||||
raise ValidationError('%s already has an account' % (email,))
|
raise AssertionError("Mirror dummy user is already active!")
|
||||||
elif existing_user_profile:
|
elif existing_user_profile:
|
||||||
# Other users should not already exist at all.
|
# Other users should not already exist at all.
|
||||||
raise ValidationError('%s already has an account' % (email,))
|
raise ValidationError('%s already has an account' % (email,))
|
||||||
|
|
|
@ -2114,18 +2114,19 @@ class UserSignUpTest(ZulipTestCase):
|
||||||
result = self.client_get(confirmation_url, subdomain="zephyr")
|
result = self.client_get(confirmation_url, subdomain="zephyr")
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
# If the mirror dummy user is already active, attempting to submit the
|
# If the mirror dummy user is already active, attempting to
|
||||||
# registration form should just redirect to a login page.
|
# submit the registration form should raise an AssertionError
|
||||||
|
# (this is an invalid state, so it's a bug we got here):
|
||||||
user_profile.is_active = True
|
user_profile.is_active = True
|
||||||
user_profile.save()
|
user_profile.save()
|
||||||
result = self.submit_reg_form_for_user(email,
|
with self.assertRaisesRegex(AssertionError, "Mirror dummy user is already active!"):
|
||||||
password,
|
result = self.submit_reg_form_for_user(
|
||||||
from_confirmation='1',
|
email,
|
||||||
# Pass HTTP_HOST for the target subdomain
|
password,
|
||||||
HTTP_HOST=subdomain + ".testserver")
|
from_confirmation='1',
|
||||||
|
# Pass HTTP_HOST for the target subdomain
|
||||||
|
HTTP_HOST=subdomain + ".testserver")
|
||||||
|
|
||||||
self.assertEqual(result.status_code, 302)
|
|
||||||
self.assertIn('login', result['Location'])
|
|
||||||
user_profile.is_active = False
|
user_profile.is_active = False
|
||||||
user_profile.save()
|
user_profile.save()
|
||||||
|
|
||||||
|
@ -2144,8 +2145,8 @@ class UserSignUpTest(ZulipTestCase):
|
||||||
|
|
||||||
def test_registration_of_active_mirror_dummy_user(self: Any) -> None:
|
def test_registration_of_active_mirror_dummy_user(self: Any) -> None:
|
||||||
"""
|
"""
|
||||||
Trying to activate an already-active mirror dummy user should just
|
Trying to activate an already-active mirror dummy user should
|
||||||
redirect to a login page.
|
raise an AssertionError.
|
||||||
"""
|
"""
|
||||||
user_profile = self.mit_user("sipbtest")
|
user_profile = self.mit_user("sipbtest")
|
||||||
email = user_profile.email
|
email = user_profile.email
|
||||||
|
@ -2153,10 +2154,8 @@ class UserSignUpTest(ZulipTestCase):
|
||||||
user_profile.is_active = True
|
user_profile.is_active = True
|
||||||
user_profile.save()
|
user_profile.save()
|
||||||
|
|
||||||
result = self.client_post('/register/', {'email': email})
|
with self.assertRaisesRegex(AssertionError, "Mirror dummy user is already active!"):
|
||||||
|
self.client_post('/register/', {'email': email}, subdomain="zephyr")
|
||||||
self.assertEqual(result.status_code, 302)
|
|
||||||
self.assertIn('login', result['Location'])
|
|
||||||
|
|
||||||
class DeactivateUserTest(ZulipTestCase):
|
class DeactivateUserTest(ZulipTestCase):
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ def accounts_register(request):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
validate_email_for_realm(realm, email)
|
validate_email_for_realm(realm, email)
|
||||||
except ValidationError:
|
except ValidationError: # nocoverage # We need to add a test for this.
|
||||||
return HttpResponseRedirect(reverse('django.contrib.auth.views.login') + '?email=' +
|
return HttpResponseRedirect(reverse('django.contrib.auth.views.login') + '?email=' +
|
||||||
urllib.parse.quote_plus(email))
|
urllib.parse.quote_plus(email))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue