Skip to content

Commit aa3a9ff

Browse files
authored
Fix: Pydantic and AsyncController Errors (#127)
* fix pydantic settings errors and async controller errors * fixed CI setup * fixed tests
1 parent 2dfdec6 commit aa3a9ff

File tree

11 files changed

+44
-47
lines changed

11 files changed

+44
-47
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Install Flit
1818
run: pip install flit
1919
- name: Install Dependencies
20-
run: flit install --symlink
20+
run: make install
2121
- name: Install build dependencies
2222
run: pip install build
2323
- name: Build distribution

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Install Flit
1919
run: pip install flit
2020
- name: Install Dependencies
21-
run: flit install --symlink
21+
run: make install
2222
- name: Test
2323
run: pytest --cov=ninja_jwt --cov-report=xml tests
2424
- name: Coverage

.github/workflows/test_full.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ jobs:
4747
- name: Install Flit
4848
run: pip install flit
4949
- name: Install Dependencies
50-
run: flit install --symlink
50+
run: make install
5151
- name: Ruff Linting Check
5252
run: ruff check ninja_jwt tests

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ clean: ## Removing cached python compiled files
1212
find . -name .ruff_cache | xargs rm -rfv
1313

1414
install:clean ## Install dependencies
15-
flit install --deps develop --symlink
15+
pip install -r requirements.txt
16+
flit install --symlink
17+
18+
install-full:install ## Install dependencies
1619
pre-commit install -f
1720

1821
lint:fmt ## Run code linters

ninja_jwt/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def validate_values(cls, request: HttpRequest, values: Dict) -> Dict:
8282

8383
def output_schema(self) -> Schema:
8484
warnings.warn(
85-
"output_schema() is deprecated in favor of " "to_response_schema()",
85+
"output_schema() is deprecated in favor of to_response_schema()",
8686
DeprecationWarning,
8787
stacklevel=2,
8888
)

ninja_jwt/utils.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import logging
2+
import typing as t
23
from calendar import timegm
34
from datetime import datetime
45
from functools import wraps
56
from importlib import import_module
67

78
from django.conf import settings
89
from django.utils.functional import lazy
9-
from django.utils.timezone import is_naive, make_aware
1010

1111
from ninja_jwt import exceptions
1212

@@ -43,35 +43,35 @@ def import_callable(path_or_callable):
4343
return getattr(packages, attr)
4444

4545

46-
def make_utc(dt):
47-
if settings.USE_TZ and is_naive(dt):
48-
return make_aware(dt, timezone=timezone.utc)
46+
def make_utc(dt: datetime) -> datetime:
47+
if settings.USE_TZ and dt.tzinfo is None:
48+
return dt.replace(tzinfo=timezone.utc)
4949

5050
return dt
5151

5252

53-
def aware_utcnow():
53+
def aware_utcnow() -> datetime:
5454
dt = datetime.now(tz=timezone.utc)
5555
if not settings.USE_TZ:
5656
dt = dt.replace(tzinfo=None)
5757

5858
return dt
5959

6060

61-
def datetime_to_epoch(dt):
61+
def datetime_to_epoch(dt: datetime) -> int:
6262
return timegm(dt.utctimetuple())
6363

6464

65-
def datetime_from_epoch(ts):
65+
def datetime_from_epoch(ts: float) -> datetime:
6666
dt = datetime.fromtimestamp(ts, tz=timezone.utc)
6767
if not settings.USE_TZ:
6868
dt = dt.replace(tzinfo=None)
6969

7070
return dt
7171

7272

73-
def format_lazy(s, *args, **kwargs):
73+
def format_lazy(s: str, *args, **kwargs) -> str:
7474
return s.format(*args, **kwargs)
7575

7676

77-
format_lazy = lazy(format_lazy, str)
77+
format_lazy: t.Callable = lazy(format_lazy, str)

pyproject.toml

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ dependencies = [
5050
"Django >= 2.1",
5151
"pyjwt>=1.7.1,<3",
5252
"pyjwt[crypto]",
53-
"django-ninja-extra >= 0.20.0",
53+
"django-ninja-extra >= 0.22.9",
5454
]
5555

5656

@@ -59,37 +59,10 @@ Documentation = "https://github.com/eadwinCode/django-ninja-jwt"
5959
Source = "https://github.com/eadwinCode/django-ninja-jwt"
6060

6161
[project.optional-dependencies]
62-
test = [
63-
"cryptography",
64-
"pytest",
65-
"pytest-cov",
66-
"pytest-django",
67-
"pytest-asyncio",
68-
"ruff ==0.11.2",
69-
"django-stubs",
70-
"python-jose==3.4.0",
71-
"click==8.1.8",
72-
"freezegun"
73-
]
74-
7562
crypto = [
7663
"cryptography>=3.3.1",
7764
]
7865

79-
dev = [
80-
"pre-commit"
81-
]
82-
83-
doc = [
84-
"mkdocs >=1.1.2,<2.0.0",
85-
"mkdocs-material",
86-
"markdown-include",
87-
"mdx-include >=1.4.1,<2.0.0",
88-
"mkdocs-markdownextradata-plugin >=0.1.7,<0.3.0",
89-
"mkdocstrings"
90-
]
91-
92-
9366
[tool.ruff]
9467
select = [
9568
"E", # pycodestyle errors

requirements-docs.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
markdown-include
2+
mdx-include >=1.4.1,<2.0.0
3+
mkdocs >=1.1.2,<2.0.0
4+
mkdocs-markdownextradata-plugin >=0.1.7,<0.3.0
5+
mkdocs-material
6+
mkdocstrings

requirements-tests.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
click==8.1.8
2+
cryptography
3+
django-stubs
4+
freezegun
5+
ninja-schema>=0.14.1
6+
pytest
7+
pytest-asyncio==0.24.0
8+
pytest-cov
9+
pytest-django
10+
python-jose==3.3.0
11+
ruff ==0.11.2

requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-e .
2+
-r requirements-docs.txt
3+
-r requirements-tests.txt
4+
5+
pre-commit

tests/test_utils.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
from datetime import datetime, timedelta
1+
from datetime import datetime, timedelta, timezone
22

33
from django.test.utils import override_settings
4-
from django.utils import timezone
54
from freezegun import freeze_time
65

76
from ninja_jwt.utils import (
@@ -24,11 +23,11 @@ def test_it_should_return_the_correct_values(self):
2423

2524
with override_settings(USE_TZ=False):
2625
dt = make_utc(dt)
27-
assert timezone.is_naive(dt)
26+
assert dt.tzinfo is None
2827

2928
with override_settings(USE_TZ=True):
3029
dt = make_utc(dt)
31-
assert timezone.is_aware(dt)
30+
assert dt.tzinfo is not None
3231
assert dt.utcoffset() == timedelta(seconds=0)
3332

3433

@@ -39,7 +38,7 @@ def test_it_should_return_the_correct_value(self):
3938
with freeze_time(now):
4039
# Should return aware utcnow if USE_TZ == True
4140
with override_settings(USE_TZ=True):
42-
assert timezone.make_aware(now, timezone=timezone.utc) == aware_utcnow()
41+
assert now.replace(tzinfo=timezone.utc) == aware_utcnow()
4342

4443
# Should return naive utcnow if USE_TZ == False
4544
with override_settings(USE_TZ=False):

0 commit comments

Comments
 (0)