Skip to content
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 .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.6
- name: Set up Python 3.7
uses: actions/setup-python@v2
with:
python-version: 3.6
python-version: 3.7
- name: Install tox
run: pip install tox
- name: Style check
Expand All @@ -27,20 +27,20 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
python-version: [3.7, 3.8, 3.9]
database: [sqlite, mysql, postgresql]

services:
mysql:
image: mysql:5
image: mysql:8
env:
MYSQL_ROOT_PASSWORD: root
ports:
- 8877:3306
# needed because the container does not provide a healthcheck
options: --health-cmd "mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries=5
postgres:
image: postgres:10
image: postgres:12-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ __pycache__
.pytest_cache
.vscode
/.tox
*.sqlite3
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ TEST_CONTAINER := django-dbcleanup-test

.PHONY: style
style:
black --target-version=py36 \
black --target-version=py37 \
--line-length=120 \
--skip-string-normalization \
dbcleanup testapp setup.py

.PHONY: style_check
style_check:
black --target-version=py36 \
black --target-version=py37 \
--line-length=120 \
--skip-string-normalization \
--check \
Expand Down Expand Up @@ -40,7 +40,7 @@ startpg:
--health-interval 10s \
--health-timeout 5s \
--health-retries 5 \
postgres:10
postgres:11-alpine
until [ "`docker inspect -f {{.State.Health.Status}} ${TEST_CONTAINER}-pg`" == "healthy" ]; do sleep 0.1; done;

testpg: startpg
Expand Down
12 changes: 11 additions & 1 deletion dbcleanup/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ def __str__(self) -> str:

return MySQLTable

if settings.DATABASES['default']['ENGINE'] == 'django.db.backends.postgresql_psycopg2':
if settings.DATABASES['default']['ENGINE'] in (
'django.db.backends.postgresql_psycopg2',
'django.db.backends.postgresql',
):
"""
based on https://wiki.postgresql.org/wiki/Disk_Usage

Expand Down Expand Up @@ -103,14 +106,21 @@ def __str__(self) -> str:

return PGTable

class TableManager(models.Manager):
def get_queryset(self):
return super().get_queryset().none()

class NoTable(models.Model):
"""
bogus to allow projects to run with unsupported DB engines
(but without any functionality from this app)
"""

objects = TableManager()

name = models.CharField(max_length=64, primary_key=True)
rows = models.PositiveBigIntegerField(null=True)
size = models.IntegerField(default=0)

class Meta:
managed = False
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ include_package_data = True
packages = find:
install_requires =
Django >= 3.0
python_requires = >=3.6
python_requires = >=3.7

[options.packages.find]
exclude =
Expand Down
2 changes: 1 addition & 1 deletion testapp/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
pytest==6.2.5
pytest-cov==2.12.1
pytest-django==4.4.0
black==20.8b1
black>=22.0
mysqlclient==2.0.3
psycopg2-binary==2.9.2
1 change: 0 additions & 1 deletion testapp/testapp/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = []
Expand Down
1 change: 0 additions & 1 deletion testapp/testapp/migrations/0002_auto_20211014_1519.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
('testapp', '0001_initial'),
]
Expand Down
20 changes: 20 additions & 0 deletions testapp/tests/test_admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from django.test import TestCase
from django.contrib.auth import get_user_model
from django.urls import reverse


class Test(TestCase):
def setUp(self):
self.user = get_user_model().objects.create_user('tester', 'tester@test.it', 'tester')

def test_changelist(self):
"""
test to make sure that every DB engine allows to *at least* list tables
"""
self.user.is_staff = True
self.user.is_superuser = True
self.user.save()
self.client.force_login(self.user)

r = self.client.get(reverse('admin:dbcleanup_table_changelist'))
self.assertEqual(r.status_code, 200)
8 changes: 4 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ deps =
dj22: Django==2.2.*
dj30: Django==3.0.*
dj32: Django==3.2.*
postgresql: psycopg2-binary
mysql: mysqlclient
postgresql: psycopg2-binary==2.9.5
mysql: mysqlclient==2.1.1
coverage
setenv =
PYTHONPATH = {toxinidir}
sqlite: DJANGO_SETTINGS_MODULE = testapp.settings
postgresql: DJANGO_SETTINGS_MODULE = testapp.settings_postgresql
mysql: DJANGO_SETTINGS_MODULE = testapp.settings_mysql
whitelist_externals = make
allowlist_externals = make
pip_pre = True
commands = make coverage TEST_ARGS='{posargs:tests}'

Expand All @@ -30,6 +30,6 @@ skip_install = true
basepython = python3
commands = make style_check
deps =
black>=19.10b0
black>=22.0
flake8
skip_install = true