2020-09-15 00:24:01 +02:00
|
|
|
# Zulip's OpenAPI-based API documentation system is documented at
|
|
|
|
# https://zulip.readthedocs.io/en/latest/documentation/api.html
|
|
|
|
#
|
|
|
|
# This Python file wraps the test suite for Zulip's JavaScript API
|
|
|
|
# examples and validates the responses against our OpenAPI definitions.
|
|
|
|
|
2020-05-17 12:04:53 +02:00
|
|
|
import json
|
2020-06-11 00:54:34 +02:00
|
|
|
import os
|
2020-05-17 12:04:53 +02:00
|
|
|
import subprocess
|
|
|
|
|
|
|
|
from zulip import Client
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2020-05-17 12:04:53 +02:00
|
|
|
from zerver.openapi.openapi import validate_against_openapi_schema
|
|
|
|
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2020-05-17 12:04:53 +02:00
|
|
|
def test_js_bindings(client: Client) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
os.environ["ZULIP_USERNAME"] = client.email
|
|
|
|
os.environ["ZULIP_API_KEY"] = client.api_key
|
|
|
|
os.environ["ZULIP_REALM"] = client.base_url[:-5]
|
2020-05-17 12:04:53 +02:00
|
|
|
|
|
|
|
output = subprocess.check_output(
|
2021-02-12 08:20:45 +01:00
|
|
|
args=["node", "--unhandled-rejections=strict", "zerver/openapi/javascript_examples.js"],
|
2020-05-17 12:04:53 +02:00
|
|
|
universal_newlines=True,
|
|
|
|
)
|
|
|
|
endpoint_responses = json.loads(output)
|
|
|
|
|
|
|
|
for response_data in endpoint_responses:
|
|
|
|
print(f"Testing javascript example: {response_data['name']} ...")
|
2021-02-12 08:19:30 +01:00
|
|
|
validate_against_openapi_schema(
|
2021-02-12 08:20:45 +01:00
|
|
|
response_data["result"],
|
|
|
|
response_data["endpoint"],
|
|
|
|
response_data["method"],
|
|
|
|
response_data["status_code"],
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2020-05-17 12:04:53 +02:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
print("JavaScript examples validated.")
|