Skip to content

Commit

Permalink
Ran tests for Django 5.0, updated tests to include new area-invalid t… (
Browse files Browse the repository at this point in the history
#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 <michael.bauer@novasystems.com>
Co-authored-by: Sunny Rangnani <1923481+SunnyR@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 26, 2024
1 parent 54cb1bb commit 9a4be13
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 36 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ my_root_certs.crt
.flake8

conf/

# Python Virtual Environment
venv
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ Changes made in this fork:
- Upgraded to use pyproject.toml
- Use github actions over travis-ci
- Python 3.12 compatibilty
- Django 4.2 compatibilty
- Django >=4.2,<5.1 compatibility
- Removed crispy-forms integration
56 changes: 28 additions & 28 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ exclude = [

[tool.poetry.dependencies]
python = "~3.12"
django = "^4.2"
django = ">=4.2,<5.1"
django-filter = "^24.2"
djangorestframework = "^3.15"

Expand All @@ -57,6 +57,7 @@ isort = "5.13.2"
bandit = "1.7.8"
# test
django-upgrade = "1.18.0"
packaging = "24.1"

[build-system]
requires = ["poetry-core"]
Expand Down
27 changes: 21 additions & 6 deletions tests/test_backends.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from urllib.parse import quote, urlencode

import django
import django_filters
from django.test import modify_settings
from packaging.version import Version
from rest_framework import status
from rest_framework.test import APIRequestFactory, APITestCase

Expand Down Expand Up @@ -227,10 +229,9 @@ class NoteFilter(FilterSet):
class RelatedViewSet(views.NoteViewSet):
filterset_class = NoteFilter

context = {"author": "invalid", "author__last_login": "invalid"}
self.assertHTMLEqual(
self.render(RelatedViewSet, context),
"""
assert_html_options = list(
map(
lambda aria: f"""
<h2>Field filters</h2>
<form class="form" action="" method="get">
<ul class="errorlist">
Expand All @@ -241,7 +242,7 @@ class RelatedViewSet(views.NoteViewSet):
</ul>
<p>
<label for="id_author">Writer:</label>
<select id="id_author" name="author">
<select {aria} id="id_author" name="author">
<option value="">---------</option>
</select>
</p>
Expand All @@ -255,7 +256,7 @@ class RelatedViewSet(views.NoteViewSet):
</ul>
<p>
<label for="id_author__last_login">Last login:</label>
<input id="id_author__last_login"
<input {aria} id="id_author__last_login"
name="author__last_login"
type="text"
value="invalid" />
Expand All @@ -265,6 +266,20 @@ class RelatedViewSet(views.NoteViewSet):
<button type="submit" class="btn btn-primary">Submit</button>
</form>
""",
["", 'aria-invalid="true"'],
)
)

# Django >5.0 adds aria-invalid="true", but want old Django version to pass as well
if Version(django.__version__) < Version("5.0"):
assert_html = assert_html_options[0]
else:
assert_html = assert_html_options[1]

context = {"author": "invalid", "author__last_login": "invalid"}
self.assertHTMLEqual(
self.render(RelatedViewSet, context),
assert_html,
)

def test_rendering_doesnt_affect_filterset_classes(self):
Expand Down

0 comments on commit 9a4be13

Please sign in to comment.