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): def set_http_host(self, kwargs):
# type: (Dict[str, Any]) -> None # type: (Dict[str, Any]) -> None
if 'subdomain' in kwargs: if 'subdomain' in kwargs:
if kwargs['subdomain'] != "": kwargs['HTTP_HOST'] = Realm.host_for_subdomain(kwargs['subdomain'])
kwargs["HTTP_HOST"] = "%s.%s" % (kwargs["subdomain"], settings.EXTERNAL_HOST)
else:
kwargs["HTTP_HOST"] = settings.EXTERNAL_HOST
del kwargs['subdomain'] del kwargs['subdomain']
elif 'HTTP_HOST' not in kwargs: elif 'HTTP_HOST' not in kwargs:
if self.DEFAULT_SUBDOMAIN == "": kwargs['HTTP_HOST'] = Realm.host_for_subdomain(self.DEFAULT_SUBDOMAIN)
kwargs["HTTP_HOST"] = settings.EXTERNAL_HOST
else:
kwargs["HTTP_HOST"] = "%s.%s" % (self.DEFAULT_SUBDOMAIN,
settings.EXTERNAL_HOST,)
@instrument_url @instrument_url
def client_patch(self, url, info={}, **kwargs): def client_patch(self, url, info={}, **kwargs):

View File

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