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 #218 from snok/branch-testing
Browse files Browse the repository at this point in the history
Enable branch testing and update development status
  • Loading branch information
Goldziher authored Feb 20, 2021
2 parents 702eee8 + ddda73a commit c1b7b40
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 12 deletions.
1 change: 0 additions & 1 deletion openapi_tester/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
from .constants import OPENAPI_PYTHON_MAPPING
from .exceptions import CaseError, DocumentationError, OpenAPISchemaError, UndocumentedSchemaSectionError
from .loaders import BaseSchemaLoader, DrfSpectacularSchemaLoader, DrfYasgSchemaLoader, StaticSchemaLoader
from .schema_converter import SchemaToPythonConverter
from .schema_tester import SchemaTester
7 changes: 2 additions & 5 deletions openapi_tester/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,7 @@ def endpoints(self) -> List[str]: # pylint: disable=no-self-use
return list({endpoint[0] for endpoint in EndpointEnumerator().get_api_endpoints()})

def resolve_path(self, endpoint_path: str, method: str) -> Tuple[str, ResolverMatch]:
"""
Resolves a Django path.
"""

""" Resolves a Django path. """
url_object = urlparse(endpoint_path)
parsed_path = url_object.path if url_object.path.endswith("/") else url_object.path + "/"
if not parsed_path.startswith("/"):
Expand Down Expand Up @@ -152,7 +149,7 @@ def handle_pk_parameter(resolved_route: ResolverMatch, path: str, method: str) -
view = getattr(imported_module, view_name)
coerced_path = BaseSchemaGenerator().coerce_path(path=path, method=method, view=view)
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 openapi_tester/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from django.core.validators import EmailValidator, URLValidator, validate_ipv4_address, validate_ipv6_address
from django.utils.dateparse import parse_date, parse_datetime, parse_time

from openapi_tester import OpenAPISchemaError
from openapi_tester.constants import (
INVALID_PATTERN_ERROR,
VALIDATE_ENUM_ERROR,
Expand All @@ -26,6 +25,7 @@
VALIDATE_TYPE_ERROR,
VALIDATE_UNIQUE_ITEMS_ERROR,
)
from openapi_tester.exceptions import OpenAPISchemaError


def create_validator(validation_fn: Callable, wrap_as_validator: bool = False) -> Callable:
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repository = "https://github.com/snok/drf-openapi-tester"
documentation = "https://github.com/snok/drf-openapi-tester"
keywords = ["openapi", "swagger", "api", "testing", "schema", "django", "drf"]
classifiers = [
"Development Status :: 4 - Beta", # TODO: Update when stable
"Development Status :: 5 - Production/Stable",
"Environment :: Web Environment",
"Framework :: Pytest",
"Framework :: Django",
Expand Down Expand Up @@ -95,11 +95,10 @@ max-returns = 21
max-branches = 20
good-names = "_,e"


[tool.coverage.run]
source = ["openapi_tester/*"]
omit = ["openapi_tester/type_declarations.py"]
branch = false
branch = true

[tool.coverage.report]
show_missing = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class SchemaToPythonConverter:
"""
This class is used both by the DocumentationError format method and the various test suites.
This class is used by various test suites.
"""

result: Any
Expand Down
2 changes: 2 additions & 0 deletions tests/test_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def test_loader_get_route(loader):
assert loader.resolve_path("/api/v1/snake-case", "get")[0] == "/api/{version}/snake-case/"
assert loader.resolve_path("api/v1/snake-case/", "get")[0] == "/api/{version}/snake-case/"
assert loader.resolve_path("api/v1/snake-case", "get")[0] == "/api/{version}/snake-case/"
with pytest.raises(ValueError, match="Could not resolve path `test`"):
assert loader.resolve_path("test", "get")


@pytest.mark.parametrize("loader", loaders)
Expand Down
2 changes: 1 addition & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import yaml
from rest_framework.response import Response

from openapi_tester.schema_converter import SchemaToPythonConverter
from tests.schema_converter import SchemaToPythonConverter

TEST_ROOT = Path(__file__).resolve(strict=True).parent

Expand Down

0 comments on commit c1b7b40

Please sign in to comment.