Testing with subclassed models - south syncdb?

27 views
Skip to first unread message

perrygeo

unread,
Mar 29, 2010, 2:32:03 PM3/29/10
to South Users, underbl...@gmail.com
We have a reusable django app with a few abstract models which need to
be subclassed by the project that implements them. For instance:

class Mpa(models.Model):
....
class Meta:
abstract = True

then the project using this would have a model such as:

class MyMpa(Mpa):
....

So in the test.py files, we have to subclass 'Mpa' to create a non-
abstract model to work on.

When running a test suite _without_ south installed, the model is
recognized and the appropriate tables are created in the test db.
However, running the tests _with_ south installed, the tables are not
created and the tests fail due to the missing tables.

Can I assume this is due to some difference in south's syncdb vs the
builtin django syncdb? Any ideas on how to fix this? As a last resort
I suppose we could uninstall south when we run the tests but I'm
hoping there is a better solution.

Andrew Godwin

unread,
Mar 29, 2010, 2:54:25 PM3/29/10
to south...@googlegroups.com
When you run tests with South turned on, it will use migrations to
create the tables for apps (that have migrations), not the standard
syncdb method.

It sounds like you have a set of migrations that doesn't rebuild the
database properly - when you run migrations from scratch on an empty
database, does it miss out any tables? Did you forget to make an
--initial migration?

(Also, what Django and South versions are you running?)

Andrew

perrygeo

unread,
Mar 29, 2010, 4:32:19 PM3/29/10
to South Users
On 29/03/10 21:25, perrygeo wrote:

versions: django trunk, south 0.7

We made initial migrations on all apps and migrate rebuilds the
*live*
database just fine. But our test database is significantly
different
as it requires additional models.

For example, in test.py
---------
class testMpa(Mpa):
pass

class TestStuff(TestCase):
def test_stuff(self):
testMpa.objects.whatever(...)
---------
creating these test models is required since we can't test Mpa
directly (it's an abstract base class) and we can't be certain
which
model inherits from Mpa (that depends on the project that
implements
it).

In any case, regular syncdb picks up on this and creates an
'appname_testmpa' table when running the test suite. South syncdb
doesn't appear to. Does this clarify the problem?


On 29/03/10 21:25, Andrew Godwin <andrewgod...@gmail.com> wrote:

Right, I see what you mean now - it won't work with migrations, since
you have models that only appear in migrations.

In any case, this is why there's the SOUTH_TESTS_MIGRATE setting:
http://south.aeracode.org/docs/settings.html#south-tests-migrate

Set that to False, and your tests should run with syncdb as normal.

Reply all
Reply to author
Forward
0 new messages