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

Commit

Permalink
Update workflows (#268)
Browse files Browse the repository at this point in the history
* chore: Update pre-commit hooks

* chore: Add dependabot for GHA

* chore: Update test workflow action/matrix versions

* chore: Rename publish workflow

* fix: Pin DRF to <3.14.0 until drf-yasg issue is fixed

axnsan12/drf-yasg#810

* chore: Fix linting errors

* chore: Update python version specification

See snok/flake8-type-checking#134 for context

* chore: Remove python 3.11 from test matrix for now

* fix: Raise error in the event that we can't parse openapi version

* chore: Remove gt 3.7 requirement and specify spec validator version

* chore: Remove poetry cache
  • Loading branch information
sondrelg authored Sep 25, 2022
1 parent ab32bc1 commit 87864ba
Show file tree
Hide file tree
Showing 9 changed files with 376 additions and 218 deletions.
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 2

updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: daily
reviewers:
- sondrelg
File renamed without changes.
40 changes: 19 additions & 21 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ jobs:
linting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- uses: actions/cache@v2
- uses: actions/cache@v3
id: cache-venv
with:
path: .venv
key: venv-0 # increment to reset
key: venv-2 # increment to reset
- run: |
python -m venv .venv --upgrade-deps
source .venv/bin/activate
pip install pre-commit
if: steps.cache-venv.outputs.cache-hit != 'true'
- uses: actions/cache@v2
- uses: actions/cache@v3
id: pre-commit-cache
with:
path: ~/.cache/pre-commit
key: key-0 # increment to reset
key: key-2 # increment to reset
- run: |
source .venv/bin/activate
pre-commit run --all-files
Expand All @@ -38,30 +38,28 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ "3.7", "3.8" , "3.9", "3.10" ]
django-version: [ "3.0", "3.1", "3.2", "4.0" ]
python-version: [ "3.7.14", "3.8.14" , "3.9.14", "3.10.7" ]
django-version: [ "3.2", "4.0", "4.1" ]
exclude:
# Django v4 drops Python 3.6, and 3.7 support
# Django v4 dropped 3.7 support
- django-version: 4.0
python-version: 3.7
python-version: 3.7.14
- django-version: 4.1
python-version: 3.7.14
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "${{ matrix.python-version }}"
- uses: actions/cache@v2
id: poetry-cache
with:
path: ~/.local
key: key-3
- uses: snok/install-poetry@v1
with:
virtualenvs-create: false
- uses: actions/cache@v2
version: 1.2.1
- uses: actions/cache@v3
id: cache-venv
with:
path: .venv
key: ${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}-2
key: ${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}-6
- run: |
python -m venv .venv
source .venv/bin/activate
Expand All @@ -80,13 +78,13 @@ jobs:
with:
name: coverage-xml
path: coverage.xml
if: matrix.python-version == '3.10' && matrix.django-version == '4.0'
if: matrix.python-version == '3.10.7' && matrix.django-version == '4.1'

coverage:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions/download-artifact@v2
with:
name: coverage-xml
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 22.6.0
rev: 22.8.0
hooks:
- id: black

Expand Down Expand Up @@ -31,7 +31,7 @@ repos:
]

- repo: https://github.com/asottile/pyupgrade
rev: v2.34.0
rev: v2.38.1
hooks:
- id: pyupgrade
args: [ "--py3-plus", "--py36-plus", "--py37-plus" ]
Expand All @@ -42,7 +42,7 @@ repos:
- id: isort

- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.961'
rev: v0.971
hooks:
- id: mypy
additional_dependencies:
Expand Down
23 changes: 17 additions & 6 deletions openapi_tester/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
from prance.util.resolver import RefResolver
from rest_framework.schemas.generators import BaseSchemaGenerator, EndpointEnumerator
from rest_framework.settings import api_settings
from rest_framework.views import APIView

from openapi_tester.constants import UNDOCUMENTED_SCHEMA_SECTION_ERROR
from openapi_tester.exceptions import UndocumentedSchemaSectionError

if TYPE_CHECKING:
from typing import Any, Callable
from urllib.parse import ParseResult

from django.urls import ResolverMatch
from rest_framework.views import APIView


def handle_recursion_limit(schema: dict) -> Callable:
Expand Down Expand Up @@ -107,6 +110,14 @@ def validate_schema(schema: dict):
validator = openapi_v30_spec_validator
elif (major, minor) == ("3", "1"):
validator = openapi_v31_spec_validator
else:
raise UndocumentedSchemaSectionError(
UNDOCUMENTED_SCHEMA_SECTION_ERROR.format(
key=schema["openapi"], error_addon="Support might need to be added."
)
)
else:
raise UndocumentedSchemaSectionError(UNDOCUMENTED_SCHEMA_SECTION_ERROR.format(key=schema["openapi"]))
else:
validator = openapi_v2_spec_validator
validator.validate(schema)
Expand All @@ -120,7 +131,7 @@ def set_schema(self, schema: dict) -> None:
self.schema = self.normalize_schema_paths(de_referenced_schema)

@cached_property
def endpoints(self) -> list[str]: # pylint: disable=no-self-use
def endpoints(self) -> list[str]:
"""
Returns a list of endpoint paths.
"""
Expand Down Expand Up @@ -163,7 +174,7 @@ def handle_pk_parameter(resolved_route: ResolverMatch, path: str, method: str) -
Handle the DRF conversion of params called {pk} into a named parameter based on Model field
"""
coerced_path = BaseSchemaGenerator().coerce_path(
path=path, method=method, view=cast(APIView, resolved_route.func)
path=path, method=method, view=cast("APIView", resolved_route.func)
)
pk_field_name = "".join(
entry.replace("+ ", "") for entry in difflib.Differ().compare(path, coerced_path) if "+ " in entry
Expand All @@ -190,7 +201,7 @@ def load_schema(self) -> dict:
Loads generated schema from drf-yasg and returns it as a dict.
"""
odict_schema = self.schema_generator.get_schema(None, True)
return cast(dict, loads(dumps(odict_schema.as_odict())))
return cast("dict", loads(dumps(odict_schema.as_odict())))

def resolve_path(self, endpoint_path: str, method: str) -> tuple[str, ResolverMatch]:
de_parameterized_path, resolved_path = super().resolve_path(endpoint_path=endpoint_path, method=method)
Expand All @@ -214,7 +225,7 @@ def load_schema(self) -> dict:
"""
Loads generated schema from drf_spectacular and returns it as a dict.
"""
return cast(dict, loads(dumps(self.schema_generator.get_schema(public=True))))
return cast("dict", loads(dumps(self.schema_generator.get_schema(public=True))))

def resolve_path(self, endpoint_path: str, method: str) -> tuple[str, ResolverMatch]:
from drf_spectacular.settings import spectacular_settings
Expand Down Expand Up @@ -245,5 +256,5 @@ def load_schema(self) -> dict[str, Any]:
with open(self.path, encoding="utf-8") as file:
content = file.read()
return cast(
dict, json.loads(content) if ".json" in self.path else yaml.load(content, Loader=yaml.FullLoader)
"dict", json.loads(content) if ".json" in self.path else yaml.load(content, Loader=yaml.FullLoader)
)
6 changes: 4 additions & 2 deletions openapi_tester/schema_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import annotations

from itertools import chain
from typing import TYPE_CHECKING, Any, Callable, List, Optional, cast
from typing import TYPE_CHECKING, Any, Callable, cast

from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
Expand Down Expand Up @@ -38,6 +38,8 @@
)

if TYPE_CHECKING:
from typing import Optional

from rest_framework.response import Response


Expand Down Expand Up @@ -262,7 +264,7 @@ def test_schema_section(
if not schema_section_type:
return
combined_validators = cast(
List[Callable[[dict, Any], Optional[str]]],
"list[Callable[[dict, Any], Optional[str]]]",
[
validate_type,
validate_format,
Expand Down
Loading

0 comments on commit 87864ba

Please sign in to comment.