From 923c5e30637f2619e868a095502cb2114afaae9f Mon Sep 17 00:00:00 2001 From: clarammdantas Date: Thu, 30 Apr 2020 20:39:17 -0300 Subject: [PATCH] test_signup: Check if user is already registered. This tests if a user, that is already registered, is redirected to the login page when they click on an invitation. Co-authored-by: Arunika --- zerver/tests/test_signup.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.py index 4674a1b1b8..1dc3f2ddb0 100644 --- a/zerver/tests/test_signup.py +++ b/zerver/tests/test_signup.py @@ -1506,6 +1506,27 @@ so we didn't send them an invitation. We did send invitations to everyone else!" self.assert_in_success_response(["Whoops. The confirmation link has expired " "or been deactivated."], result) + def test_validate_email_not_already_in_realm(self) -> None: + email = self.nonreg_email('alice') + password = 'password' + realm = get_realm('zulip') + inviter = self.example_user('iago') + prereg_user = PreregistrationUser.objects.create( + email=email, referred_by=inviter, realm=realm) + + confirmation_link = create_confirmation_link(prereg_user, 'host', Confirmation.USER_REGISTRATION) + registration_key = confirmation_link.split('/')[-1] + + url = "/accounts/register/" + self.client_post(url, {"key": registration_key, "from_confirmation": 1, "full_name": "alice"}) + self.submit_reg_form_for_user(email, password, key=registration_key) + + url = "/accounts/register/" + response = self.client_post(url, {"key": registration_key, "from_confirmation": 1, "full_name": "alice"}) + self.assertEqual(response.status_code, 302) + self.assertEqual(response.url, reverse('django.contrib.auth.views.login') + '?email=' + + urllib.parse.quote_plus(email)) + class InvitationsTestCase(InviteUserBase): def test_do_get_user_invites(self) -> None: self.login('iago')