forked from zulip/zulip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-api
executable file
·47 lines (35 loc) · 1.22 KB
/
test-api
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
from __future__ import print_function
import os
import sys
try:
import django
except ImportError as e:
print("ImportError: {}".format(e))
print("You need to run the Zulip tests inside a Zulip dev environment.")
print("If you are using Vagrant, you can `vagrant ssh` to enter the Vagrant guest.")
sys.exit(1)
TOOLS_DIR = os.path.dirname(__file__)
ROOT_DIR = os.path.dirname(TOOLS_DIR)
sys.path.insert(0, ROOT_DIR)
api_path = os.path.abspath(os.path.join(ROOT_DIR, 'api'))
if not os.path.exists(api_path):
raise Exception('programming error--files probably got moved')
sys.path.insert(0, api_path)
from zulip import Client
from tools.lib.test_server import test_server_running
from tools.lib.api_tests import test_the_api
os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.test_settings'
django.setup()
from zerver.models import get_user_profile_by_email
with test_server_running():
email = '[email protected]' # Iago is an admin
api_key = get_user_profile_by_email(email).api_key
site = 'http://127.0.0.1:9981'
client = Client(
email=email,
api_key=api_key,
site=site)
print("Running API tests...")
test_the_api(client)
print("API tests passed!")