Merge lp:~elachuni/u1-test-utils/migration-tests into lp:u1-test-utils

Proposed by Anthony Lenton
Status: Rejected
Rejected by: Vincent Ladeuil
Proposed branch: lp:~elachuni/u1-test-utils/migration-tests
Merge into: lp:u1-test-utils
Diff against target: 104 lines (+76/-6)
3 files modified
canonical/__init__.py (+0/-5)
isdutils/tests/migrations.py (+75/-0)
setup.py (+1/-1)
To merge this branch: bzr merge lp:~elachuni/u1-test-utils/migration-tests
Reviewer Review Type Date Requested Status
Vincent Ladeuil (community) Needs Fixing
Review via email: mp+55551@code.launchpad.net

Description of the change

Overview
========
This branch adds a drop-in migration test case that can be applied to all our projects.

Details
=======
The new MigrationTestCase basically runs all migrations forwards and backwards again, to ensure that they run correctly.
A future improvement would be to add frozen fixtures that can be loaded after each migration, to ensure that the DB schema is left in a sane state.

While I was there, I renamed canonical.isd to isdutils, so that we're not using namespace packages as agreed in our team tech call.

To post a comment you must log in.
Revision history for this message
Vincent Ladeuil (vila) wrote :

Unfortunately this mp seems to be abandoned, marking as rejected to clear the queue, feel free to mark needs review with an explanation if needed.

review: Needs Fixing

Unmerged revisions

2. By Anthony Lenton

Renamed canonical.isd package to isdutils.

Added MigrationTestCase, that should be a drop-in test for migrations in all our projects.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== removed directory 'canonical'
=== removed file 'canonical/__init__.py'
--- canonical/__init__.py 2011-02-07 16:48:09 +0000
+++ canonical/__init__.py 1970-01-01 00:00:00 +0000
@@ -1,5 +0,0 @@
1from pkgutil import extend_path
2
3
4# denote package as namespace package
5__path__ = extend_path(__path__, __name__)
60
=== renamed directory 'canonical/isd' => 'isdutils'
=== added file 'isdutils/tests/migrations.py'
--- isdutils/tests/migrations.py 1970-01-01 00:00:00 +0000
+++ isdutils/tests/migrations.py 2011-03-30 14:26:01 +0000
@@ -0,0 +1,75 @@
1# A standard test case for checking migrations. Just import MigrationTestCase
2# from your tests' __init__.py
3
4from __future__ import absolute_import
5
6__all__ = [
7 'MigrationTestCase',
8]
9
10import os
11
12from django.conf import settings
13from django.core import management
14from django.db import connection
15from south import migration, orm
16
17from isdutils.tests.django import switch_settings
18from isdutils.tests.logging import LogHandlerTestCase
19
20class MigrationTestCase(LogHandlerTestCase):
21 def setUp(self):
22 self.test_db_name = '/tmp/migrations_test.sql'
23 patched_settings = {
24 'DATABASE_NAME': self.test_db_name,
25 'DATABASE_ENGINE': 'sqlite3',
26 }
27 self.orig_settings = switch_settings(**patched_settings)
28 connection.settings_dict.update(patched_settings)
29 self.orig_connection = connection.connection
30 connection.connection = None
31 management._commands['syncdb'] = 'south'
32
33 def patch_hacky_sqlite3_cludge(self):
34 """Work around a South sqlite3 hack with another even hackier one.
35
36 As Sqlite3 doesn't support altering or deleting a column, South
37 simulates this by creating a new table with the new columns, copying
38 over the data and then putting the new table in the old one's place.
39
40 South 0.6 does this at most once for each migration, so the new table
41 is remade the first time any column is deleted or altered.
42
43 So's to remember that it has already remade a table it stores a class
44 attribute *on the orm model itself*. As South's orm stores one model
45 per migration, this works fine as long as each migration is run
46 at most once per process, in any direction.
47
48 To be able to run migrations multiple times here, we invalidate the
49 orm's cache after any run.
50
51 Luckily this hack won't be needed in South 0.7.
52 """
53 orm._orm_cache = {}
54
55 def tearDown(self):
56 switch_settings(**self.orig_settings)
57 connection.settings_dict.update(self.orig_settings)
58 connection.connection = self.orig_connection
59 if os.path.exists(self.test_db_name):
60 os.remove(self.test_db_name)
61 management._commands['syncdb'] = 'django.core'
62
63 def test_migrations_straight_forwards(self):
64 """Run migrations forwards from an empty DB"""
65 management.call_command('syncdb', migrate=True, interactive=False,
66 verbosity=0)
67 self.patch_hacky_sqlite3_cludge()
68
69 def test_migrations_straight_backwards(self):
70 """Run migrations backwards, from an fully migrated DB"""
71 management.call_command('syncdb', migrate=True, interactive=False,
72 verbosity=0)
73 self.patch_hacky_sqlite3_cludge()
74 management.call_command('migrate', target='zero', verbosity=0)
75 self.patch_hacky_sqlite3_cludge()
076
=== modified file 'setup.py'
--- setup.py 2011-02-08 20:15:31 +0000
+++ setup.py 2011-03-30 14:26:01 +0000
@@ -8,7 +8,7 @@
8def get_version():8def get_version():
9 version = [9 version = [
10 (line.split('=')[1]).strip().strip('"').strip("'")10 (line.split('=')[1]).strip().strip('"').strip("'")
11 for line in open(os.path.join('canonical', 'isd', '__init__.py'))11 for line in open(os.path.join('isdutils', '__init__.py'))
12 if line.startswith( '__version__' )12 if line.startswith( '__version__' )
13 ][0]13 ][0]
14 return version14 return version

Subscribers

People subscribed via source and target branches

to all changes: