Tuesday, July 27, 2010

testing with multiple databases

Hello Djangonauts,

I am using django in an application that has multiple distinct
databases, each with unique data (i.e. not master/slave type
configuration). I've created an app (django-admin.py startapp) for
each database and the settings.py defines DATABASE_ROUTERS where I
specify what database a table belongs in depending on the application
a model is in. This configuration has a few bumps when testing.

First, loading fixture data into a database other than the default,
does not work with the 'fixtures' list in a TestCase. I tracked the
problem down to the fixtures only being loaded into the default
database. If the fixture is for data in another database, no go. I
believed I was clever by adding the following to my TestCase's setUp()
function:

management.call_command('loaddata', 'mydata.json',
database='otherdb', verbosity=0)

Then I ran into a problem where databases other than the default are
not cleared per test. Subsequent tests are failing due to additional
data being in the database already.

Is there something I am doing wrong?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment