Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c954ae4
commit dcaa5a6
Showing
5 changed files
with
76 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.core.management import call_command | ||
from django.test import TransactionTestCase | ||
|
||
from south.migration import Migrations | ||
|
||
|
||
class SouthMigrationTestCase(TransactionTestCase): | ||
"""A Test case for testing South migrations.""" | ||
|
||
# Source: | ||
# https://micknelson.wordpress.com/2013/03/01/testing-django-migrations/ | ||
|
||
# These must be defined by subclasses. | ||
start_migration = None | ||
dest_migration = None | ||
django_application = None | ||
|
||
def setUp(self): | ||
super(SouthMigrationTestCase, self).setUp() | ||
migrations = Migrations(self.django_application) | ||
self.start_orm = migrations[self.start_migration].orm() | ||
self.dest_orm = migrations[self.dest_migration].orm() | ||
|
||
# Ensure the migration history is up-to-date with a fake migration. | ||
# The other option would be to use the south setting for these tests | ||
# so that the migrations are used to setup the test db. | ||
call_command('migrate', self.django_application, fake=True, | ||
verbosity=0) | ||
# Then migrate back to the start migration. | ||
call_command('migrate', self.django_application, self.start_migration, | ||
verbosity=0) | ||
|
||
def tearDown(self): | ||
# Leave the db in the final state so that the test runner doesn't | ||
# error when truncating the database. | ||
call_command('migrate', self.django_application, verbosity=0) | ||
|
||
def migrate_to_dest(self): | ||
call_command('migrate', self.django_application, self.dest_migration, | ||
verbosity=0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,23 @@ | ||
""" | ||
This file demonstrates writing tests using the unittest module. These will pass | ||
when you run "manage.py test". | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
Replace this with more appropriate tests for your application. | ||
""" | ||
from .migration_helpers import SouthMigrationTestCase | ||
|
||
from django.test import TestCase | ||
from .models import ChickenBalls | ||
|
||
|
||
class SimpleTest(TestCase): | ||
def test_basic_addition(self): | ||
""" | ||
Tests that 1 + 1 always equals 2. | ||
""" | ||
self.assertEqual(1 + 1, 2) | ||
class MyMigrationTestCase(SouthMigrationTestCase): | ||
|
||
start_migration = '0001_initial' | ||
dest_migration = '0002_auto__add_field_chickenballs_dips' | ||
django_application = 'suthern' | ||
|
||
def test_field_survives_migration(self): | ||
self.migrate_to_dest() | ||
|
||
choice_1 = ChickenBalls.HONEY_MUSTARD | ||
order = ChickenBalls() | ||
order.dips = choice_1 | ||
order.save() | ||
|
||
self.assertEqual(order.dips, [choice_1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters