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:
100RABHpy 2021-04-02 15:58:50 +05:30 committed by Tim Abbott
parent e40ebe1a5d
commit 2ead0fa824
2 changed files with 12 additions and 9 deletions

View File

@ -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]],

View File

@ -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)
)