tests: Simplify set_http_host to dedupe its logic.

This will make it easier to change this logic.
This commit is contained in:
Greg Price 2017-10-26 18:27:29 -07:00 committed by Tim Abbott
parent e4b4f67b44
commit 6d403ff255
2 changed files with 9 additions and 11 deletions

View File

@ -113,17 +113,10 @@ class ZulipTestCase(TestCase):
def set_http_host(self, kwargs):
# type: (Dict[str, Any]) -> None
if 'subdomain' in kwargs:
if kwargs['subdomain'] != "":
kwargs["HTTP_HOST"] = "%s.%s" % (kwargs["subdomain"], settings.EXTERNAL_HOST)
else:
kwargs["HTTP_HOST"] = settings.EXTERNAL_HOST
kwargs['HTTP_HOST'] = Realm.host_for_subdomain(kwargs['subdomain'])
del kwargs['subdomain']
elif 'HTTP_HOST' not in kwargs:
if self.DEFAULT_SUBDOMAIN == "":
kwargs["HTTP_HOST"] = settings.EXTERNAL_HOST
else:
kwargs["HTTP_HOST"] = "%s.%s" % (self.DEFAULT_SUBDOMAIN,
settings.EXTERNAL_HOST,)
kwargs['HTTP_HOST'] = Realm.host_for_subdomain(self.DEFAULT_SUBDOMAIN)
@instrument_url
def client_patch(self, url, info={}, **kwargs):

View File

@ -276,8 +276,13 @@ class Realm(ModelReprMixin, models.Model):
@property
def host(self):
# type: () -> str
if self.subdomain not in [None, ""]:
return "%s.%s" % (self.subdomain, settings.EXTERNAL_HOST)
return self.host_for_subdomain(self.subdomain)
@staticmethod
def host_for_subdomain(subdomain):
# type: (str) -> str
if subdomain not in [None, ""]:
return "%s.%s" % (subdomain, settings.EXTERNAL_HOST)
return settings.EXTERNAL_HOST
@property