Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cd47d87

Browse files
Merge pull request #3 from surface-security/fix_analyze
Fix analyze
2 parents b624853 + 08f4bb2 commit cd47d87

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

‎.github/workflows/publish_test.yml_disabled‎ renamed to ‎.github/workflows/publish_test.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# This workflows will upload a Python Package using Twine when a release is created
22
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
33

4-
name: publish
4+
name: publish test
55

66
on:
7-
release:
8-
types: [created]
7+
push:
8+
branches: testpypi
99

1010
jobs:
1111
deploy:

‎dbcleanup/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = '0.1.0'
1+
__version__ = '0.1.1'
22

33
default_app_config = 'dbcleanup.apps.DBCleanupConfig'

‎dbcleanup/utils.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@
55

66
@lru_cache()
77
def model_tables():
8+
from .models import Table
9+
810
tables_in_use = {}
911
for m in registry.apps.get_models():
12+
if m == Table:
13+
# skip ourselves
14+
continue
1015
if not m._meta.managed:
1116
# skip models not managed by django
1217
continue

‎testapp/tests/test_analyze.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import unittest
2+
from unittest import mock
3+
from io import StringIO
4+
5+
from django.test import TestCase
6+
from django.apps import registry
7+
from django.contrib.auth import get_user_model
8+
from django.core.management import call_command
9+
from django.urls import reverse
10+
from django.conf import settings
11+
12+
from dbcleanup import utils, models, admin
13+
14+
15+
@unittest.skipUnless(
16+
settings.DATABASES['default']['ENGINE'] in ('django.db.backends.mysql'),
17+
"only mysql",
18+
)
19+
class Test(TestCase):
20+
def test_command(self):
21+
out = StringIO()
22+
call_command('dbcleanup', stdout=out, just='analyze')
23+
# there might be old tables in the testdb, do not assume empty output...
24+
baseline = {x.split(' ')[1] for x in out.getvalue().splitlines()}
25+
# cannot create tables inside TransactionTests (it's mysql), so let's "remove" a model
26+
org_list = [m for m in registry.apps.get_models() if m._meta.db_table != 'auth_user']
27+
utils.model_tables.cache_clear()
28+
with mock.patch('django.apps.registry.apps.get_models', return_value=org_list):
29+
call_command('dbcleanup', stdout=out, just='tables')
30+
self.assertEqual(
31+
{x.split(' ')[1] for x in out.getvalue().splitlines()} - baseline,
32+
{'auth_user', 'auth_user_groups', 'auth_user_user_permissions'},
33+
)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /