From 5051ad6ca5d43519ffff6433ae6691ff0efabacf Mon Sep 17 00:00:00 2001 From: Lauryn Menard Date: Tue, 28 Nov 2023 20:24:27 +0100 Subject: [PATCH] api-tests: Exclude some documented endpoints from curl tests. Adds a set of excluded endpoints for the test of generated curl examples in the API documentation. Currently, only the `api/test-notify` endpoint is excluded since there would need to be a push notification bouncer set up to test that generated curl example. --- api_docs/include/rest-endpoints.md | 1 + zerver/openapi/test_curl_examples.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/api_docs/include/rest-endpoints.md b/api_docs/include/rest-endpoints.md index 198e23a3fa..3e9c54307b 100644 --- a/api_docs/include/rest-endpoints.md +++ b/api_docs/include/rest-endpoints.md @@ -117,3 +117,4 @@ * [Fetch an API key (production)](/api/fetch-api-key) * [Fetch an API key (development only)](/api/dev-fetch-api-key) +* [Send a test notification to mobile device(s)](/api/test-notify) diff --git a/zerver/openapi/test_curl_examples.py b/zerver/openapi/test_curl_examples.py index b009afb198..136bffe9a5 100644 --- a/zerver/openapi/test_curl_examples.py +++ b/zerver/openapi/test_curl_examples.py @@ -24,6 +24,12 @@ from zerver.openapi.curl_param_value_generators import ( ) from zerver.openapi.openapi import get_endpoint_from_operationid +UNTESTED_GENERATED_CURL_EXAMPLES = { + # Would need push notification bouncer set up to test the + # generated curl example for this endpoint. + "test-notify", +} + def test_generated_curl_examples_for_success(client: Client) -> None: default_authentication_line = f"{client.email}:{client.api_key}" @@ -42,9 +48,10 @@ def test_generated_curl_examples_for_success(client: Client) -> None: with open(rest_endpoints_path) as f: rest_endpoints_raw = f.read() ENDPOINT_REGEXP = re.compile(r"/api/\s*(.*?)\)") - endpoint_list = sorted(set(re.findall(ENDPOINT_REGEXP, rest_endpoints_raw))) + documented_endpoints = set(re.findall(ENDPOINT_REGEXP, rest_endpoints_raw)) + endpoints_to_test = sorted(documented_endpoints.difference(UNTESTED_GENERATED_CURL_EXAMPLES)) - for endpoint in endpoint_list: + for endpoint in endpoints_to_test: article_name = endpoint + ".md" file_name = os.path.join(settings.DEPLOY_ROOT, "api_docs/", article_name)