On Thursday, 2 February 2012 18:43:43 UTC, Andrew Godwin wrote:
On 02/02/12 17:15, George Lund wrote:
> I have a problem where South is not persisting the on_delete option
> passed to a ForeignKey, when it saves the ORM into a migration.
...
Yep, it's probably because on_delete is relatively new (well, compared
to South's last release) and it's not in the models introspector.
Andrew
Unfortunately I've really struggled with making test cases.
I created a new class south.tests.ondelete.TestMigration, like the other tests.
This test is different to the others in that I want to first freeze the ORM, as in a migration, then generate the models, and make sure that they behave as expected. Just testing a previously-frozen set of models in a pre-created migration wouldn't really test that the freezing process still includes the correct field attributes.
To do this, I tried to create a dummy migration class, from which I could extract a working ORM. My function (to be used by my test class) looks like this:
_TEST_APP_NAME = "ondeleteapp"
def _get_orm():
class _DummyMigration(object):
models = None
migration_class = _DummyMigration
migration_class.models = freeze_apps(_TEST_APP_NAME)
orm = FakeORM(migration_class, _TEST_APP_NAME)
return orm
Unfortunately, freeze_apps doesn't work from here. I don't know why -- I'm just getting nothing back.
The problem actually happens in freezer.py:25, where this standard Django call
models.get_models(models.get_app(app))
is returning an empty list.
I just don't know how to get my test case's models to appear. (Adding the test case into INSTALLED_APPS doesn't seem to actually help.)
It looked like the monkey-patching base test class might be trying to fix this kind of thing but what it was doing left me confused, and deriving from that didn't seem to help.
Hopefully someone else can pick up where I'm going here, unfortunately I don't have any more time to look at this right now (though let me know if I can clarify any of the above).
thanks
George