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

Commit 87864ba

Browse files
authored
Update workflows (#268)
* 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
1 parent ab32bc1 commit 87864ba

File tree

9 files changed

+376
-218
lines changed

9 files changed

+376
-218
lines changed

.github/dependabot.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: 2
2+
3+
updates:
4+
- package-ecosystem: github-actions
5+
directory: /
6+
schedule:
7+
interval: daily
8+
reviewers:
9+
- sondrelg
File renamed without changes.

.github/workflows/testing.yml

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ jobs:
1010
linting:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v2
14-
- uses: actions/setup-python@v2
13+
- uses: actions/checkout@v3
14+
- uses: actions/setup-python@v4
1515
with:
1616
python-version: "3.10"
17-
- uses: actions/cache@v2
17+
- uses: actions/cache@v3
1818
id: cache-venv
1919
with:
2020
path: .venv
21-
key: venv-0 # increment to reset
21+
key: venv-2 # increment to reset
2222
- run: |
2323
python -m venv .venv --upgrade-deps
2424
source .venv/bin/activate
2525
pip install pre-commit
2626
if: steps.cache-venv.outputs.cache-hit != 'true'
27-
- uses: actions/cache@v2
27+
- uses: actions/cache@v3
2828
id: pre-commit-cache
2929
with:
3030
path: ~/.cache/pre-commit
31-
key: key-0 # increment to reset
31+
key: key-2 # increment to reset
3232
- run: |
3333
source .venv/bin/activate
3434
pre-commit run --all-files
@@ -38,30 +38,28 @@ jobs:
3838
strategy:
3939
fail-fast: false
4040
matrix:
41-
python-version: [ "3.7", "3.8" , "3.9", "3.10" ]
42-
django-version: [ "3.0", "3.1", "3.2", "4.0" ]
41+
python-version: [ "3.7.14", "3.8.14" , "3.9.14", "3.10.7" ]
42+
django-version: [ "3.2", "4.0", "4.1" ]
4343
exclude:
44-
# Django v4 drops Python 3.6, and 3.7 support
44+
# Django v4 dropped 3.7 support
4545
- django-version: 4.0
46-
python-version: 3.7
46+
python-version: 3.7.14
47+
- django-version: 4.1
48+
python-version: 3.7.14
4749
steps:
48-
- uses: actions/checkout@v2
49-
- uses: actions/setup-python@v2
50+
- uses: actions/checkout@v3
51+
- uses: actions/setup-python@v4
5052
with:
5153
python-version: "${{ matrix.python-version }}"
52-
- uses: actions/cache@v2
53-
id: poetry-cache
54-
with:
55-
path: ~/.local
56-
key: key-3
5754
- uses: snok/install-poetry@v1
5855
with:
5956
virtualenvs-create: false
60-
- uses: actions/cache@v2
57+
version: 1.2.1
58+
- uses: actions/cache@v3
6159
id: cache-venv
6260
with:
6361
path: .venv
64-
key: ${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}-2
62+
key: ${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}-6
6563
- run: |
6664
python -m venv .venv
6765
source .venv/bin/activate
@@ -80,13 +78,13 @@ jobs:
8078
with:
8179
name: coverage-xml
8280
path: coverage.xml
83-
if: matrix.python-version == '3.10' && matrix.django-version == '4.0'
81+
if: matrix.python-version == '3.10.7' && matrix.django-version == '4.1'
8482

8583
coverage:
8684
needs: test
8785
runs-on: ubuntu-latest
8886
steps:
89-
- uses: actions/checkout@v2
87+
- uses: actions/checkout@v3
9088
- uses: actions/download-artifact@v2
9189
with:
9290
name: coverage-xml

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/psf/black
3-
rev: 22.6.0
3+
rev: 22.8.0
44
hooks:
55
- id: black
66

@@ -31,7 +31,7 @@ repos:
3131
]
3232

3333
- repo: https://github.com/asottile/pyupgrade
34-
rev: v2.34.0
34+
rev: v2.38.1
3535
hooks:
3636
- id: pyupgrade
3737
args: [ "--py3-plus", "--py36-plus", "--py37-plus" ]
@@ -42,7 +42,7 @@ repos:
4242
- id: isort
4343

4444
- repo: https://github.com/pre-commit/mirrors-mypy
45-
rev: 'v0.961'
45+
rev: v0.971
4646
hooks:
4747
- id: mypy
4848
additional_dependencies:

openapi_tester/loaders.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616
from prance.util.resolver import RefResolver
1717
from rest_framework.schemas.generators import BaseSchemaGenerator, EndpointEnumerator
1818
from rest_framework.settings import api_settings
19-
from rest_framework.views import APIView
19+
20+
from openapi_tester.constants import UNDOCUMENTED_SCHEMA_SECTION_ERROR
21+
from openapi_tester.exceptions import UndocumentedSchemaSectionError
2022

2123
if TYPE_CHECKING:
2224
from typing import Any, Callable
2325
from urllib.parse import ParseResult
2426

2527
from django.urls import ResolverMatch
28+
from rest_framework.views import APIView
2629

2730

2831
def handle_recursion_limit(schema: dict) -> Callable:
@@ -107,6 +110,14 @@ def validate_schema(schema: dict):
107110
validator = openapi_v30_spec_validator
108111
elif (major, minor) == ("3", "1"):
109112
validator = openapi_v31_spec_validator
113+
else:
114+
raise UndocumentedSchemaSectionError(
115+
UNDOCUMENTED_SCHEMA_SECTION_ERROR.format(
116+
key=schema["openapi"], error_addon="Support might need to be added."
117+
)
118+
)
119+
else:
120+
raise UndocumentedSchemaSectionError(UNDOCUMENTED_SCHEMA_SECTION_ERROR.format(key=schema["openapi"]))
110121
else:
111122
validator = openapi_v2_spec_validator
112123
validator.validate(schema)
@@ -120,7 +131,7 @@ def set_schema(self, schema: dict) -> None:
120131
self.schema = self.normalize_schema_paths(de_referenced_schema)
121132

122133
@cached_property
123-
def endpoints(self) -> list[str]: # pylint: disable=no-self-use
134+
def endpoints(self) -> list[str]:
124135
"""
125136
Returns a list of endpoint paths.
126137
"""
@@ -163,7 +174,7 @@ def handle_pk_parameter(resolved_route: ResolverMatch, path: str, method: str) -
163174
Handle the DRF conversion of params called {pk} into a named parameter based on Model field
164175
"""
165176
coerced_path = BaseSchemaGenerator().coerce_path(
166-
path=path, method=method, view=cast(APIView, resolved_route.func)
177+
path=path, method=method, view=cast("APIView", resolved_route.func)
167178
)
168179
pk_field_name = "".join(
169180
entry.replace("+ ", "") for entry in difflib.Differ().compare(path, coerced_path) if "+ " in entry
@@ -190,7 +201,7 @@ def load_schema(self) -> dict:
190201
Loads generated schema from drf-yasg and returns it as a dict.
191202
"""
192203
odict_schema = self.schema_generator.get_schema(None, True)
193-
return cast(dict, loads(dumps(odict_schema.as_odict())))
204+
return cast("dict", loads(dumps(odict_schema.as_odict())))
194205

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

219230
def resolve_path(self, endpoint_path: str, method: str) -> tuple[str, ResolverMatch]:
220231
from drf_spectacular.settings import spectacular_settings
@@ -245,5 +256,5 @@ def load_schema(self) -> dict[str, Any]:
245256
with open(self.path, encoding="utf-8") as file:
246257
content = file.read()
247258
return cast(
248-
dict, json.loads(content) if ".json" in self.path else yaml.load(content, Loader=yaml.FullLoader)
259+
"dict", json.loads(content) if ".json" in self.path else yaml.load(content, Loader=yaml.FullLoader)
249260
)

openapi_tester/schema_tester.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from __future__ import annotations
33

44
from itertools import chain
5-
from typing import TYPE_CHECKING, Any, Callable, List, Optional, cast
5+
from typing import TYPE_CHECKING, Any, Callable, cast
66

77
from django.conf import settings
88
from django.core.exceptions import ImproperlyConfigured
@@ -38,6 +38,8 @@
3838
)
3939

4040
if TYPE_CHECKING:
41+
from typing import Optional
42+
4143
from rest_framework.response import Response
4244

4345

@@ -262,7 +264,7 @@ def test_schema_section(
262264
if not schema_section_type:
263265
return
264266
combined_validators = cast(
265-
List[Callable[[dict, Any], Optional[str]]],
267+
"list[Callable[[dict, Any], Optional[str]]]",
266268
[
267269
validate_type,
268270
validate_format,

0 commit comments

Comments
 (0)