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.
This commit is contained in:
Tim Abbott 2019-08-16 12:13:53 -07:00
parent f32382f7b7
commit e8b4e80d45
1 changed files with 7 additions and 8 deletions

View File

@ -7,7 +7,6 @@ import sys
from lib import sanity_check from lib import sanity_check
sanity_check.check_venv(__file__) sanity_check.check_venv(__file__)
import django
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, ZULIP_PATH) sys.path.insert(0, ZULIP_PATH)
os.chdir(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_script import assert_provisioning_status_ok
from tools.lib.test_server import test_server_running 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]""" usage = """test-api [options]"""
parser = argparse.ArgumentParser(usage) parser = argparse.ArgumentParser(usage)
@ -34,6 +26,13 @@ options = parser.parse_args()
assert_provisioning_status_ok(options.force) assert_provisioning_status_ok(options.force)
with test_server_running(force=options.force, external_host='zulipdev.com:9981'): 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...") print("Running API tests...")
# Prepare the admin client # Prepare the admin client