mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
js-api: Add hooks to run tests and render docs of JS API examples.
This commit adds python code to call javascript_examples.js in its two supported modes. tools/test-api asserts that the example output is as expected, whereas the API markdown extension is used to render these examples in the docs.
This commit is contained in:
committed by
Tim Abbott
parent
642d1a20d0
commit
6dd4030e67
26
zerver/openapi/javascript_examples.py
Normal file
26
zerver/openapi/javascript_examples.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import os
|
||||
import json
|
||||
import subprocess
|
||||
|
||||
from zulip import Client
|
||||
from zerver.openapi.openapi import validate_against_openapi_schema
|
||||
|
||||
def test_js_bindings(client: Client) -> None:
|
||||
os.environ['ZULIP_USERNAME'] = client.email
|
||||
os.environ['ZULIP_API_KEY'] = client.api_key
|
||||
os.environ['ZULIP_REALM'] = client.base_url[:-5]
|
||||
|
||||
output = subprocess.check_output(
|
||||
args=['node', 'zerver/openapi/javascript_examples.js'],
|
||||
universal_newlines=True,
|
||||
)
|
||||
endpoint_responses = json.loads(output)
|
||||
|
||||
for response_data in endpoint_responses:
|
||||
print(f"Testing javascript example: {response_data['name']} ...")
|
||||
validate_against_openapi_schema(response_data['result'],
|
||||
response_data['endpoint'],
|
||||
response_data['method'],
|
||||
response_data['status_code'])
|
||||
|
||||
print('JavaScript examples validated.')
|
||||
Reference in New Issue
Block a user