mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
Fix EXTERNAL_HOST computations in test_settings.py.
test_settings.py was setting EXTERNAL_HOST after importing settings.py, which has several variables (like SERVER_URI) that are computed from EXTERNAL_HOST. [tweaked by tabbott to add comments explaining the story here].
This commit is contained in:
@@ -23,22 +23,22 @@ class IntegrationTest(TestCase):
|
||||
# type: () -> None
|
||||
context = dict() # type: Dict[str, Any]
|
||||
add_api_uri_context(context, HostRequestMock())
|
||||
self.assertEqual(context["external_api_path_subdomain"], "zulipdev.com:9991/api")
|
||||
self.assertEqual(context["external_api_uri_subdomain"], "http://zulipdev.com:9991/api")
|
||||
self.assertEqual(context["external_api_path_subdomain"], "testserver/api")
|
||||
self.assertEqual(context["external_api_uri_subdomain"], "http://testserver/api")
|
||||
|
||||
@override_settings(REALMS_HAVE_SUBDOMAINS=True)
|
||||
def test_api_url_view_subdomains_base(self):
|
||||
# type: () -> None
|
||||
context = dict() # type: Dict[str, Any]
|
||||
add_api_uri_context(context, HostRequestMock())
|
||||
self.assertEqual(context["external_api_path_subdomain"], "yourZulipDomain.zulipdev.com:9991/api")
|
||||
self.assertEqual(context["external_api_uri_subdomain"], "http://yourZulipDomain.zulipdev.com:9991/api")
|
||||
self.assertEqual(context["external_api_path_subdomain"], "yourZulipDomain.testserver/api")
|
||||
self.assertEqual(context["external_api_uri_subdomain"], "http://yourZulipDomain.testserver/api")
|
||||
|
||||
@override_settings(REALMS_HAVE_SUBDOMAINS=True, EXTERNAL_HOST="zulipdev.com")
|
||||
@override_settings(REALMS_HAVE_SUBDOMAINS=True)
|
||||
def test_api_url_view_subdomains_full(self):
|
||||
# type: () -> None
|
||||
context = dict() # type: Dict[str, Any]
|
||||
request = HostRequestMock(host="mysubdomain.zulipdev.com")
|
||||
request = HostRequestMock(host="mysubdomain.testserver")
|
||||
add_api_uri_context(context, request)
|
||||
self.assertEqual(context["external_api_path_subdomain"], "mysubdomain.zulipdev.com:9991/api")
|
||||
self.assertEqual(context["external_api_uri_subdomain"], "http://mysubdomain.zulipdev.com:9991/api")
|
||||
self.assertEqual(context["external_api_path_subdomain"], "mysubdomain.testserver/api")
|
||||
self.assertEqual(context["external_api_uri_subdomain"], "http://mysubdomain.testserver/api")
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
# For the Dev VM environment, we use the same settings as the
|
||||
# sample prod_settings.py file, with a few exceptions.
|
||||
from .prod_settings_template import *
|
||||
import os
|
||||
|
||||
LOCAL_UPLOADS_DIR = 'var/uploads'
|
||||
EXTERNAL_HOST = 'zulipdev.com:9991'
|
||||
# We check the environment to support test_settings.py controlling
|
||||
# EXTERNAL_HOST.
|
||||
EXTERNAL_HOST = os.getenv('EXTERNAL_HOST', 'zulipdev.com:9991')
|
||||
ALLOWED_HOSTS = ['*']
|
||||
AUTHENTICATION_BACKENDS = ('zproject.backends.DevAuthBackend',)
|
||||
# Add some of the below if you're testing other backends
|
||||
|
||||
@@ -1,6 +1,23 @@
|
||||
from __future__ import absolute_import
|
||||
from .settings import *
|
||||
import os
|
||||
# test_settings.py works differently from
|
||||
# dev_settings.py/prod_settings.py; it actually is directly referenced
|
||||
# by the test suite as DJANGO_SETTINGS_MODULE and imports settings.py
|
||||
# directly and then hacks up the values that are different for the
|
||||
# test suite. As will be explained, this is kinda messy and probably
|
||||
# we'd be better off switching it to work more like dev_settings.py,
|
||||
# but for now, this is what we have.
|
||||
#
|
||||
# An important downside of the test_settings.py approach is that if we
|
||||
# want to change any settings that settings.py then computes
|
||||
# additional settings from (e.g. EXTERNAL_HOST), we need to do a hack
|
||||
# like the below line(s) before we import from settings, for
|
||||
# transmitting the value of EXTERNAL_HOST to dev_settings.py so that
|
||||
# it can be set there, at the right place in the settings.py flow.
|
||||
# Ick.
|
||||
if os.getenv("EXTERNAL_HOST") is None:
|
||||
os.environ["EXTERNAL_HOST"] = "testserver"
|
||||
from .settings import *
|
||||
|
||||
DATABASES["default"] = {"NAME": "zulip_test",
|
||||
"USER": "zulip_test",
|
||||
@@ -82,7 +99,6 @@ LOCAL_UPLOADS_DIR = 'var/test_uploads'
|
||||
S3_KEY = 'test-key'
|
||||
S3_SECRET_KEY = 'test-secret-key'
|
||||
S3_AUTH_UPLOADS_BUCKET = 'test-authed-bucket'
|
||||
EXTERNAL_HOST = os.getenv('EXTERNAL_HOST', "testserver")
|
||||
REALMS_HAVE_SUBDOMAINS = bool(os.getenv('REALMS_HAVE_SUBDOMAINS', False))
|
||||
|
||||
# Test Custom TOS template rendering
|
||||
|
||||
Reference in New Issue
Block a user