Skip to content

Commit

Permalink
made tests compatible with newer django releases
Browse files Browse the repository at this point in the history
  • Loading branch information
wolph committed May 15, 2019
1 parent e6ade67 commit 8352b10
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
8 changes: 4 additions & 4 deletions example/db_router.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class Router(object):
TABLE_MAPPINGS = {
'autocompletionexample_extraspam': 'other',
Expand All @@ -11,16 +10,17 @@ def get_db(self, model, **hints):
db_for_read = db_for_write = get_db

def allow_migrate(self, *args, **hints):
# Django 1.8, 1.9 and 1.10 all have different behaviour... sigh
# Django 1.8, 1.9, 1.10 and 2.2 all have different behaviour... sigh
if 'model_name' in hints:
model_name = hints['model_name']
elif 'model' in hints:
model_name = hints['model']._meta.db_table
else:
elif hasattr(args[1], '_meta'):
model_name = args[1]._meta.db_table
else:
model_name = args[1]

return self.TABLE_MAPPINGS.get(model_name, 'default')

def allow_relation(self, obj1, obj2, **hints):
return True

2 changes: 2 additions & 0 deletions example/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class Form(forms.Form):


class BaseTestCase(test.TestCase):
databases = ['default', 'other']

@transaction.atomic
def setUp(self):
self.client = client.Client()
Expand Down
15 changes: 10 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[tox]
envlist =
py{py,27}-django11,
py35-django{11,20},
py36-django{11,20},
py35-django{11,21,22},
py36-django{11,21,22},
py37-django{11,21,22},
py38-django{11,21,22},
flake8,
docs

Expand All @@ -12,13 +14,16 @@ usedevelop = True
[testenv]
deps =
django11: Django<2.0
django20: Django>=2.0,<2.1
django21: Django>=2.1,<2.2
django22: Django>=2.2,<2.3
-r{toxinidir}/example/requirements.txt

envlist =
py{py,27}-django11,
py35-django{11,20},
py36-django{11,20},
py35-django{11,21,22},
py36-django{11,21,22},
py37-django{11,21,22},
py38-django{11,21,22}

commands =
python setup.py test
Expand Down

0 comments on commit 8352b10

Please sign in to comment.