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 #220 from snok/resolve-pk-resolution-issues
Browse files Browse the repository at this point in the history
fixed import issue
  • Loading branch information
Goldziher authored Feb 21, 2021
2 parents e4d62b6 + 555eccd commit df82793
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## v1.3.2 2020-02-20

* Hotfix regression due to pk resolution logic

## v1.3.1 2020-02-20

Expand Down
7 changes: 1 addition & 6 deletions openapi_tester/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import json
import pathlib
from functools import cached_property
from importlib import import_module
from json import dumps, loads
from typing import Callable, Dict, List, Optional, Tuple
from urllib.parse import ParseResult, urlparse
Expand Down Expand Up @@ -146,11 +145,7 @@ def resolve_path(self, endpoint_path: str, method: str) -> Tuple[str, ResolverMa
def handle_pk_parameter( # pylint: disable=no-self-use
self, resolved_route: ResolverMatch, path: str, method: str
) -> Tuple[str, ResolverMatch]:
split_view_path = resolved_route.view_name.split(".")
view_name = split_view_path.pop()
imported_module = import_module(".".join(split_view_path))
view = getattr(imported_module, view_name)
coerced_path = BaseSchemaGenerator().coerce_path(path=path, method=method, view=view)
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])
)
Expand Down
2 changes: 1 addition & 1 deletion openapi_tester/type_declarations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
""" Type declarations Module - this file is used for type checking and type casting """
# flake8: noqa
# pylint: disable=unused-import, invalid-name, unused-argument, no-self-use, missing-function-docstring
# pylint: disable=unused-import, missing-function-docstring

import sys
from typing import TYPE_CHECKING
Expand Down
10 changes: 7 additions & 3 deletions 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.1"
version = "1.3.2"
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 Expand Up @@ -86,13 +86,17 @@ disable = """
missing-function-docstring,
import-outside-toplevel,
fixme,
too-many-locals
line-too-long,
"""
enable = "useless-suppression"

[tool.pylint.BASIC]
[tool.pylint.DESIGN]
max-args = 6
max-returns = 21
max-branches = 20
max-locals = 20

[tool.pylint.BASIC]
good-names = "_,e"

[tool.coverage.run]
Expand Down
17 changes: 7 additions & 10 deletions tests/test_schema_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from tests.utils import TEST_ROOT, iterate_schema, mock_schema, response_factory

tester = SchemaTester()
name_id = 1234567890
parameterized_path = "/api/{version}/cars/correct"
de_parameterized_path = "/api/v1/cars/correct"
method = "get"
Expand Down Expand Up @@ -102,17 +103,13 @@ def test_loader_inference(settings):
SchemaTester()


def test_drf_coerced_model_primary_key(db, client):
name = Names.objects.create(custom_id_field=1234567890)
response = client.get(f"/api/v1/{name.custom_id_field}/names")
schema_tester = SchemaTester()
schema_tester.validate_response(response)

response = client.get("/api/v1/router_generated/names/")
schema_tester = SchemaTester()
schema_tester.validate_response(response)
response = client.get(f"/api/v1/router_generated/names/{name.custom_id_field}/")
@pytest.mark.parametrize(
"url", [f"/api/v1/{name_id}/names", "/api/v1/router_generated/names/", f"/api/v1/router_generated/names/{name_id}/"]
)
def test_drf_coerced_model_primary_key(db, client, url):
Names.objects.create(custom_id_field=name_id)
schema_tester = SchemaTester()
response = client.get(url)
schema_tester.validate_response(response)


Expand Down

0 comments on commit df82793

Please sign in to comment.