Skip to content

Commit

Permalink
Added working South tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinwong-ca committed Feb 14, 2015
1 parent c954ae4 commit dcaa5a6
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 22 deletions.
8 changes: 5 additions & 3 deletions MANIFEST.in
Expand Up @@ -11,6 +11,9 @@ recursive-include test_projects *.py

recursive-include test_projects/django14 *.py
recursive-include test_projects/django14/django14 *.py
recursive-include test_projects/django14/forthewing *.py
recursive-include test_projects/django14/forthewing/templates/forthewing *.html
recursive-include test_projects/django14/forthewing/templatetags *.py
recursive-include test_projects/django14/global_assets/static/css *.css
recursive-include test_projects/django14/global_assets/static/multiselect-0.9.10 *.txt *.markdown *.json
recursive-include test_projects/django14/global_assets/static/multiselect-0.9.10/css *.css
Expand All @@ -22,6 +25,5 @@ recursive-include test_projects/django14/global_assets/templates/theme *.html
recursive-include test_projects/django14/pizzagigi *.py
recursive-include test_projects/django14/pizzagigi/templates/pizzagigi *.html
recursive-include test_projects/django14/pizzagigi/templatetags *.py
recursive-include test_projects/django14/forthewing *.py
recursive-include test_projects/django14/forthewing/templates/forthewing *.html
recursive-include test_projects/django14/forthewing/templatetags *.py
recursive-include test_projects/django14/suthern/ *.py
recursive-include test_projects/django14/suthern/migrations/ *.py
8 changes: 8 additions & 0 deletions setup.py
Expand Up @@ -55,6 +55,14 @@ def run(self):
call_command('test', 'pizzagigi', interactive=False, verbosity=1)
call_command('test', 'forthewing', interactive=False, verbosity=1)

try:
import south
except ImportError:
pass
else:
call_command('test', 'suthern', interactive=False, verbosity=1)


cmdclasses['test_demo'] = DemoTester


Expand Down
43 changes: 43 additions & 0 deletions test_projects/django14/suthern/migration_helpers.py
@@ -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)
31 changes: 19 additions & 12 deletions test_projects/django14/suthern/tests.py
@@ -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])
8 changes: 1 addition & 7 deletions tox.ini
Expand Up @@ -2,7 +2,7 @@
envlist =
py26-dj14, py26-dj16, py26-dj14-south, py26-dj16-south,
py27, py27-dj14, py27-dj16, py27-dj14-south, py27-dj16-south, py27-djnext,
py32, py32-dj16, py32-dj16-south,
py32, py32-dj16,
py33, py33-dj16, py33-dj16-south,
py34, py34-dj16, py34-dj16-south, py34-djnext

Expand Down Expand Up @@ -78,12 +78,6 @@ basepython = python3.2
deps =
django==1.6.10

[testenv:py32-dj16-south]
basepython = python3.2
deps =
django==1.6.10
south==1.0.2

[testenv:py33]
deps =
django==1.7.4
Expand Down

0 comments on commit dcaa5a6

Please sign in to comment.