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-02-05 21:24:28 +01:00
|
|
|
import django
|
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
|
|
|
|
|
2018-04-28 02:21:12 +02:00
|
|
|
from tools.lib.test_script import get_provisioning_status
|
2017-01-13 13:50:39 +01:00
|
|
|
from tools.lib.test_server import test_server_running
|
2018-02-16 21:58:03 +01:00
|
|
|
from zerver.lib.api_test_helpers import test_the_api, test_invalid_api_key, \
|
|
|
|
test_update_message_edit_permission_error, \
|
2018-02-16 23:22:45 +01:00
|
|
|
test_user_not_authorized_error, test_authorization_errors_fatal
|
2017-01-13 13:50:39 +01:00
|
|
|
|
|
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.test_settings'
|
|
|
|
django.setup()
|
2018-06-23 22:46:44 +02:00
|
|
|
from zerver.lib.actions import do_create_user
|
2017-07-19 15:35:08 +02:00
|
|
|
from zerver.models import get_user, get_realm
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2018-04-28 02:21:12 +02:00
|
|
|
usage = """test-js-with-casper [options]"""
|
|
|
|
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
|
|
|
|
2018-04-28 02:21:12 +02:00
|
|
|
if not options.force:
|
|
|
|
ok, msg = get_provisioning_status()
|
|
|
|
if not ok:
|
|
|
|
print(msg)
|
|
|
|
print('If you really know what you are doing, use --force to run anyway.')
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
with test_server_running(force=options.force, external_host='zulipdev.com:9981'):
|
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")
|
|
|
|
api_key = get_user(email, realm).api_key
|
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')
|
|
|
|
api_key = guest_user.api_key
|
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!")
|