mirror of
https://github.com/django-helpdesk/django-helpdesk.git
synced 2024-12-13 10:21:05 +01:00
Django1.7 tests: load initial_data w/ migration
This commit is contained in:
parent
afb0bd25b3
commit
f68c1b3ae9
44
helpdesk/migrations/0004_initial_data_import.py
Normal file
44
helpdesk/migrations/0004_initial_data_import.py
Normal file
@ -0,0 +1,44 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
from sys import path
|
||||
|
||||
from django.db import models, migrations
|
||||
from django.core import serializers
|
||||
|
||||
fixture_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '../fixtures'))
|
||||
fixture_filename = 'initial_data.json'
|
||||
|
||||
def deserialize_fixture():
|
||||
fixture_file = os.path.join(fixture_dir, fixture_filename)
|
||||
|
||||
with open(fixture_file, 'rb') as fixture:
|
||||
return list(serializers.deserialize('json', fixture, ignorenonexistent=True))
|
||||
|
||||
|
||||
def load_fixture(apps, schema_editor):
|
||||
objects = deserialize_fixture()
|
||||
|
||||
for obj in objects:
|
||||
obj.save()
|
||||
|
||||
|
||||
def unload_fixture(apps, schema_editor):
|
||||
"Delete all EmailTemplate objects"
|
||||
|
||||
objects = deserialize_fixture()
|
||||
|
||||
EmailTemplate = apps.get_model("helpdesk", "emailtemplate")
|
||||
EmailTemplate.objects.filter(pk__in=[ obj.object.pk for obj in objects ]).delete()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('helpdesk', '0003_populate_usersettings'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(load_fixture, reverse_code=unload_fixture),
|
||||
]
|
10
quicktest.py
10
quicktest.py
@ -28,6 +28,7 @@ class QuickDjangoTest(object):
|
||||
'django.contrib.humanize',
|
||||
'bootstrapform',
|
||||
)
|
||||
MIDDLEWARE_CLASSES = []
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.apps = args
|
||||
@ -43,8 +44,7 @@ class QuickDjangoTest(object):
|
||||
"""
|
||||
Figure out which version of Django's test suite we have to play with.
|
||||
"""
|
||||
from django import VERSION
|
||||
if VERSION[0] == 1 and VERSION[1] >= 2:
|
||||
if django.VERSION > (1, 2):
|
||||
return 'new'
|
||||
else:
|
||||
return 'old'
|
||||
@ -67,6 +67,7 @@ class QuickDjangoTest(object):
|
||||
"""
|
||||
Fire up the Django test suite developed for version 1.2
|
||||
"""
|
||||
|
||||
settings.configure(
|
||||
DEBUG = True,
|
||||
DATABASES = {
|
||||
@ -80,9 +81,12 @@ class QuickDjangoTest(object):
|
||||
}
|
||||
},
|
||||
INSTALLED_APPS = self.INSTALLED_APPS + self.apps,
|
||||
MIDDLEWARE_CLASSES = self.MIDDLEWARE_CLASSES,
|
||||
ROOT_URLCONF = self.apps[0] + '.urls',
|
||||
)
|
||||
django.setup()
|
||||
|
||||
if django.VERSION > (1, 7):
|
||||
django.setup()
|
||||
|
||||
from django.test.simple import DjangoTestSuiteRunner
|
||||
failures = DjangoTestSuiteRunner().run_tests(self.apps, verbosity=1)
|
||||
|
Loading…
Reference in New Issue
Block a user