Tuesday, February 21, 2017

Initial data, tests and migrations

Hi all

I'm having some difficulty working out how I am supposed to provide
initial data for testing purposes, particularly when the initial data
is not immediately pertinent to the test.

For instance, our project uses django_otp, which has some simple
tests. However, these tests create user objects, which then calls in
to other parts of the project code. This code adds users to various
auth.Group, depending upon the user attributes. This code fails after
the first test has been run, because all the auth.Group model
instances are flushed from the database.

Previously, these instances were loaded from a JSON fixtures file,
which used to be the recommended way. For our own tests, we simply
load these fixtures in the setUp portion of the test; obviously we
can't go around modifying tests in third party libraries.
I tried taking them out of the fixtures, and adding them instead in a
data migration, but this also had the same effect - the instances were
there for the first test ran, and then missing for all the subsequent
ones.


What is the "correct" way of ensuring that these instances exist in
the test database before any test is run?

How can I stop them getting wiped out after any test has run?

Cheers

Tom

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFHbX1JKCugKaijhD6_wX-M-2nN04eTqDuFG08%3D%2BtUNBW3o5hA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment