Skip to content

Commit

Permalink
Merge pull request #1226 from tim-schilling/tox-expand-db-tests
Browse files Browse the repository at this point in the history
Test with postgresql and mariadb on multiple versions of Django.
  • Loading branch information
matthiask authored Jan 31, 2020
2 parents a8ae50b + 0caa826 commit 98308a2
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 62 deletions.
70 changes: 52 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,67 @@ matrix:
- env: TOXENV=style
- env: TOXENV=readme
- python: 3.5
env: TOXENV=py35-dj111
env: TOXENV=py35-dj111-sqlite
- python: 3.6
env: TOXENV=py36-dj111
env: TOXENV=py36-dj111-sqlite
- python: 3.7
env: TOXENV=py37-dj111
env: TOXENV=py37-dj111-sqlite
- python: 3.5
env: TOXENV=py35-dj22
env: TOXENV=py35-dj22-sqlite
- python: 3.6
env: TOXENV=py36-dj22
env: TOXENV=py36-dj22-sqlite
- python: 3.7
env: TOXENV=py37-dj22
env: TOXENV=py37-dj22-sqlite
- python: 3.8
env: TOXENV=py38-dj22
env: TOXENV=py38-dj22-sqlite
- python: 3.6
env: TOXENV=py36-dj30
env: TOXENV=py36-dj30-sqlite
- python: 3.7
env: TOXENV=py37-dj30
env: TOXENV=py37-dj30-sqlite
- python: 3.8
env: TOXENV=py38-dj30
env: TOXENV=py38-dj30-sqlite
- python: 3.6
env: TOXENV=py36-djmaster
env: TOXENV=py36-djmaster-sqlite
- python: 3.7
env: TOXENV=py37-djmaster
env: TOXENV=py37-djmaster-sqlite
- python: 3.8
env: TOXENV=py38-djmaster
- env: TOXENV=postgresql
env: TOXENV=py38-djmaster-sqlite
- python: 3.7
env: TOXENV=py37-dj111-postgresql
addons:
postgresql: "9.5"
- python: 3.8
env: TOXENV=py38-dj22-postgresql
addons:
postgresql: "9.5"
- python: 3.8
env: TOXENV=py38-dj30-postgresql
addons:
postgresql: "9.5"
- env: TOXENV=mariadb
- python: 3.7
env: TOXENV=py37-dj111-mariadb
addons:
mariadb: "10.3"
script:
# working around https://travis-ci.community/t/mariadb-build-error-with-xenial/3160
- mysql -u root -e "DROP USER IF EXISTS 'travis'@'%';"
- mysql -u root -e "CREATE USER 'travis'@'%';"
- mysql -u root -e "CREATE DATABASE debug_toolbar;"
- mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO 'travis'@'%';";
- tox -v
- python: 3.8
env: TOXENV=py38-dj22-mariadb
addons:
mariadb: "10.3"
script:
# working around https://travis-ci.community/t/mariadb-build-error-with-xenial/3160
- mysql -u root -e "DROP USER IF EXISTS 'travis'@'%';"
- mysql -u root -e "CREATE USER 'travis'@'%';"
- mysql -u root -e "CREATE DATABASE debug_toolbar;"
- mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO 'travis'@'%';";
- tox -v
- python: 3.8
env: TOXENV=py38-dj30-mariadb
addons:
mariadb: "10.3"
script:
Expand All @@ -46,9 +78,11 @@ matrix:
- mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO 'travis'@'%';";
- tox -v
allow_failures:
- env: TOXENV=py36-djmaster
- env: TOXENV=py37-djmaster
- env: TOXENV=py38-djmaster
- env: TOXENV=py36-djmaster-sqlite
- env: TOXENV=py37-djmaster-sqlite
- env: TOXENV=py38-djmaster-sqlite
- env: TOXENV=py38-djmaster-postgresql
- env: TOXENV=py38-djmaster-mariadb

install:
- pip install tox codecov
Expand Down
12 changes: 9 additions & 3 deletions debug_toolbar/management/commands/debugsqlshell.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
from time import time

import django
import sqlparse
from django.core.management.commands.shell import Command # noqa
from django.db.backends import utils as db_backends_utils
from django.db import connection

if connection.vendor == "postgresql" and django.VERSION >= (3, 0, 0):
from django.db.backends.postgresql import base as base_module
else:
from django.db.backends import utils as base_module

# 'debugsqlshell' is the same as the 'shell'.


class PrintQueryWrapper(db_backends_utils.CursorDebugWrapper):
class PrintQueryWrapper(base_module.CursorDebugWrapper):
def execute(self, sql, params=()):
start_time = time()
try:
Expand All @@ -20,4 +26,4 @@ def execute(self, sql, params=()):
print("{} [{:.2f}ms]".format(formatted_sql, duration))


db_backends_utils.CursorDebugWrapper = PrintQueryWrapper
base_module.CursorDebugWrapper = PrintQueryWrapper
12 changes: 9 additions & 3 deletions tests/commands/test_debugsqlshell.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import io
import sys

import django
from django.contrib.auth.models import User
from django.core import management
from django.db.backends import utils as db_backends_utils
from django.db import connection
from django.test import TestCase
from django.test.utils import override_settings

if connection.vendor == "postgresql" and django.VERSION >= (3, 0, 0):
from django.db.backends.postgresql import base as base_module
else:
from django.db.backends import utils as base_module


@override_settings(DEBUG=True)
class DebugSQLShellTestCase(TestCase):
def setUp(self):
self.original_cursor_wrapper = db_backends_utils.CursorDebugWrapper
self.original_wrapper = base_module.CursorDebugWrapper
# Since debugsqlshell monkey-patches django.db.backends.utils, we can
# test it simply by loading it, without executing it. But we have to
# undo the monkey-patch on exit.
Expand All @@ -20,7 +26,7 @@ def setUp(self):
management.load_command_class(app_name, command_name)

def tearDown(self):
db_backends_utils.CursorDebugWrapper = self.original_cursor_wrapper
base_module.CursorDebugWrapper = self.original_wrapper

def test_command(self):
original_stdout, sys.stdout = sys.stdout, io.StringIO()
Expand Down
49 changes: 11 additions & 38 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ envlist =
flake8
style
readme
py{35,36,37}-dj111
py{35,36,37,38}-dj22
py{36,37,38}-dj30
py{36,37,38}-djmaster
postgresql
mariadb
py{35,36,37}-dj111-sqlite
py{35,36,37,38}-dj22-sqlite
py{36,37,38}-dj30-sqlite
py{36,37,38}-djmaster-sqlite
py37-dj111-{postgresql,mariadb}
py{37,38}-dj{22,30}-{postgresql,mariadb}

[testenv]
deps =
dj111: Django==1.11.*
dj22: Django==2.2.*
dj30: Django==3.0.*
sqlite: mock
postgresql: psycopg2-binary
mariadb: mysqlclient
djmaster: https://github.com/django/django/archive/master.tar.gz
coverage
Jinja2
Expand All @@ -23,38 +26,8 @@ deps =
sqlparse
setenv =
PYTHONPATH = {toxinidir}
whitelist_externals = make
pip_pre = True
commands = make coverage TEST_ARGS='{posargs:tests}'

[testenv:postgresql]
deps =
Django==1.11.*
coverage
Jinja2
html5lib
psycopg2-binary
selenium<4.0
sqlparse
setenv =
PYTHONPATH = {toxinidir}
DJANGO_DATABASE_ENGINE = postgresql
whitelist_externals = make
pip_pre = True
commands = make coverage TEST_ARGS='{posargs:tests}'

[testenv:mariadb]
deps =
Django==2.2.*
coverage
Jinja2
html5lib
mysqlclient<1.4
selenium<4.0
sqlparse
setenv =
PYTHONPATH = {toxinidir}
DJANGO_DATABASE_ENGINE = mysql
postgresql: DJANGO_DATABASE_ENGINE = postgresql
mariadb: DJANGO_DATABASE_ENGINE = mysql
whitelist_externals = make
pip_pre = True
commands = make coverage TEST_ARGS='{posargs:tests}'
Expand Down

0 comments on commit 98308a2

Please # to comment.