mirror of https://github.com/zulip/zulip.git
tests: Raise zerver/views/registration.py test coverage (part 2).
This commit is contained in:
parent
8ab88f5aad
commit
8cfc231d03
|
@ -534,6 +534,31 @@ so we didn't send them an invitation. We did send invitations to everyone else!"
|
|||
self.assert_json_success(self.invite(external_address, ["Denmark"]))
|
||||
self.check_sent_emails([external_address])
|
||||
|
||||
def test_invite_outside_domain_before_closing(self):
|
||||
# type: () -> None
|
||||
"""
|
||||
If you invite someone with a different domain from that of the realm
|
||||
when `restricted_to_domain = False`, but `restricted_to_domain` later
|
||||
changes to true, the invitation should succeed but the invitee's signup
|
||||
attempt should fail.
|
||||
"""
|
||||
zulip_realm = get_realm("zulip")
|
||||
zulip_realm.restricted_to_domain = False
|
||||
zulip_realm.save()
|
||||
|
||||
self.login("hamlet@zulip.com")
|
||||
external_address = "foo@example.com"
|
||||
|
||||
self.assert_json_success(self.invite(external_address, ["Denmark"]))
|
||||
self.check_sent_emails([external_address])
|
||||
|
||||
zulip_realm.restricted_to_domain = True
|
||||
zulip_realm.save()
|
||||
|
||||
result = self.submit_reg_form_for_user("foo@example.com", "password")
|
||||
self.assertEqual(result.status_code, 200)
|
||||
self.assert_in_response("only allows users with e-mail", result)
|
||||
|
||||
def test_invite_with_non_ascii_streams(self):
|
||||
# type: () -> None
|
||||
"""
|
||||
|
@ -974,6 +999,38 @@ class UserSignUpTest(ZulipTestCase):
|
|||
result = self.submit_reg_form_for_user(email, password, full_name="<invalid>")
|
||||
self.assert_in_success_response(["Invalid characters in name!"], result)
|
||||
|
||||
def test_signup_without_full_name(self):
|
||||
# type: () -> None
|
||||
"""
|
||||
Check if signing up without a full name redirects to a registration
|
||||
form.
|
||||
"""
|
||||
email = "newguy@zulip.com"
|
||||
password = "newpassword"
|
||||
|
||||
result = self.client_post('/accounts/home/', {'email': email})
|
||||
self.assertEqual(result.status_code, 302)
|
||||
self.assertTrue(result["Location"].endswith(
|
||||
"/accounts/send_confirm/%s" % (email,)))
|
||||
result = self.client_get(result["Location"])
|
||||
self.assert_in_response("Check your email so we can get started.", result)
|
||||
|
||||
# Visit the confirmation link.
|
||||
confirmation_url = self.get_confirmation_url_from_outbox(email)
|
||||
result = self.client_get(confirmation_url)
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
result = self.client_post(
|
||||
'/accounts/register/',
|
||||
{'password': password,
|
||||
'realm_name': 'Zulip Test',
|
||||
'realm_subdomain': 'zuliptest',
|
||||
'key': find_key_by_email(email),
|
||||
'realm_org_type': Realm.COMMUNITY,
|
||||
'terms': True,
|
||||
'from_confirmation': '1'})
|
||||
self.assert_in_success_response(["You're almost there."], result)
|
||||
|
||||
def test_unique_completely_open_domain(self):
|
||||
# type: () -> None
|
||||
password = "test"
|
||||
|
@ -1232,6 +1289,23 @@ class UserSignUpTest(ZulipTestCase):
|
|||
|
||||
result = self.client_get(confirmation_url)
|
||||
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.
|
||||
user_profile.is_active = True
|
||||
user_profile.save()
|
||||
result = self.submit_reg_form_for_user(email,
|
||||
password,
|
||||
realm_name=realm_name,
|
||||
realm_subdomain=subdomain,
|
||||
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()
|
||||
|
||||
result = self.submit_reg_form_for_user(email,
|
||||
password,
|
||||
realm_name=realm_name,
|
||||
|
@ -1249,6 +1323,24 @@ class UserSignUpTest(ZulipTestCase):
|
|||
self.assertEqual(result.status_code, 302)
|
||||
self.assertEqual(get_session_dict_user(self.client.session), user_profile.id)
|
||||
|
||||
def test_registration_of_active_mirror_dummy_user(self):
|
||||
# type: (Any) -> None
|
||||
"""
|
||||
Trying to activate an already-active mirror dummy user should just
|
||||
redirect to a login page.
|
||||
"""
|
||||
email = "sipbtest@mit.edu"
|
||||
|
||||
user_profile = get_user_profile_by_email(email)
|
||||
user_profile.is_mirror_dummy = True
|
||||
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'])
|
||||
|
||||
class TestOpenRealms(ZulipTestCase):
|
||||
def test_open_realm_logic(self):
|
||||
# type: () -> None
|
||||
|
|
Loading…
Reference in New Issue