mirror of
https://github.com/zulip/zulip.git
synced 2025-11-12 09:58:06 +00:00
tests: Simplify set_http_host to dedupe its logic.
This will make it easier to change this logic.
This commit is contained in:
@@ -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):
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user