From 72bfd9d233e9d6df3d0443bb52df9812cbd613da Mon Sep 17 00:00:00 2001 From: Robin Mackaij Date: Fri, 15 Mar 2024 20:49:50 +0100 Subject: [PATCH 1/3] delayed_load_of_openapi_spec --- src/OpenApiDriver/openapi_reader.py | 3 ++- src/OpenApiDriver/openapidriver.py | 4 ++-- src/OpenApiLibCore/openapi_libcore.py | 3 +++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/OpenApiDriver/openapi_reader.py b/src/OpenApiDriver/openapi_reader.py index 5d0e823..eb709a7 100644 --- a/src/OpenApiDriver/openapi_reader.py +++ b/src/OpenApiDriver/openapi_reader.py @@ -33,7 +33,8 @@ class OpenApiReader(AbstractReaderClass): def get_data_from_source(self) -> List[TestCaseData]: test_data: List[TestCaseData] = [] - paths = getattr(self, "paths") + read_paths_method = getattr(self, "read_paths_method") + paths: Dict[str, Any] = read_paths_method() self._filter_paths(paths) ignored_responses_ = [ diff --git a/src/OpenApiDriver/openapidriver.py b/src/OpenApiDriver/openapidriver.py index 0869f51..a42f39c 100644 --- a/src/OpenApiDriver/openapidriver.py +++ b/src/OpenApiDriver/openapidriver.py @@ -337,11 +337,11 @@ def __init__( # pylint: disable=too-many-arguments, too-many-locals, dangerous- proxies=proxies, ) - paths = self.openapi_spec["paths"] + read_paths_method = self.read_paths DataDriver.__init__( self, reader_class=OpenApiReader, - paths=paths, + read_paths_method=read_paths_method, included_paths=included_paths, ignored_paths=ignored_paths, ignored_responses=ignored_responses, diff --git a/src/OpenApiLibCore/openapi_libcore.py b/src/OpenApiLibCore/openapi_libcore.py index 20ba3c4..40f87d4 100644 --- a/src/OpenApiLibCore/openapi_libcore.py +++ b/src/OpenApiLibCore/openapi_libcore.py @@ -582,6 +582,9 @@ def _openapi_spec(self) -> Dict[str, Any]: parser = self._load_parser() return parser.specification + def read_paths(self) -> Dict[str, Any]: + return self.openapi_spec["paths"] + def _load_parser(self) -> ResolvingParser: try: From e4bdd239461f3f772b40f4ab096501d5aedecfec Mon Sep 17 00:00:00 2001 From: Robin Mackaij Date: Fri, 15 Mar 2024 21:09:54 +0100 Subject: [PATCH 2/3] Remove deprecated test --- tests/driver/unittests/test_openapidriver.py | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 tests/driver/unittests/test_openapidriver.py diff --git a/tests/driver/unittests/test_openapidriver.py b/tests/driver/unittests/test_openapidriver.py deleted file mode 100644 index 8ab716d..0000000 --- a/tests/driver/unittests/test_openapidriver.py +++ /dev/null @@ -1,14 +0,0 @@ -import unittest - -from OpenApiDriver import OpenApiDriver - - -class TestInit(unittest.TestCase): - def test_load_from_invalid_source(self): - self.assertRaises( - Exception, OpenApiDriver, source="http://localhost:8000/openapi.doc" - ) - - -if __name__ == "__main__": - unittest.main() From 75de7821a8e3536ca98d12852aea4883a1f685c9 Mon Sep 17 00:00:00 2001 From: Robin Mackaij Date: Fri, 15 Mar 2024 21:20:10 +0100 Subject: [PATCH 3/3] Update broken test --- tests/files/schema_with_allof.yaml | 2 +- tests/libcore/suites/test_schema_variations.robot | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/files/schema_with_allof.yaml b/tests/files/schema_with_allof.yaml index 8a164f8..41cb46c 100644 --- a/tests/files/schema_with_allof.yaml +++ b/tests/files/schema_with_allof.yaml @@ -43,7 +43,7 @@ paths: requestBody: description: this is a description content: - application/json: + application/hal+json: schema: allOf: - $ref: '#/components/schemas/MediaMetadata' diff --git a/tests/libcore/suites/test_schema_variations.robot b/tests/libcore/suites/test_schema_variations.robot index 1fb53da..201e2f0 100644 --- a/tests/libcore/suites/test_schema_variations.robot +++ b/tests/libcore/suites/test_schema_variations.robot @@ -16,6 +16,7 @@ Test Get Request Data For Schema With allOf ${dict}= Create Dictionary ${list}= Create List ${list_of_dict}= Create List ${dict} + ${expected_headers}= Create Dictionary content-type=application/hal+json Length Should Be ${request_data.dto.isan} 36 Length Should Be ${request_data.dto.published} 10 Should Be Equal ${request_data.dto.tags} ${list_of_dict} @@ -23,4 +24,4 @@ Test Get Request Data For Schema With allOf Length Should Be ${request_data.dto_schema.get("properties")} 4 Should Be Equal ${request_data.parameters} ${list} Should Be Equal ${request_data.params} ${dict} - Should Be Equal ${request_data.headers} ${dict} + Should Be Equal ${request_data.headers} ${expected_headers}