mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 12:33:40 +00:00
test_helpers: Add HostRequestMock helper class.
This commit is contained in:
@@ -204,6 +204,17 @@ class POSTRequestMock(object):
|
||||
self._log_data = {} # type: Dict[str, Any]
|
||||
self.META = {'PATH_INFO': 'test'}
|
||||
|
||||
class HostRequestMock(object):
|
||||
"""A mock request object where get_host() works. Useful for testing
|
||||
routes that use Zulip's subdomains feature"""
|
||||
def __init__(self, host=settings.EXTERNAL_HOST):
|
||||
# type: (text_type) -> None
|
||||
self.host = host
|
||||
|
||||
def get_host(self):
|
||||
# type: () -> text_type
|
||||
return self.host
|
||||
|
||||
INSTRUMENTING = os.environ.get('TEST_INSTRUMENT_URL_COVERAGE', '') == 'TRUE'
|
||||
INSTRUMENTED_CALLS = [] # type: List[Dict[str, Any]]
|
||||
|
||||
|
||||
@@ -8,11 +8,9 @@ from typing import Any
|
||||
|
||||
from zproject.settings import DEPLOY_ROOT
|
||||
from zerver.lib.integrations import INTEGRATIONS
|
||||
from zerver.lib.test_helpers import HostRequestMock
|
||||
from zerver.views.integrations import add_api_uri_context
|
||||
|
||||
class RequestMock(object):
|
||||
pass
|
||||
|
||||
class IntegrationTest(TestCase):
|
||||
def test_check_if_every_integration_has_logo_that_exists(self):
|
||||
# type: () -> None
|
||||
@@ -22,6 +20,6 @@ class IntegrationTest(TestCase):
|
||||
def test_api_url_view_base(self):
|
||||
# type: () -> None
|
||||
context = dict() # type: Dict[str, Any]
|
||||
add_api_uri_context(context, RequestMock())
|
||||
add_api_uri_context(context, HostRequestMock())
|
||||
self.assertEqual(context["external_api_path_subdomain"], "localhost:9991/api")
|
||||
self.assertEqual(context["external_api_uri_subdomain"], "http://localhost:9991/api")
|
||||
|
||||
Reference in New Issue
Block a user