[TIP] Foreign Key Constraint and model testing

Sylvain Le Beux artheist at gmail.com
Tue Sep 16 05:33:55 PDT 2014


Hi all,

This is my first post and even though I have been lurking for a while into
test driven development, it's been quite new that I dived into it.
The problem that caused me a great deal recently is the fact that I am
doing some functional tests against a mysql database, build thanks to an
sqlalchemy model.
There are of course numbers of foreign key and my I discovered that the
model objects are being created only if there are no foreign key
constraints on the database.
To make it more clear, I tested to run the tests with a setup where all
foreign constraints are present (it is actually a dump of the database) and
in another setup, the foreign key constraints are deleted, all other things
being equal.
In the first configuration, the test fails and for the latter the test is a
success.
Thus my interrogations :
- Is this common to delete the foreign key constraints while testing
against a database model ?
- If the test fails while the foreign key constraints are present, does
this means the constraints are badly implemented ?
- How do you tests the foreign key constraints themselves ?
If you have any documentation or open source projects examples that deal
with these issues, I would be very glad you'd point them to me ?


Thanks in advance,

Sylvain

N.B. : I tried a setup where I was letting sqlalchemy build the model
itself (i.e. without the dump of the current database, and it fails even
sooner during the setup process, before the tests even started)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20140916/704631c3/attachment.htm>


More information about the testing-in-python mailing list