From 7e6bf6d8746ad06abd4810ed0c6dd7dcd7284dd2 Mon Sep 17 00:00:00 2001 From: Dmitry Dygalo Date: Fri, 8 May 2020 20:02:33 +0200 Subject: [PATCH] refactor: Rename `_get_response_schema` to `get_response_schema` --- src/schemathesis/schemas.py | 12 +++--------- src/schemathesis/specs/openapi/checks.py | 4 ++-- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/schemathesis/schemas.py b/src/schemathesis/schemas.py index c495cf3ca7..b619ba93fe 100644 --- a/src/schemathesis/schemas.py +++ b/src/schemathesis/schemas.py @@ -147,9 +147,7 @@ def clone( # pylint: disable=too-many-arguments validate_schema=validate_schema, # type: ignore ) - def _get_response_schema( - self, definition: Dict[str, Any], scope: str - ) -> Tuple[List[str], Optional[Dict[str, Any]]]: + def get_response_schema(self, definition: Dict[str, Any], scope: str) -> Tuple[List[str], Optional[Dict[str, Any]]]: """Extract response schema from `responses`.""" raise NotImplementedError @@ -338,9 +336,7 @@ def parameter_to_json_schema(self, data: Dict[str, Any]) -> Dict[str, Any]: if not (key == "required" and not isinstance(value, list)) } - def _get_response_schema( - self, definition: Dict[str, Any], scope: str - ) -> Tuple[List[str], Optional[Dict[str, Any]]]: + def get_response_schema(self, definition: Dict[str, Any], scope: str) -> Tuple[List[str], Optional[Dict[str, Any]]]: scopes, definition = self.resolver.resolve_in_scope(deepcopy(definition), scope) schema = definition.get("schema") if not schema: @@ -432,9 +428,7 @@ def parameter_to_json_schema(self, data: Dict[str, Any]) -> Dict[str, Any]: # "schema" field is required for all parameters in Open API 3.0 return super().parameter_to_json_schema(data["schema"]) - def _get_response_schema( - self, definition: Dict[str, Any], scope: str - ) -> Tuple[List[str], Optional[Dict[str, Any]]]: + def get_response_schema(self, definition: Dict[str, Any], scope: str) -> Tuple[List[str], Optional[Dict[str, Any]]]: scopes, definition = self.resolver.resolve_in_scope(deepcopy(definition), scope) options = iter(definition.get("content", {}).values()) option = next(options, None) diff --git a/src/schemathesis/specs/openapi/checks.py b/src/schemathesis/specs/openapi/checks.py index a71ef0d351..d15c7d4d58 100644 --- a/src/schemathesis/specs/openapi/checks.py +++ b/src/schemathesis/specs/openapi/checks.py @@ -72,7 +72,7 @@ def response_schema_conformance(response: GenericResponse, case: "Case") -> None else: # No response defined for the received response status code return - scopes, schema = case.endpoint.schema._get_response_schema(definition, case.endpoint.definition.scope) + scopes, schema = case.endpoint.schema.get_response_schema(definition, case.endpoint.definition.scope) if not schema: return if isinstance(response, requests.Response): @@ -92,7 +92,7 @@ def response_schema_conformance(response: GenericResponse, case: "Case") -> None def in_scopes(resolver: jsonschema.RefResolver, scopes: List[str]) -> Generator[None, None, None]: """Push all available scopes into the resolver. - There could be an additional scope change during schema resolving in `_get_response_schema`, so in total there + There could be an additional scope change during schema resolving in `get_response_schema`, so in total there could be a stack of two scopes maximum. This context manager handles both cases (1 or 2 scope changes) in the same way. """