From 8187be1d480aaac415bfdc54da1183df941b7ae5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Lilleb=C3=B8=20Gundersen?= Date: Thu, 25 Feb 2021 12:43:01 +0000 Subject: [PATCH 1/3] Replace functools cached_property wrapper with django wrapper --- openapi_tester/loaders.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openapi_tester/loaders.py b/openapi_tester/loaders.py index 0b88ca01..c76f3856 100644 --- a/openapi_tester/loaders.py +++ b/openapi_tester/loaders.py @@ -2,13 +2,13 @@ import difflib import json import pathlib -from functools import cached_property from json import dumps, loads from typing import Callable, Dict, List, Optional, Tuple from urllib.parse import ParseResult, urlparse import yaml from django.urls import Resolver404, ResolverMatch, resolve +from django.utils.functional import cached_property from openapi_spec_validator import openapi_v2_spec_validator, openapi_v3_spec_validator # noinspection PyProtectedMember @@ -147,7 +147,7 @@ def handle_pk_parameter( # pylint: disable=no-self-use ) -> Tuple[str, ResolverMatch]: coerced_path = BaseSchemaGenerator().coerce_path(path=path, method=method, view=resolved_route.func) # type: ignore pk_field_name = "".join( - list([entry.replace("+ ", "") for entry in difflib.Differ().compare(path, coerced_path) if "+ " in entry]) + entry.replace("+ ", "") for entry in difflib.Differ().compare(path, coerced_path) if "+ " in entry ) resolved_route.kwargs[pk_field_name] = resolved_route.kwargs["pk"] del resolved_route.kwargs["pk"] From 9d69660ff34ec18d4621a7fa08de5202945c30bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Lilleb=C3=B8=20Gundersen?= Date: Thu, 25 Feb 2021 20:44:11 +0000 Subject: [PATCH 2/3] Trim match statement for flaky test --- tests/test_schema_tester.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/test_schema_tester.py b/tests/test_schema_tester.py index cabfe8c9..51916f54 100644 --- a/tests/test_schema_tester.py +++ b/tests/test_schema_tester.py @@ -193,18 +193,16 @@ def test_validate_response_failure_scenario_undocumented_status_code(monkeypatch def test_validate_response_global_case_tester(client): - tester_with_case_tester = SchemaTester(case_tester=is_pascal_case) response = client.get(de_parameterized_path) - with pytest.raises(CaseError, match="The response key `name` is not properly PascalCased. Expected value: Name"): - tester_with_case_tester.validate_response(response=response) + with pytest.raises(CaseError, match="is not properly PascalCased"): + SchemaTester(case_tester=is_pascal_case).validate_response(response=response) def test_validate_response_global_ignored_case(client): - tester_with_case_tester = SchemaTester( - case_tester=is_pascal_case, ignore_case=["name", "color", "height", "width", "length"] - ) response = client.get(de_parameterized_path) - tester_with_case_tester.validate_response(response=response) + SchemaTester( + case_tester=is_pascal_case, ignore_case=["name", "color", "height", "width", "length"] + ).validate_response(response=response) def test_validate_response_passed_in_case_tester(client): From 278053a239f70ce0e0da8994318dda46ac3631d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Lilleb=C3=B8=20Gundersen?= Date: Thu, 25 Feb 2021 20:46:08 +0000 Subject: [PATCH 3/3] Update changelog and bump patch version --- CHANGELOG.md | 4 ++++ pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 132b1896..f44d1f2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v1.3.3 2020-02-25 + +* Replace Python 3.8+ functools feature with builtin Django equivalent + ## v1.3.2 2020-02-20 * Hotfix regression due to pk resolution logic diff --git a/pyproject.toml b/pyproject.toml index f9b1ba8f..af01358c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "drf-openapi-tester" -version = "1.3.2" +version = "1.3.3" description = "Django test utility for validating OpenAPI response documentation" authors = ["Sondre Lillebø Gundersen ", "Na'aman Hirschfeld "] maintainers = ["Na'aman Hirschfeld "]