mirror of https://github.com/zulip/zulip.git
tests: Simplify set_http_host to dedupe its logic.
This will make it easier to change this logic.
This commit is contained in:
parent
e4b4f67b44
commit
6d403ff255
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue