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.

openapi: Refactor the way we find uncalled curl test functions.

100RABHpy2ead0fa8246e
diff --git a/zerver/openapi/curl_param_value_generators.py b/zerver/openapi/curl_param_value_generators.py
index e21385c74c4..4cd6ce318c1 100644
--- a/zerver/openapi/curl_param_value_generators.py
+++ b/zerver/openapi/curl_param_value_generators.py
@@ -55,6 +55,16 @@ def openapi_param_value_generator(
return wrapper
+def assert_all_helper_functions_called() -> None:
+ """Throws an exception if any registered helpers were not called by tests"""
+ if REGISTERED_GENERATOR_FUNCTIONS == CALLED_GENERATOR_FUNCTIONS:
+ return
+
+ uncalled_functions = str(REGISTERED_GENERATOR_FUNCTIONS - CALLED_GENERATOR_FUNCTIONS)
+
+ raise Exception(f"Registered curl API generators were not called: {uncalled_functions}")
+
+
def patch_openapi_example_values(
entry: str,
params: List[Dict[str, Any]],
diff --git a/zerver/openapi/test_curl_examples.py b/zerver/openapi/test_curl_examples.py
index 72a0f9b43e5..90be1939d0b 100644
--- a/zerver/openapi/test_curl_examples.py
+++ b/zerver/openapi/test_curl_examples.py
@@ -16,10 +16,7 @@ from zulip import Client
from zerver.models import get_realm
from zerver.openapi import markdown_extension
-from zerver.openapi.curl_param_value_generators import (
- CALLED_GENERATOR_FUNCTIONS,
- REGISTERED_GENERATOR_FUNCTIONS,
-)
+from zerver.openapi.curl_param_value_generators import assert_all_helper_functions_called
def test_generated_curl_examples_for_success(client: Client, owner_client: Client) -> None:
@@ -117,8 +114,4 @@ To learn more about the test itself, see zerver/openapi/test_curl_examples.py.
)
raise
- if REGISTERED_GENERATOR_FUNCTIONS != CALLED_GENERATOR_FUNCTIONS:
- raise Exception(
- "Some registered generator functions were not called:\n"
- " " + str(REGISTERED_GENERATOR_FUNCTIONS - CALLED_GENERATOR_FUNCTIONS)
- )
+ assert_all_helper_functions_called()