<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">An example of the failing test and the data/schema would be nice.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">Certainly, I have never had to relax foreign key constraints when running tests. It sounds like maybe you have a problem with your fixture system?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> testing-in-python-bounces@lists.idyll.org [mailto:testing-in-python-bounces@lists.idyll.org]
<b>On Behalf Of </b>Sylvain Le Beux<br>
<b>Sent:</b> Tuesday, September 16, 2014 8:34 AM<br>
<b>To:</b> testing-in-python@lists.idyll.org<br>
<b>Subject:</b> [TIP] Foreign Key Constraint and model testing<o:p></o:p></span></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">Hi all,<o:p></o:p></p>
</div>
<p class="MsoNormal">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.<o:p></o:p></p>
</div>
<p class="MsoNormal">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.<o:p></o:p></p>
</div>
<p class="MsoNormal">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.<o:p></o:p></p>
</div>
<p class="MsoNormal">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.<o:p></o:p></p>
</div>
<p class="MsoNormal">In the first configuration, the test fails and for the latter the test is a success.<o:p></o:p></p>
</div>
<p class="MsoNormal">Thus my interrogations : <o:p></o:p></p>
</div>
<p class="MsoNormal">- Is this common to delete the foreign key constraints while testing against a database model ?
<o:p></o:p></p>
</div>
<p class="MsoNormal">- If the test fails while the foreign key constraints are present, does this means the constraints are badly implemented ?<o:p></o:p></p>
</div>
<p class="MsoNormal">- How do you tests the foreign key constraints themselves ?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">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 ?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">Thanks in advance,<br>
<br>
Sylvain<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<p class="MsoNormal">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)<o:p></o:p></p>
</div>
</div>
</body>
</html>