I am testing my application and I am having a problem and am not sure why. I download instruments for my tests, and instruments have foreign keys that rely on each other. They must be loaded in a specific order or will not work.
Attached files that I upload:
["test_company_data", "test_rate_index", 'test_rate_description']
These companies are the first. test_rate_index has a foreign key for the company, and test_rate_description has a foreign key for the model declared in test_rate_index. (alternatively, different tests need different devices, so I donโt just push all in one)
If I use the standard django routine to load the tests, the tests do not load in the correct order.
class TestPackages (test.TestCase):
fixtures = ["test_company_data", "test_rate_index", "test_rate_description",]
I get a message
DoesNotExist: RateDescription matching query does not exist.
But if I cancel the order of my devices (which does not make sense), it works:
fixtures = ["test_rate_description", "test_company_data", "test_rate_index",]
The Django documentation claims that the scales load in the order in which they are declared, but this does not seem to be the case.
As a workaround instead of using django
call_command ('loaddata', * fixtures, ** {
'verbosity': 0,
'commit': False,
'database': 'default'
}) I use another function in the setUp method, which 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 that I am doing wrong or do not understand that my devices cannot load in the correct order when trying to use the standard method?