Skip to content

Commit

Permalink
Upgraded Django to 4.2.13 (attempt 3)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmispelon committed Jun 14, 2024
1 parent 32cc253 commit af1aa64
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ repos:
rev: "1.18.0"
hooks:
- id: django-upgrade
args: [--target-version, "3.2"]
args: [--target-version, "4.2"]
- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
Expand Down
18 changes: 9 additions & 9 deletions blog/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_manager_active(self):
pub_date=self.now, is_active=True, headline="active", slug="b"
)

self.assertQuerysetEqual(
self.assertQuerySetEqual(
Entry.objects.published(),
["active"],
transform=lambda entry: entry.headline,
Expand All @@ -54,7 +54,7 @@ def test_manager_published(self):
pub_date=self.tomorrow, is_active=True, headline="future active", slug="d"
)

self.assertQuerysetEqual(
self.assertQuerySetEqual(
Entry.objects.published(),
["past active"],
transform=lambda entry: entry.headline,
Expand Down Expand Up @@ -85,10 +85,10 @@ def test_manager_past_future(self):
Event.objects.create(date=self.yesterday, pub_date=self.now, headline="past")
Event.objects.create(date=self.tomorrow, pub_date=self.now, headline="future")

self.assertQuerysetEqual(
self.assertQuerySetEqual(
Event.objects.future(), ["future"], transform=lambda event: event.headline
)
self.assertQuerysetEqual(
self.assertQuerySetEqual(
Event.objects.past(), ["past"], transform=lambda event: event.headline
)

Expand All @@ -98,10 +98,10 @@ def test_manager_past_future_include_today(self):
"""
Event.objects.create(date=self.now, pub_date=self.now, headline="today")

self.assertQuerysetEqual(
self.assertQuerySetEqual(
Event.objects.future(), ["today"], transform=lambda event: event.headline
)
self.assertQuerysetEqual(
self.assertQuerySetEqual(
Event.objects.past(), ["today"], transform=lambda event: event.headline
)

Expand All @@ -121,10 +121,10 @@ def test_past_future_ordering(self):
date=self.tomorrow + D, pub_date=self.tomorrow + D, headline="d"
)

self.assertQuerysetEqual(
self.assertQuerySetEqual(
Event.objects.future(), ["c", "d"], transform=lambda event: event.headline
)
self.assertQuerysetEqual(
self.assertQuerySetEqual(
Event.objects.past(), ["b", "a"], transform=lambda event: event.headline
)

Expand All @@ -141,7 +141,7 @@ def test_no_past_upcoming_events(self):
)
response = self.client.get(reverse("weblog:index"))
self.assertEqual(response.status_code, 200)
self.assertQuerysetEqual(response.context["events"], [])
self.assertQuerySetEqual(response.context["events"], [])


class SitemapTests(DateTimeMixin, TestCase):
Expand Down
6 changes: 4 additions & 2 deletions contact/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_invalid_email(self):
)
self.assertEqual(response.status_code, 200)
self.assertFormError(
response, "form", "email", ["Enter a valid email address."]
response.context["form"], "email", ["Enter a valid email address."]
)

@override_settings(AKISMET_API_KEY="") # Disable Akismet in tests
Expand Down Expand Up @@ -67,7 +67,9 @@ def test_empty_name(self):
"body": "Hello, World!",
},
)
self.assertFormError(response, "form", "name", ["This field is required."])
self.assertFormError(
response.context["form"], "name", ["This field is required."]
)

@skipIf(not has_network_connection, "Requires a network connection")
def test_akismet_detect_spam(self):
Expand Down
6 changes: 5 additions & 1 deletion djangoproject/settings/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@

SESSION_COOKIE_SECURE = True

STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
STORAGES = {
"staticfiles": {
"BACKEND": "django.contrib.staticfiles.storage.ManifestStaticFilesStorage",
},
}

STATIC_ROOT = str(DATA_DIR.joinpath("static"))

Expand Down
12 changes: 6 additions & 6 deletions djangoproject/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def setUpTestData(cls):
def test_docs_host_excluded(self):
"We get no Content-Language or Vary headers when docs host is excluded"
with self.settings(LOCALE_MIDDLEWARE_EXCLUDED_HOSTS=[self.docs_host]):
resp = self.client.get("/", HTTP_HOST=self.docs_host)
resp = self.client.get("/", headers={"host": self.docs_host})
self.assertEqual(resp.status_code, HTTPStatus.FOUND)
self.assertNotIn("Content-Language", resp)
self.assertNotIn("Vary", resp)
Expand All @@ -73,7 +73,7 @@ def test_docs_host_with_port_excluded(self):
(with a port) is excluded
"""
with self.settings(LOCALE_MIDDLEWARE_EXCLUDED_HOSTS=[self.docs_host]):
resp = self.client.get("/", HTTP_HOST="%s:8000" % self.docs_host)
resp = self.client.get("/", headers={"host": "%s:8000" % self.docs_host})
self.assertEqual(resp.status_code, HTTPStatus.FOUND)
self.assertNotIn("Content-Language", resp)
self.assertNotIn("Vary", resp)
Expand All @@ -86,31 +86,31 @@ def test_docs_host_forwarded_excluded(self):
with self.settings(
LOCALE_MIDDLEWARE_EXCLUDED_HOSTS=[self.docs_host], USE_X_FORWARDED_HOST=True
):
resp = self.client.get("/", HTTP_X_FORWARDED_HOST=self.docs_host)
resp = self.client.get("/", headers={"x-forwarded-host": self.docs_host})
self.assertEqual(resp.status_code, HTTPStatus.FOUND)
self.assertNotIn("Content-Language", resp)
self.assertNotIn("Vary", resp)

def test_docs_host_not_excluded(self):
"We still get Content-Language when docs host is not excluded"
with self.settings(LOCALE_MIDDLEWARE_EXCLUDED_HOSTS=[]):
resp = self.client.get("/", HTTP_HOST=self.docs_host)
resp = self.client.get("/", headers={"host": self.docs_host})
self.assertEqual(resp.status_code, HTTPStatus.FOUND)
self.assertIn("Content-Language", resp)
self.assertIn("Vary", resp)

def test_www_host(self):
"www should still use LocaleMiddleware"
with self.settings(LOCALE_MIDDLEWARE_EXCLUDED_HOSTS=[self.docs_host]):
resp = self.client.get("/", HTTP_HOST=self.www_host)
resp = self.client.get("/", headers={"host": self.www_host})
self.assertEqual(resp.status_code, HTTPStatus.OK)
self.assertIn("Content-Language", resp)
self.assertIn("Vary", resp)

def test_www_host_with_port(self):
"www (with a port) should still use LocaleMiddleware"
with self.settings(LOCALE_MIDDLEWARE_EXCLUDED_HOSTS=[self.docs_host]):
resp = self.client.get("/", HTTP_HOST="%s:8000" % self.www_host)
resp = self.client.get("/", headers={"host": "%s:8000" % self.www_host})
self.assertEqual(resp.status_code, HTTPStatus.OK)
self.assertIn("Content-Language", resp)
self.assertIn("Vary", resp)
14 changes: 7 additions & 7 deletions docs/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def test_team_url(self):
def test_internals_team(self):
response = self.client.get(
"/en/dev/internals/team/",
HTTP_HOST="docs.djangoproject.localhost:8000",
headers={"host": "docs.djangoproject.localhost:8000"},
)
self.assertRedirects(
response,
Expand All @@ -190,7 +190,7 @@ def tearDownClass(cls):

def test_empty_get(self):
response = self.client.get(
"/en/dev/search/", HTTP_HOST="docs.djangoproject.localhost:8000"
"/en/dev/search/", headers={"host": "docs.djangoproject.localhost:8000"}
)
self.assertEqual(response.status_code, 200)

Expand Down Expand Up @@ -303,7 +303,7 @@ def test_title_strip_tags(self):
}
]
)
self.assertQuerysetEqual(
self.assertQuerySetEqual(
self.release.documents.all(),
["This is the title"],
transform=attrgetter("title"),
Expand All @@ -319,7 +319,7 @@ def test_title_entities(self):
}
]
)
self.assertQuerysetEqual(
self.assertQuerySetEqual(
self.release.documents.all(),
["Title & title"],
transform=attrgetter("title"),
Expand All @@ -333,7 +333,7 @@ def test_empty_documents(self):
{"current_page_name": "foo/3"},
]
)
self.assertQuerysetEqual(self.release.documents.all(), [])
self.assertQuerySetEqual(self.release.documents.all(), [])

def test_excluded_documents(self):
"""
Expand Down Expand Up @@ -375,7 +375,7 @@ def tearDownClass(cls):

def test_sitemap_index(self):
response = self.client.get(
"/sitemap.xml", HTTP_HOST="docs.djangoproject.localhost:8000"
"/sitemap.xml", headers={"host": "docs.djangoproject.localhost:8000"}
)
self.assertContains(response, "<sitemap>", count=2)
self.assertContains(
Expand All @@ -394,7 +394,7 @@ def test_sitemap(self):

def test_sitemap_404(self):
response = self.client.get(
"/sitemap-xx.xml", HTTP_HOST="docs.djangoproject.localhost:8000"
"/sitemap-xx.xml", headers={"host": "docs.djangoproject.localhost:8000"}
)
self.assertEqual(response.status_code, 404)
self.assertEqual(
Expand Down
2 changes: 1 addition & 1 deletion docs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def sitemap_index(request, sitemaps):
sitemap_url = reverse(
"document-sitemap", host="docs", kwargs={"section": section}
)
sites.append(sitemap_url)
sites.append({"location": sitemap_url})
return TemplateResponse(
request,
"sitemap_index.xml",
Expand Down
4 changes: 2 additions & 2 deletions requirements/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ django-contact-form==2.1
django-countries==7.5.1
django-hosts==5.1
django-money==3.1
django-push==1.1
django-push @ git+https://github.com/brutasse/django-push.git@22fda99641cfbd2f3075a723d92652a8e38220a5
django-read-only==1.12.0
django-recaptcha==4.0.0
django-registration-redux==2.13
Django==3.2.25
Django==4.2.13
docutils==0.17.1
feedparser==6.0.8
Jinja2==3.1.4
Expand Down
6 changes: 3 additions & 3 deletions tracdb/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ def assertTicketsEqual(
"""
A wrapper around assertQuerysetEqual with some useful defaults
"""
self.assertQuerysetEqual(
self.assertQuerySetEqual(
queryset, expected, transform=transform, ordered=ordered
)

def test_ticket_table_exist_in_testdb(self):
self._create_ticket(summary="test", custom={"x": "y"})
self.assertTicketsEqual(Ticket.objects.all(), ["test"])
self.assertQuerysetEqual(
self.assertQuerySetEqual(
TicketCustom.objects.all(),
[("x", "y")],
transform=attrgetter("name", "value"),
Expand All @@ -54,7 +54,7 @@ def test_with_custom(self):
self._create_ticket(summary="test1", custom={"x": "A", "y": "B"})
self._create_ticket(summary="test2", custom={"z": "C"})

self.assertQuerysetEqual(
self.assertQuerySetEqual(
Ticket.objects.with_custom().order_by("summary"),
[
("test1", {"x": "A", "y": "B"}),
Expand Down

0 comments on commit af1aa64

Please sign in to comment.