I am testing my application and I am running into an issue and I'm not sure why. I'm loading fixtures for my tests and the fixtures have foreign keys that rely on each other. They must be loaded in a certain order or it won't work.
The fixtures I'm loading are:
["test_company_data", "test_rate_index", 'test_rate_description']
Company data is the first one. test_rate_index has a foreign key to company, and test_rate_description has a foreign key to a model declared in test_rate_index. (as an aside, different test need different fixtures which is why I'm not just shoving everything in one)
If I use django's standard procedure for loading tests, the tests do not load in the proper order.
class TestPackages(test.TestCase): fixtures = ["test_company_data", "test_rate_index", "test_rate_description",]
I get the message
DoesNotExist: RateDescription matching query does not exist.
But if I reverse the order of my fixtures (which makes no sense) it works:
fixtures = ["test_rate_description", "test_company_data", "test_rate_index",]
Django's documentation states that the fixtures load in the order they are declared, but this doesn't seem to be the case.
As a workaround, instead of using django's
call_command('loaddata', *fixtures, **{ 'verbosity': 0, 'commit': False, 'database': 'default' })
I'm using a different function in the setUp method that loads the fixtures one at a time.
def load_fixtures(fixtures): for fixture in fixtures: call_command('loaddata', fixture, **{ 'verbosity': 0, 'commit': False, 'database': 'default' })
Is there something I'm doing incorrectly or not understanding that is causing my fixtures not to be loaded in the proper order when trying to use the standard method?