Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ran tests for Django 5.0, updated tests to include new area-invalid t… #5

Merged
merged 6 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
SunnyR marked this conversation as resolved.
Show resolved Hide resolved
- 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"
SunnyR marked this conversation as resolved.
Show resolved Hide resolved
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