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:
Tim Abbott 2017-11-26 15:58:56 -08:00
parent b9bc1c2b33
commit 2210f627a5
3 changed files with 16 additions and 17 deletions

View File

@ -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:
# Mirror dummy users to be activated must be inactive
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:
# Other users should not already exist at all.
raise ValidationError('%s already has an account' % (email,))

View File

@ -2114,18 +2114,19 @@ class UserSignUpTest(ZulipTestCase):
result = self.client_get(confirmation_url, subdomain="zephyr")
self.assertEqual(result.status_code, 200)
# If the mirror dummy user is already active, attempting to submit the
# registration form should just redirect to a login page.
# If the mirror dummy user is already active, attempting to
# 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.save()
result = self.submit_reg_form_for_user(email,
password,
from_confirmation='1',
# Pass HTTP_HOST for the target subdomain
HTTP_HOST=subdomain + ".testserver")
with self.assertRaisesRegex(AssertionError, "Mirror dummy user is already active!"):
result = self.submit_reg_form_for_user(
email,
password,
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.save()
@ -2144,8 +2145,8 @@ class UserSignUpTest(ZulipTestCase):
def test_registration_of_active_mirror_dummy_user(self: Any) -> None:
"""
Trying to activate an already-active mirror dummy user should just
redirect to a login page.
Trying to activate an already-active mirror dummy user should
raise an AssertionError.
"""
user_profile = self.mit_user("sipbtest")
email = user_profile.email
@ -2153,10 +2154,8 @@ class UserSignUpTest(ZulipTestCase):
user_profile.is_active = True
user_profile.save()
result = self.client_post('/register/', {'email': email})
self.assertEqual(result.status_code, 302)
self.assertIn('login', result['Location'])
with self.assertRaisesRegex(AssertionError, "Mirror dummy user is already active!"):
self.client_post('/register/', {'email': email}, subdomain="zephyr")
class DeactivateUserTest(ZulipTestCase):

View File

@ -80,7 +80,7 @@ def accounts_register(request):
try:
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=' +
urllib.parse.quote_plus(email))