From e8b4e80d45d228f55725f3f917d1c3cb61eb6211 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Fri, 16 Aug 2019 12:13:53 -0700 Subject: [PATCH] test-api: Fix double use of django.setup. django.setup is already called (with different/better environment variables) inside test_server_running; we shouldn't be calling it just before that to make imports work. I discovered this because imports done at the wrong time would potentially incorrectly have `testserver` as the EXTERNAL_HOST. --- tools/test-api | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tools/test-api b/tools/test-api index bfbf938af0..1b12e24fe4 100755 --- a/tools/test-api +++ b/tools/test-api @@ -7,7 +7,6 @@ import sys from lib import sanity_check sanity_check.check_venv(__file__) -import django ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, ZULIP_PATH) os.chdir(ZULIP_PATH) @@ -16,13 +15,6 @@ from zulip import Client from tools.lib.test_script import assert_provisioning_status_ok from tools.lib.test_server import test_server_running -from zerver.openapi.python_examples import test_the_api, test_invalid_api_key - -os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.test_settings' -django.setup() -from zerver.lib.actions import do_create_user -from zerver.lib.users import get_api_key -from zerver.models import get_user, get_realm usage = """test-api [options]""" parser = argparse.ArgumentParser(usage) @@ -34,6 +26,13 @@ options = parser.parse_args() assert_provisioning_status_ok(options.force) with test_server_running(force=options.force, external_host='zulipdev.com:9981'): + # Zerver imports should happen after `django.setup()` is run + # by the test_server_running decorator. + from zerver.openapi.python_examples import test_the_api, test_invalid_api_key + from zerver.lib.actions import do_create_user + from zerver.lib.users import get_api_key + from zerver.models import get_user, get_realm + print("Running API tests...") # Prepare the admin client