zulip/tools/test-api

65 lines
1.7 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env python3
2017-01-13 13:50:39 +01:00
import os
import sys
# check for the venv
from lib import sanity_check
sanity_check.check_venv(__file__)
2017-01-13 13:50:39 +01:00
import django
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
from tools.lib.test_server import test_server_running
from zerver.lib.api_test_helpers import test_the_api, test_invalid_api_key, \
test_update_message_edit_permission_error, \
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()
2017-07-19 15:35:08 +02:00
from zerver.models import get_user, get_realm
2017-01-13 13:50:39 +01:00
with test_server_running(external_host='zulipdev.com:9981'):
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
site = 'http://zulip.zulipdev.com:9981'
2017-01-13 13:50:39 +01:00
client = Client(
email=email,
api_key=api_key,
site=site)
2017-01-26 01:42:09 +01:00
print("Running API tests...")
2017-01-13 13:50:39 +01:00
test_the_api(client)
2017-01-26 01:42:09 +01:00
email = 'newbie@zulip.com' # newbie is not an admin
realm = get_realm("zulip")
api_key = get_user(email, realm).api_key
site = 'http://zulip.zulipdev.com:9981'
nonadmin_client = Client(
email=email,
api_key=api_key,
site=site
)
# Run tests that require non-admin client
test_update_message_edit_permission_error(client, nonadmin_client)
test_user_not_authorized_error(nonadmin_client)
test_authorization_errors_fatal(client, nonadmin_client)
# 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!")