mirror of https://github.com/zulip/zulip.git
openapi: Refactor the way we find uncalled curl test functions.
In "test_curl_examples.py" we find the functions that registered but never called. To improve readablity, now we have the full implementation in curl_param_value_generators, rather than inspecting its fields from another module.
This commit is contained in:
parent
e40ebe1a5d
commit
2ead0fa824
|
@ -55,6 +55,16 @@ def openapi_param_value_generator(
|
||||||
return wrapper
|
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(
|
def patch_openapi_example_values(
|
||||||
entry: str,
|
entry: str,
|
||||||
params: List[Dict[str, Any]],
|
params: List[Dict[str, Any]],
|
||||||
|
|
|
@ -16,10 +16,7 @@ from zulip import Client
|
||||||
|
|
||||||
from zerver.models import get_realm
|
from zerver.models import get_realm
|
||||||
from zerver.openapi import markdown_extension
|
from zerver.openapi import markdown_extension
|
||||||
from zerver.openapi.curl_param_value_generators import (
|
from zerver.openapi.curl_param_value_generators import assert_all_helper_functions_called
|
||||||
CALLED_GENERATOR_FUNCTIONS,
|
|
||||||
REGISTERED_GENERATOR_FUNCTIONS,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_generated_curl_examples_for_success(client: Client, owner_client: Client) -> None:
|
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
|
raise
|
||||||
|
|
||||||
if REGISTERED_GENERATOR_FUNCTIONS != CALLED_GENERATOR_FUNCTIONS:
|
assert_all_helper_functions_called()
|
||||||
raise Exception(
|
|
||||||
"Some registered generator functions were not called:\n"
|
|
||||||
" " + str(REGISTERED_GENERATOR_FUNCTIONS - CALLED_GENERATOR_FUNCTIONS)
|
|
||||||
)
|
|
||||||
|
|
Loading…
Reference in New Issue