Skip to content

Commit 9a4be13

Browse files
mixtahMichael BauerSunnyR
authored
Ran tests for Django 5.0, updated tests to include new area-invalid t… (#5)
* Ran tests for Django 5.0, updated tests to include new area-invalid tag in form * More specific versions specified as supported * Ran black formatter * linting fixes --------- Co-authored-by: Michael Bauer <[email protected]> Co-authored-by: Sunny Rangnani <[email protected]>
1 parent 54cb1bb commit 9a4be13

File tree

5 files changed

+55
-36
lines changed

5 files changed

+55
-36
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,6 @@ my_root_certs.crt
5656
.flake8
5757

5858
conf/
59+
60+
# Python Virtual Environment
61+
venv

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ Changes made in this fork:
2727
- Upgraded to use pyproject.toml
2828
- Use github actions over travis-ci
2929
- Python 3.12 compatibilty
30-
- Django 4.2 compatibilty
30+
- Django >=4.2,<5.1 compatibility
3131
- Removed crispy-forms integration

poetry.lock

+28-28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ exclude = [
3939

4040
[tool.poetry.dependencies]
4141
python = "~3.12"
42-
django = "^4.2"
42+
django = ">=4.2,<5.1"
4343
django-filter = "^24.2"
4444
djangorestframework = "^3.15"
4545

@@ -57,6 +57,7 @@ isort = "5.13.2"
5757
bandit = "1.7.8"
5858
# test
5959
django-upgrade = "1.18.0"
60+
packaging = "24.1"
6061

6162
[build-system]
6263
requires = ["poetry-core"]

tests/test_backends.py

+21-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from urllib.parse import quote, urlencode
22

3+
import django
34
import django_filters
45
from django.test import modify_settings
6+
from packaging.version import Version
57
from rest_framework import status
68
from rest_framework.test import APIRequestFactory, APITestCase
79

@@ -227,10 +229,9 @@ class NoteFilter(FilterSet):
227229
class RelatedViewSet(views.NoteViewSet):
228230
filterset_class = NoteFilter
229231

230-
context = {"author": "invalid", "author__last_login": "invalid"}
231-
self.assertHTMLEqual(
232-
self.render(RelatedViewSet, context),
233-
"""
232+
assert_html_options = list(
233+
map(
234+
lambda aria: f"""
234235
<h2>Field filters</h2>
235236
<form class="form" action="" method="get">
236237
<ul class="errorlist">
@@ -241,7 +242,7 @@ class RelatedViewSet(views.NoteViewSet):
241242
</ul>
242243
<p>
243244
<label for="id_author">Writer:</label>
244-
<select id="id_author" name="author">
245+
<select {aria} id="id_author" name="author">
245246
<option value="">---------</option>
246247
</select>
247248
</p>
@@ -255,7 +256,7 @@ class RelatedViewSet(views.NoteViewSet):
255256
</ul>
256257
<p>
257258
<label for="id_author__last_login">Last login:</label>
258-
<input id="id_author__last_login"
259+
<input {aria} id="id_author__last_login"
259260
name="author__last_login"
260261
type="text"
261262
value="invalid" />
@@ -265,6 +266,20 @@ class RelatedViewSet(views.NoteViewSet):
265266
<button type="submit" class="btn btn-primary">Submit</button>
266267
</form>
267268
""",
269+
["", 'aria-invalid="true"'],
270+
)
271+
)
272+
273+
# Django >5.0 adds aria-invalid="true", but want old Django version to pass as well
274+
if Version(django.__version__) < Version("5.0"):
275+
assert_html = assert_html_options[0]
276+
else:
277+
assert_html = assert_html_options[1]
278+
279+
context = {"author": "invalid", "author__last_login": "invalid"}
280+
self.assertHTMLEqual(
281+
self.render(RelatedViewSet, context),
282+
assert_html,
268283
)
269284

270285
def test_rendering_doesnt_affect_filterset_classes(self):

0 commit comments

Comments
 (0)