views:

24

answers:

2

Hi,

I've made a mistake of creating my own User model and am trying to recover.

I've created a south migration that copies my old user models and creates django.contrib.auth.models.User models. To ensure my current users don't get left in the dark, I created a bunch of unittests to ensure everything gets converted appropriately.

So, I need to test the south migration and see if it worked. In order to do that I need to load data of the old User type before the migration runs. How do I do that?

A: 

When the test suite is run via python manage.py test someapp, first django creates a test database, then applies all migrations in order, then runs test cases. So if the goal is to test the migration itself, you'll need to load fixture data before that migration.

You can add a line or two loading fixture to your migration that applies your model changes just for the sake of testing, then remove.

def forwards(self, orm):
    from django.core import management
    management.call_command('loaddata', 'myfixture.json')
    ... your migration

also, you can add a condition on some made up django setting, then you won't have to edit the code later.

Evgeny
A: 

Is called data migrations: http://south.aeracode.org/docs/tutorial/part3.html enjoy!

diegueus9
I'm already using a data migration. The question is how do I test it?
Pilgrim
http://south.aeracode.org/docs/fixtures.html#initial-data
diegueus9
http://south.aeracode.org/docs/signals.html#pre-migrate
diegueus9
and if you are paranoic about this, may i suggest run migration in development environment with the copy of data and make a backup before run the migration in production server(s)?
diegueus9