Skip to content

Commit

Permalink
test_realm_aliases.py: realm_alias to realm_domain migration.
Browse files Browse the repository at this point in the history
* Remove any occurrences of `alias` or `realm_alias`.

* Rename `test_realm_aliases.py` to `test_realm_domains.py`.
  • Loading branch information
HarshitOnGitHub authored and timabbott committed Apr 4, 2017
1 parent b40a8ea commit cebcfb8
Showing 1 changed file with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


class RealmDomainTest(ZulipTestCase):
def test_list_aliases(self):
def test_list_realm_domains(self):
# type: () -> None
self.login("[email protected]")
realm = get_realm('zulip')
Expand All @@ -41,7 +41,7 @@ def test_not_realm_admin(self):
result = self.client_delete("/json/realm/domains/15")
self.assert_json_error(result, 'Must be a realm administrator')

def test_create_alias(self):
def test_create_realm_domain(self):
# type: () -> None
self.login("[email protected]")
data = {'domain': ujson.dumps(''),
Expand Down Expand Up @@ -69,7 +69,7 @@ def test_create_alias(self):
HTTP_HOST=mit_user_profile.realm.host)
self.assert_json_success(result)

def test_patch_alias(self):
def test_patch_realm_domain(self):
# type: () -> None
self.login("[email protected]")
realm = get_realm('zulip')
Expand All @@ -89,7 +89,7 @@ def test_patch_alias(self):
self.assertEqual(result.status_code, 400)
self.assert_json_error(result, 'No entry found for domain non-existent.com.')

def test_delete_alias(self):
def test_delete_realm_domain(self):
# type: () -> None
self.login("[email protected]")
realm = get_realm('zulip')
Expand All @@ -103,19 +103,19 @@ def test_delete_alias(self):
self.assertFalse(RealmDomain.objects.filter(domain='acme.com').exists())
self.assertTrue(realm.restricted_to_domain)

def test_delete_all_aliases(self):
def test_delete_all_realm_domains(self):
# type: () -> None
self.login("[email protected]")
realm = get_realm('zulip')
query = RealmDomain.objects.filter(realm=realm)

self.assertTrue(realm.restricted_to_domain)
for alias in query.all():
do_remove_realm_domain(alias)
for realm_domain in query.all():
do_remove_realm_domain(realm_domain)
self.assertEqual(query.count(), 0)
# Deleting last alias should set `restricted_to_domain` to False.
# This should be tested on a fresh instance, since the cached
# objects would not be updated.
# Deleting last realm_domain should set `restricted_to_domain` to False.
# This should be tested on a fresh instance, since the cached objects
# would not be updated.
self.assertFalse(get_realm('zulip').restricted_to_domain)

def test_get_realm_by_email_domain(self):
Expand All @@ -124,8 +124,8 @@ def test_get_realm_by_email_domain(self):
realm2, created = do_create_realm('testrealm2', 'Test Realm 2')
realm3, created = do_create_realm('testrealm3', 'Test Realm 3')

alias1 = RealmDomain.objects.create(realm=realm1, domain='test1.com', allow_subdomains=True)
alias2 = RealmDomain.objects.create(realm=realm2, domain='test2.test1.com', allow_subdomains=False)
realm_domain_1 = RealmDomain.objects.create(realm=realm1, domain='test1.com', allow_subdomains=True)
realm_domain_2 = RealmDomain.objects.create(realm=realm2, domain='test2.test1.com', allow_subdomains=False)
RealmDomain.objects.create(realm=realm3, domain='test3.test2.test1.com', allow_subdomains=True)

def assert_and_check(email, realm_string_id):
Expand All @@ -146,11 +146,11 @@ def assert_and_check(email, realm_string_id):
assert_and_check('[email protected]', 'testrealm1')
assert_and_check('[email protected]', 'testrealm3')

do_change_realm_domain(alias1, False)
do_change_realm_domain(realm_domain_1, False)
assert_and_check('[email protected]', None)
assert_and_check('[email protected]', 'testrealm1')

do_change_realm_domain(alias2, True)
do_change_realm_domain(realm_domain_2, True)
assert_and_check('[email protected]', 'testrealm2')
assert_and_check('[email protected]', 'testrealm2')

Expand All @@ -163,7 +163,7 @@ def test_email_allowed_for_realm(self):
realm1, created = do_create_realm('testrealm1', 'Test Realm 1', restricted_to_domain=True)
realm2, created = do_create_realm('testrealm2', 'Test Realm 2', restricted_to_domain=True)

alias = RealmDomain.objects.create(realm=realm1, domain='test1.com', allow_subdomains=False)
realm_domain = RealmDomain.objects.create(realm=realm1, domain='test1.com', allow_subdomains=False)
RealmDomain.objects.create(realm=realm2, domain='test2.test1.com', allow_subdomains=True)

self.assertEqual(email_allowed_for_realm('[email protected]', realm1), True)
Expand All @@ -172,12 +172,12 @@ def test_email_allowed_for_realm(self):
self.assertEqual(email_allowed_for_realm('[email protected]', realm2), True)
self.assertEqual(email_allowed_for_realm('[email protected]', realm2), False)

do_change_realm_domain(alias, True)
do_change_realm_domain(realm_domain, True)
self.assertEqual(email_allowed_for_realm('[email protected]', realm1), True)
self.assertEqual(email_allowed_for_realm('[email protected]', realm1), True)
self.assertEqual(email_allowed_for_realm('[email protected]', realm1), False)

def test_realm_aliases_uniqueness(self):
def test_realm_realm_domains_uniqueness(self):
# type: () -> None
realm = get_realm('zulip')
with self.settings(REALMS_HAVE_SUBDOMAINS=True), self.assertRaises(IntegrityError):
Expand Down

0 comments on commit cebcfb8

Please sign in to comment.