From bbab3cdc3008a27da60a074954065c201f082877 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Tue, 27 Sep 2016 21:06:21 -0700 Subject: [PATCH] test_helpers: Add HostRequestMock helper class. --- zerver/lib/test_helpers.py | 11 +++++++++++ zerver/tests/test_integrations.py | 6 ++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/zerver/lib/test_helpers.py b/zerver/lib/test_helpers.py index b5d7b4fd00..79631af26e 100644 --- a/zerver/lib/test_helpers.py +++ b/zerver/lib/test_helpers.py @@ -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]] diff --git a/zerver/tests/test_integrations.py b/zerver/tests/test_integrations.py index e61df51a5f..4bd53dc91b 100644 --- a/zerver/tests/test_integrations.py +++ b/zerver/tests/test_integrations.py @@ -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")