test_signup.py: Refactor test_create_realm_with_subdomain.

Refactor test_create_realm_with_subdomain to match test_create_realm more
closely, so that it's easier to see their similarities and differences.
This commit is contained in:
Rishi Gupta 2016-11-03 17:33:46 -07:00 committed by Tim Abbott
parent 4db10a05de
commit 950831810b
1 changed files with 12 additions and 21 deletions

View File

@ -648,13 +648,14 @@ class RealmCreationTest(ZulipTestCase):
# type: () -> None
username = "user1"
password = "test"
string_id = "testid"
domain = "test.com"
email = "user1@test.com"
subdomain = "test"
realm_name = "Test"
# Make sure the realm does not exist
self.assertIsNone(get_realm(domain))
with self.settings(REALMS_HAVE_SUBDOMAINS=True), self.settings(OPEN_REALM_CREATION=True):
# Create new realm with the email
result = self.client_post('/create_realm/', {'email': email})
@ -663,38 +664,28 @@ class RealmCreationTest(ZulipTestCase):
"/accounts/send_confirm/%s@%s" % (username, domain)))
result = self.client_get(result["Location"])
self.assert_in_response("Check your email so we can get started.", result)
# Visit the confirmation link.
from django.core.mail import outbox
for message in reversed(outbox):
if email in message.to:
confirmation_link_pattern = re.compile(settings.EXTERNAL_HOST + "(\S+)>")
confirmation_url = confirmation_link_pattern.search(
message.body).groups()[0]
break
else:
raise ValueError("Couldn't find a confirmation email.")
# Visit the confirmation link.
confirmation_url = self.get_confirmation_url_from_outbox(email)
result = self.client_get(confirmation_url)
self.assertEquals(result.status_code, 200)
result = self.submit_reg_form_for_user(username,
password,
domain=domain,
result = self.submit_reg_form_for_user(username, password, domain=domain,
realm_subdomain = string_id,
realm_name=realm_name,
realm_subdomain=subdomain,
# Pass HTTP_HOST for the target subdomain
HTTP_HOST=subdomain + ".testserver")
HTTP_HOST=string_id + ".testserver")
self.assertEquals(result.status_code, 302)
# Make sure the realm is created
realm = get_realm_by_string_id(subdomain)
realm = get_realm_by_string_id(string_id)
self.assertIsNotNone(realm)
self.assertEqual(realm.string_id, subdomain)
self.assertEqual(realm.name, realm_name)
self.assertEqual(realm.subdomain, subdomain)
self.assertEqual(realm.string_id, string_id)
self.assertEqual(get_user_profile_by_email(email).realm, realm)
self.assertEqual(realm.name, realm_name)
self.assertEqual(realm.subdomain, string_id)
class UserSignUpTest(ZulipTestCase):
def test_user_default_language(self):