Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

curl_examples: Add testing for template endpoints.

Suyash Vardhan Mathur44c25619d73c
diff --git a/zerver/openapi/test_curl_examples.py b/zerver/openapi/test_curl_examples.py
index 4fbcbe54db6..3edbd6e0801 100644
--- a/zerver/openapi/test_curl_examples.py
+++ b/zerver/openapi/test_curl_examples.py
@@ -22,6 +22,7 @@ from zerver.openapi.curl_param_value_generators import (
AUTHENTICATION_LINE,
assert_all_helper_functions_called,
)
+from zerver.openapi.openapi import get_endpoint_from_operationid
def test_generated_curl_examples_for_success(client: Client) -> None:
@@ -49,7 +50,8 @@ def test_generated_curl_examples_for_success(client: Client) -> None:
file_name = os.path.join(settings.DEPLOY_ROOT, "templates/zerver/api/", article_name)
curl_commands_to_test = []
- with open(file_name) as f:
+ if os.path.exists(file_name):
+ f = open(file_name, "r")
for line in f:
# Set AUTHENTICATION_LINE to default_authentication_line.
# Set this every iteration, because deactivate_own_user
@@ -59,6 +61,17 @@ def test_generated_curl_examples_for_success(client: Client) -> None:
# {generate_code_example(curl, ...}
if line.startswith("{generate_code_example(curl"):
curl_commands_to_test.append(line)
+ else:
+ # If the file doesn't exist, then it has been
+ # deleted and its page is generated by the
+ # template. Thus, the curl example would just
+ # a single one following the template's pattern.
+ endpoint_path, endpoint_method = get_endpoint_from_operationid(
+ endpoint.replace("-", "_")
+ )
+ endpoint_string = endpoint_path + ":" + endpoint_method
+ command = f"{{generate_code_example(curl)|{endpoint_string}|example}}"
+ curl_commands_to_test.append(command)
for line in curl_commands_to_test:
# To do an end-to-end test on the documentation examples