Skip to content
This repository has been archived by the owner on Nov 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #223 from snok/fix-222
Browse files Browse the repository at this point in the history
Replace functools cached_property wrapper with django wrapper
  • Loading branch information
sondrelg authored Feb 25, 2021
2 parents 6707d3a + 278053a commit eca2fb2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions openapi_tester/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>", "Na'aman Hirschfeld <[email protected]>"]
maintainers = ["Na'aman Hirschfeld <[email protected]>"]
Expand Down
12 changes: 5 additions & 7 deletions tests/test_schema_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit eca2fb2

Please sign in to comment.