Do I need to load Django Fixtures in the wrong order when testing?

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?

+6
python django django-fixtures
source share
1 answer

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.

This, of course, is strange. The lights load in the correct order when I tested one of my projects (Django 1.2.1, Python 2.6.2, Postgresql 8.3.11).

Here is what I would do to troubleshoot.

DoNotExist: RateDescription mapping request does not exist.

  • Do you get this error when loading the instrument or when performing a test? Can you find a fixture / code that raises this? If necessary, increase verbosity.

  • Can you try running the loaddata command from the command line? Call it three times, passing the name of one fixture for each call in the proper expected sequence. And see if the appliances load.

  • I know that you probably already did this, but can you make sure that the first and second lamps do not contain any RateDescription data?

+1
source share

All Articles