openapi: Add test to see if code exists for documented endpoints.

In addition to the test which checks to to see if each endpoint in
code (urls.py) is documented in the openapi documentation (and with
the right arugments). We now also have a test to see if every
endpoint in the openapi documentation is a legitimate endpoint
also existing in code.

We do this by piggy-backing on the work done be the former test and
using set operations. This method avoid the need for an extra loop
and it uses set operations for additional speed and ease of reading.
This commit is contained in:
Hemanth V. Alluri
2019-07-08 17:38:02 +05:30
committed by Tim Abbott
parent 718744c22d
commit cecdec3097
2 changed files with 38 additions and 8 deletions

View File

@@ -1,7 +1,7 @@
# Set of helper functions to manipulate the OpenAPI files that define our REST
# API's specification.
import os
from typing import Any, Dict, List, Optional
from typing import Any, Dict, List, Optional, Set
OPENAPI_SPEC_PATH = os.path.abspath(os.path.join(
os.path.dirname(__file__),
@@ -67,6 +67,9 @@ def get_openapi_fixture(endpoint: str, method: str,
[response]['content']['application/json']['schema']
['example'])
def get_openapi_paths() -> Set[str]:
return set(openapi_spec.spec()['paths'].keys())
def get_openapi_parameters(endpoint: str,
method: str) -> List[Dict[str, Any]]:
return (openapi_spec.spec()['paths'][endpoint][method.lower()]['parameters'])