Skip to content

Commit 6057e1c

Browse files
authored
Merge pull request #1996 from opensafely-core/django-41
Bump django to 4.1
2 parents 21c8fb9 + 829eca2 commit 6057e1c

File tree

9 files changed

+33
-35
lines changed

9 files changed

+33
-35
lines changed

jobserver/signing.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import hashlib
2-
from datetime import datetime, timezone
2+
from datetime import datetime
33

44
import itsdangerous
5+
from django.utils import timezone
56
from pydantic import BaseModel, Field, ValidationError, root_validator, validator
67

78

@@ -82,7 +83,7 @@ def check_url(cls, url):
8283
@validator("expiry")
8384
def check_expiry(cls, expiry):
8485
"""Enforce the token has not expired."""
85-
if datetime.now(timezone.utc) > expiry:
86+
if timezone.now() > expiry:
8687
raise ValueError(f"token expired on {expiry.isoformat()}")
8788
return expiry
8889

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ filterwarnings = [
7070
"error",
7171
"ignore::pytest.PytestUnraisableExceptionWarning:",
7272
"ignore:distutils Version classes are deprecated:DeprecationWarning:pytest_freezegun",
73-
"ignore:'django_extensions' defines default_app_config:django.utils.deprecation.RemovedInDjango41Warning:django",
74-
"ignore:'slippers' defines default_app_config:django.utils.deprecation.RemovedInDjango41Warning:django",
7573
]
7674
markers = [
7775
"verification: tests that verify fakes",

requirements.prod.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ argon2-cffi-bindings==21.2.0 \
3131
--hash=sha256:f1152ac548bd5b8bcecfb0b0371f082037e47128653df2e8ba6e914d384f3c3e \
3232
--hash=sha256:f9f8b450ed0547e3d473fdc8612083fd08dd2120d6ac8f73828df9b7d45bb351
3333
# via argon2-cffi
34-
asgiref==3.5.0 \
35-
--hash=sha256:2f8abc20f7248433085eda803936d98992f1343ddb022065779f37c5da0181d0 \
36-
--hash=sha256:88d59c13d634dcffe0510be048210188edd79aeccb6a6c9028cdad6f31d730a9
34+
asgiref==3.5.2 \
35+
--hash=sha256:1d2880b792ae8757289136f1db2b7b99100ce959b2aa57fd69dab783d05afac4 \
36+
--hash=sha256:4a29362a6acebe09bf1d6640db38c1dc3d9217c68e6f9f6204d72667fc19a424
3737
# via django
3838
attrs==21.4.0 \
3939
--hash=sha256:2d27e3784d7a565d36ab851fe94887c5eccd6a463168875832a1be79c82828b4 \
@@ -228,9 +228,9 @@ dj-email-url==1.0.5 \
228228
--hash=sha256:64257c4f9d8139a4af8e5267229d32260e433fbf257b0cf8fc855bb0cc39ca7d \
229229
--hash=sha256:ef36f8a324ec57cf3be5c7a7ef44ed6900ca0208624a918ab33adc1cf6427b39
230230
# via environs
231-
django==4.0.7 \
232-
--hash=sha256:41bd65a9e5f8a89cdbfa7a7bba45cd7431ae89e750af82dea8a35fd1a7ecbe66 \
233-
--hash=sha256:9c6d5ad36be798e562ddcaa6b17b1c3ff2d3c4f529a47432b69fb9a30f847461
231+
django==4.1 \
232+
--hash=sha256:031ccb717782f6af83a0063a1957686e87cb4581ea61b47b3e9addf60687989a \
233+
--hash=sha256:032f8a6fc7cf05ccd1214e4a2e21dfcd6a23b9d575c6573cacc8c67828dbe642
234234
# via
235235
# django-anymail
236236
# django-browser-reload

tests/factories/applications.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from datetime import timezone
2+
13
import factory
24
import factory.fuzzy
3-
from django.utils import timezone
45

56
from applications.models import (
67
Application,

tests/factories/jobserver.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
from datetime import datetime
1+
from datetime import datetime, timezone
22

33
import factory
44
import factory.fuzzy
5-
from django.utils import timezone
65
from social_django.models import UserSocialAuth
76

87
from jobserver.models import (

tests/fakes.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import textwrap
2-
from datetime import datetime
2+
from datetime import datetime, timezone
33

4-
from django.utils import timezone
4+
from django.utils.timezone import now
55

66

77
class FakeGitHubAPI:
@@ -67,35 +67,35 @@ def get_repos_with_dates(self, org):
6767
"name": "research-repo-1",
6868
"url": "https://github.com/opensafely/research-repo-1",
6969
"is_private": True,
70-
"created_at": timezone.now(),
70+
"created_at": now(),
7171
"topics": ["github-releases"],
7272
},
7373
{
7474
"name": "research-repo-2",
7575
"url": "https://github.com/opensafely/research-repo-2",
7676
"is_private": True,
77-
"created_at": timezone.now(),
77+
"created_at": now(),
7878
"topics": [],
7979
},
8080
{
8181
"name": "research-repo-3",
8282
"url": "https://github.com/opensafely/research-repo-3",
8383
"is_private": False,
84-
"created_at": timezone.now(),
84+
"created_at": now(),
8585
"topics": ["github-releases"],
8686
},
8787
{
8888
"name": "no workspaces or jobs",
8989
"url": "https://github.com/opensafely/research-repo-4",
9090
"is_private": True,
91-
"created_at": timezone.now(),
91+
"created_at": now(),
9292
"topics": [],
9393
},
9494
{
9595
"name": "jobs haven't run",
9696
"url": "https://github.com/opensafely/research-repo-5",
9797
"is_private": True,
98-
"created_at": timezone.now(),
98+
"created_at": now(),
9999
"topics": [],
100100
},
101101
]

tests/unit/jobserver/models/test_stats.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
from datetime import datetime
2-
3-
from django.utils import timezone
1+
from datetime import datetime, timezone
42

53
from ....factories import BackendFactory, StatsFactory
64

tests/unit/jobserver/test_signing.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import json
22
import secrets
3-
from datetime import datetime, timedelta, timezone
3+
from datetime import timedelta
44

55
import pytest
6+
from django.utils import timezone
67
from pydantic import ValidationError
78
from pydantic.json import pydantic_encoder
89

@@ -26,7 +27,7 @@ def test_token_sign_verify_roundtrip(secret_key):
2627
token1 = signing.AuthToken(
2728
url="https://example.com/url",
2829
user="user",
29-
expiry=datetime.now(timezone.utc) + timedelta(minutes=1),
30+
expiry=timezone.now() + timedelta(minutes=1),
3031
)
3132
token_string = token1.sign(secret_key, "salt")
3233

@@ -39,7 +40,7 @@ def test_token_object_url_invalid():
3940
signing.AuthToken(
4041
url="bad",
4142
user="user",
42-
expiry=datetime.now(timezone.utc) + timedelta(minutes=1),
43+
expiry=timezone.now() + timedelta(minutes=1),
4344
)
4445

4546

@@ -48,15 +49,15 @@ def test_token_object_expired():
4849
signing.AuthToken(
4950
url="https://example.com/url",
5051
user="user",
51-
expiry=datetime.now(timezone.utc) - timedelta(minutes=1),
52+
expiry=timezone.now() - timedelta(minutes=1),
5253
)
5354

5455

5556
def test_token_verify_mismatched_secrets():
5657
payload = dict(
5758
url="https://example.com/url",
5859
user="user",
59-
expiry=datetime.now(timezone.utc) + timedelta(minutes=1),
60+
expiry=timezone.now() + timedelta(minutes=1),
6061
)
6162
token = create_raw_token(payload, "secret1" * 10)
6263

@@ -76,7 +77,7 @@ def test_token_verify_expired(secret_key):
7677
payload = dict(
7778
url="https://example.com/url",
7879
user="user",
79-
expiry=datetime.now(timezone.utc) - timedelta(minutes=1),
80+
expiry=timezone.now() - timedelta(minutes=1),
8081
)
8182
token = create_raw_token(payload, secret_key)
8283
with pytest.raises(signing.AuthToken.Expired):
@@ -87,7 +88,7 @@ def test_token_verify_wrong_all_the_things(secret_key):
8788
payload = dict(
8889
url="bad url",
8990
# missing user
90-
expiry=datetime.now(timezone.utc) - timedelta(minutes=1),
91+
expiry=timezone.now() - timedelta(minutes=1),
9192
)
9293
token = create_raw_token(payload, secret_key)
9394
with pytest.raises(ValidationError) as exc_info:

tests/unit/jobserver/views/test_status.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import functools
22
import time
3-
from datetime import datetime, timedelta
3+
from datetime import datetime, timedelta, timezone
44

55
import pytest
6-
from django.utils import timezone
6+
from django.utils.timezone import now
77
from first import first
88

99
from jobserver.views.status import DBAvailability, PerBackendStatus, Status
@@ -82,7 +82,7 @@ def test_status_healthy(rf):
8282
# acked, because JobFactory will implicitly create JobRequests
8383
JobFactory.create_batch(3, job_request__backend=backend)
8484

85-
last_seen = minutes_ago(timezone.now(), 1)
85+
last_seen = minutes_ago(now(), 1)
8686
StatsFactory(backend=backend, api_last_seen=last_seen)
8787

8888
request = rf.get("/")
@@ -110,7 +110,7 @@ def test_status_no_last_seen(rf):
110110
def test_status_unacked_jobs_but_recent_api_contact(rf):
111111
backend = BackendFactory()
112112

113-
last_seen = minutes_ago(timezone.now(), 1)
113+
last_seen = minutes_ago(now(), 1)
114114
StatsFactory(backend=backend, api_last_seen=last_seen)
115115

116116
request = rf.get("/")
@@ -131,7 +131,7 @@ def test_status_unhealthy(rf):
131131
# unacked, because it has no Jobs
132132
JobRequestFactory(backend=backend)
133133

134-
last_seen = minutes_ago(timezone.now(), 10)
134+
last_seen = minutes_ago(now(), 10)
135135
StatsFactory(backend=backend, api_last_seen=last_seen, url="foo")
136136

137137
request = rf.get("/")

0 commit comments

Comments
 (0)