Skip to content

Commit

Permalink
Dealing with tests configuration on Django 1.9+. Wip commit
Browse files Browse the repository at this point in the history
  • Loading branch information
darklow committed Aug 18, 2016
1 parent 9c217ee commit f3cfd85
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 13 deletions.
12 changes: 6 additions & 6 deletions suit/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import django
try:
# Django 1.9+
django.setup()
except Exception:
pass

from suit.tests.templatetags.suit_menu import SuitMenuTestCase, \
SuitMenuAdminRootURLTestCase, SuitMenuAdminI18NURLTestCase, \
SuitMenuAdminCustomURLTestCase
Expand All @@ -15,12 +21,6 @@
except ImportError:
from django.test.simple import DjangoTestSuiteRunner

try:
# Django 1.9 only
django.setup()
except Exception:
pass


class NoDbTestRunner(DjangoTestSuiteRunner):
"""A test suite runner that does not set up and tear down a database."""
Expand Down
36 changes: 36 additions & 0 deletions suit/tests/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Album',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=64)),
],
),
migrations.CreateModel(
name='Book',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=64)),
],
options={
'ordering': ('-id',),
},
),
migrations.CreateModel(
name='User',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=64)),
],
),
]
Empty file.
16 changes: 12 additions & 4 deletions suit/tests/mixins.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.conf import settings
from django.contrib.auth.models import User
from django.core.management import CommandError
from django.core.management import call_command
from django.core.urlresolvers import reverse
from django.db.models.loading import load_app
from django.test import TestCase
from random import randint

Expand Down Expand Up @@ -53,9 +53,17 @@ def _pre_setup(self):
list(self.saved_INSTALLED_APPS) + [test_app]
)
settings.DEBUG = True
# load our fake application and syncdb
load_app(test_app)
call_command('syncdb', verbosity=0, interactive=False)

# Legacy Django < 1.9: load our fake application and syncdb
try:
from django.db.models.loading import load_app
load_app(test_app)
except ImportError:
pass
try:
call_command('syncdb', verbosity=0, interactive=False)
except CommandError:
pass
super(ModelsTestCaseMixin, self)._pre_setup()

def _post_teardown(self):
Expand Down
3 changes: 0 additions & 3 deletions suit/tests/templates/form_tabs.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from django.conf import settings
from django.contrib import admin
from django.core.urlresolvers import reverse
from django.template.base import TemplateDoesNotExist
from django.utils.translation import ugettext
from suit.templatetags.suit_menu import get_menu
from suit.tests.mixins import ModelsTestCaseMixin, UserTestCaseMixin
from suit.tests.models import Book, BookAdmin, test_app_label

Expand Down
1 change: 1 addition & 0 deletions suit/tests/templatetags/suit_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def setUp(self):
self.login_superuser()

def setUpConfig(self):
settings.SUIT_CONFIG = getattr(settings, 'SUIT_CONFIG', {})
settings.SUIT_CONFIG.update({
'MENU_OPEN_FIRST_CHILD': True,
'MENU_ICONS': {
Expand Down

0 comments on commit f3cfd85

Please sign in to comment.