py3: Switch almost all shebang lines to use `python3`.
This causes `upgrade-zulip-from-git`, as well as a no-option run of
`tools/build-release-tarball`, to produce a Zulip install running
Python 3, rather than Python 2. In particular this means that the
virtualenv we create, in which all application code runs, is Python 3.
One shebang line, on `zulip-ec2-configure-interfaces`, explicitly
keeps Python 2, and at least one external ops script, `wal-e`, also
still runs on Python 2. See discussion on the respective previous
commits that made those explicit. There may also be some other
third-party scripts we use, outside of this source tree and running
outside our virtualenv, that still run on Python 2.
2017-08-02 23:15:16 +02:00
|
|
|
#!/usr/bin/env python3
|
2018-04-28 02:21:12 +02:00
|
|
|
import argparse
|
2017-01-13 13:50:39 +01:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2017-02-05 21:24:28 +01:00
|
|
|
# check for the venv
|
|
|
|
from lib import sanity_check
|
|
|
|
sanity_check.check_venv(__file__)
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2017-08-28 01:03:45 +02:00
|
|
|
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
sys.path.insert(0, ZULIP_PATH)
|
|
|
|
os.chdir(ZULIP_PATH)
|
2017-01-13 13:50:39 +01:00
|
|
|
|
|
|
|
from zulip import Client
|
|
|
|
|
2019-06-20 18:27:09 +02:00
|
|
|
from tools.lib.test_script import assert_provisioning_status_ok
|
2017-01-13 13:50:39 +01:00
|
|
|
from tools.lib.test_server import test_server_running
|
|
|
|
|
2018-09-06 20:40:22 +02:00
|
|
|
usage = """test-api [options]"""
|
2018-04-28 02:21:12 +02:00
|
|
|
parser = argparse.ArgumentParser(usage)
|
|
|
|
parser.add_argument('--force', dest='force',
|
|
|
|
action="store_true",
|
|
|
|
default=False, help='Run tests despite possible provisioning problems.')
|
|
|
|
options = parser.parse_args()
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2019-06-20 18:27:09 +02:00
|
|
|
assert_provisioning_status_ok(options.force)
|
2018-04-28 02:21:12 +02:00
|
|
|
|
|
|
|
with test_server_running(force=options.force, external_host='zulipdev.com:9981'):
|
2019-08-16 21:13:53 +02:00
|
|
|
# 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
|
|
|
|
|
2018-06-23 22:46:44 +02:00
|
|
|
print("Running API tests...")
|
|
|
|
|
|
|
|
# Prepare the admin client
|
2017-05-17 23:24:05 +02:00
|
|
|
email = 'iago@zulip.com' # Iago is an admin
|
2017-07-19 15:35:08 +02:00
|
|
|
realm = get_realm("zulip")
|
2018-08-01 10:53:40 +02:00
|
|
|
user = get_user(email, realm)
|
|
|
|
api_key = get_api_key(user)
|
2017-10-02 22:12:58 +02:00
|
|
|
site = 'http://zulip.zulipdev.com:9981'
|
2017-01-13 13:50:39 +01:00
|
|
|
|
|
|
|
client = Client(
|
|
|
|
email=email,
|
|
|
|
api_key=api_key,
|
2018-06-23 22:46:44 +02:00
|
|
|
site=site
|
|
|
|
)
|
2017-01-26 01:42:09 +01:00
|
|
|
|
2018-06-23 22:46:44 +02:00
|
|
|
# Prepare the admin client
|
|
|
|
email = 'guest@zulip.com' # guest is not an admin
|
|
|
|
guest_user = do_create_user('guest@zulip.com', 'secret',
|
|
|
|
get_realm('zulip'), 'Mr. Guest', 'guest')
|
2018-08-01 10:53:40 +02:00
|
|
|
api_key = get_api_key(guest_user)
|
2018-02-16 21:26:43 +01:00
|
|
|
nonadmin_client = Client(
|
|
|
|
email=email,
|
|
|
|
api_key=api_key,
|
|
|
|
site=site
|
|
|
|
)
|
|
|
|
|
2018-06-23 22:46:44 +02:00
|
|
|
test_the_api(client, nonadmin_client)
|
2018-02-16 21:26:43 +01:00
|
|
|
|
2018-02-06 21:04:07 +01:00
|
|
|
# Test error payloads
|
|
|
|
client = Client(
|
|
|
|
email=email,
|
|
|
|
api_key='abcedrsdfd',
|
|
|
|
site=site
|
|
|
|
)
|
|
|
|
test_invalid_api_key(client)
|
|
|
|
|
|
|
|
|
2017-01-26 01:42:09 +01:00
|
|
|
print("API tests passed!")
|