test_helpers: Add HostRequestMock helper class.

This commit is contained in:
Tim Abbott
2016-09-27 21:06:21 -07:00
parent 97a2e53992
commit bbab3cdc30
2 changed files with 13 additions and 4 deletions

View File

@@ -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]]

View File

@@ -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")