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

Minor testing cleanups #1782

Merged
merged 3 commits into from
May 23, 2023
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
10 changes: 5 additions & 5 deletions tests/panels/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
psycopg = None

from ..base import BaseMultiDBTestCase, BaseTestCase
from ..models import PostgresJSON
from ..models import Binary, PostgresJSON


def sql_call(use_iterator=False):
Expand Down Expand Up @@ -149,7 +149,7 @@ def test_non_ascii_query(self):
self.assertEqual(len(self.panel._queries), 2)

# non-ASCII bytes parameters
list(User.objects.filter(username="café".encode()))
list(Binary.objects.filter(field__in=["café".encode()]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose behind changing this from a bytes to a list of bytes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found that even with BinaryField, using .filter(field="café") would generate a BytesWarning internally within Django. Not wanting to shave that particular yak, I found that switching to the form above allowed the test to proceed without any BytesWarning.

self.assertEqual(len(self.panel._queries), 3)

response = self.panel.process_request(self.request)
Expand Down Expand Up @@ -335,7 +335,7 @@ def test_insert_content(self):
Test that the panel only inserts content after generate_stats and
not the process_request.
"""
list(User.objects.filter(username="café".encode()))
list(User.objects.filter(username="café"))
response = self.panel.process_request(self.request)
# ensure the panel does not have content yet.
self.assertNotIn("café", self.panel.content)
Expand All @@ -351,7 +351,7 @@ def test_insert_locals(self):
Test that the panel inserts locals() content.
"""
local_var = "<script>alert('test');</script>" # noqa: F841
list(User.objects.filter(username="café".encode()))
list(User.objects.filter(username="café"))
response = self.panel.process_request(self.request)
self.panel.generate_stats(self.request, response)
self.assertIn("local_var", self.panel.content)
Expand All @@ -365,7 +365,7 @@ def test_not_insert_locals(self):
"""
Test that the panel does not insert locals() content.
"""
list(User.objects.filter(username="café".encode()))
list(User.objects.filter(username="café"))
response = self.panel.process_request(self.request)
self.panel.generate_stats(self.request, response)
self.assertNotIn("djdt-locals", self.panel.content)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,8 @@ class DebugToolbarLiveTestCase(StaticLiveServerTestCase):
def setUpClass(cls):
super().setUpClass()
options = Options()
options.headless = bool(os.environ.get("CI"))
if os.environ.get("CI"):
options.add_argument("-headless")
cls.selenium = webdriver.Firefox(options=options)

@classmethod
Expand Down
18 changes: 8 additions & 10 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,27 @@ isolated_build = true
envlist =
docs
packaging
py{38,39,310}-dj{32}-{sqlite,postgresql,postgis,mysql}
py{310}-dj{40}-{sqlite}
py{310,311}-dj{41}-{sqlite,postgresql,postgis,mysql}
py{310,311}-dj{42,main}-{sqlite,postgresql,postgis,mysql}
py{310,311}-dj{42,main}-psycopg3
py{38,39,310}-dj32-{sqlite,postgresql,postgis,mysql}
py310-dj40-sqlite
py{310,311}-dj41-{sqlite,postgresql,postgis,mysql}
py{310,311}-dj{42,main}-{sqlite,postgresql,psycopg3,postgis,mysql}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for cleaning this up


[testenv]
deps =
dj32: django~=3.2.9
dj40: django~=4.0.0
dj41: django~=4.1.3
dj42: django>=4.2a1,<5
dj42: django~=4.2.1
djmain: https://github.com/django/django/archive/main.tar.gz
postgresql: psycopg2-binary
psycopg3: psycopg[binary]
postgis: psycopg2-binary
mysql: mysqlclient
djmain: https://github.com/django/django/archive/main.tar.gz
coverage[toml]
Jinja2
html5lib
pygments
selenium
selenium>=4.8.0
sqlparse
passenv=
CI
Expand All @@ -40,7 +39,7 @@ setenv =
PYTHONPATH = {toxinidir}
PYTHONWARNINGS = d
py39-dj32-postgresql: DJANGO_SELENIUM_TESTS = true
py310-dj41-postgresql: DJANGO_SELENIUM_TESTS = true
py311-dj42-postgresql: DJANGO_SELENIUM_TESTS = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

DB_NAME = {env:DB_NAME:debug_toolbar}
DB_USER = {env:DB_USER:debug_toolbar}
DB_HOST = {env:DB_HOST:localhost}
Expand All @@ -56,7 +55,6 @@ setenv =
DB_BACKEND = postgresql
DB_PORT = {env:DB_PORT:5432}


[testenv:py{38,39,310,311}-dj{32,40,41,42,main}-postgis]
setenv =
{[testenv]setenv}
Expand Down