Yep, that&#39;s the module I&#39;m talking about.  <div><br></div><div>I&#39;m not quite sure what you&#39;re asking. The test classes load fixtures via hand-coded SQLAlchemy objects.  Something like this:</div><div><br></div>
<div>def setup(self):</div><div><div><br></div><div>    objects = [</div><div>      Employee(name=&quot;engineer&quot;, role=&quot;engineer&quot;),</div><div>      Employee(name=&quot;manager&quot;, role=&quot;manager&quot;),</div>
<div>    ]</div><div>    </div><div>    for item in objects:</div><div>        db.session.add(item)</div><div>        </div><div>    db.session.commit()</div><div> </div></div><div>It works okay for small sets of data, but relating objects/primary keys are annoying and I can&#39;t refer to particular objects easily. The fixture module looked like it handled that part of it nicely. </div>
<div><br></div><div>(Also, the developer before me didn&#39;t want to create separate data for each test and instead just created a giant shared one. I&#39;m trying to kill it - it slows down the tests tremendously and makes them hard to debug.)</div>
<div><br></div><div>It looks like testscenario is for generating *tests*, not fixture data, or am I reading it wrong? The only examples I could find were for that.</div><div><div><br></div><div><div class="gmail_quote">On Wed, Nov 21, 2012 at 6:25 PM, Martin Pool <span dir="ltr">&lt;<a href="mailto:mbp@sourcefrog.net" target="_blank">mbp@sourcefrog.net</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Are you talking about &lt;<a href="http://pypi.python.org/pypi/fixtures" target="_blank">http://pypi.python.org/pypi/fixtures</a>&gt; or something else?  What does your current fixture-using code look like?<div>

<br></div><div>For things where you want to repeat a test over a possibly dynamically generated set of conditions, &lt;<a href="http://pypi.python.org/pypi/testscenarios" target="_blank">http://pypi.python.org/pypi/testscenarios</a>&gt; is good.</div>



<div class="gmail_extra"><br><br><div class="gmail_quote"><div><div>On 22 November 2012 04:54, Rachel Sanders <span dir="ltr">&lt;<a href="mailto:rachel@trustrachel.com" target="_blank">rachel@trustrachel.com</a>&gt;</span> wrote:<br>



</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div>I&#39;m working with the fixture module for the first time, trying to get a better set of testing data so I can make our functional tests more complete.</div>



<div><br></div><div>I&#39;m finding the fixture module a bit clunky, and I&#39;m hoping it&#39;s just because I&#39;m going at this wrong. This is a Flask/SQLAlchemy app in Python 2.7, and we&#39;re using nose as a test runner.</div>




<div><br></div><div>So I have a set of employees. Employees have roles. There&#39;s a few pages in our app with  complex permissions, and I&#39;d like to make sure those are tested fully.</div><div><br></div><div>I created a DataSet that has each type of role (there&#39;s about 15 roles in our app):</div>




<div><br></div><div>class EmployeeData(DataSet):</div><div><br></div><div>  class Meta:</div><div>    storable = Employee</div><div><br></div><div>  class engineer:</div><div>    username = &quot;engineer&quot;</div><div>




    role = ROLE_ENGINEER</div><div><br></div><div>  class manager:</div><div>    username = &quot;manager&quot;</div><div>    role = ROLE_MANAGER</div><div><br></div><div>  class admin:</div><div>    username = &quot;admin&quot;</div>




<div>    role = ROLE_ADMIN</div><div>    </div><div>and what I&#39;d like to do is write a functional test that checks only the right people can access a page. (The actual permissions are way more complicated, I just wanted a toy example to show you.)</div>




<div><br></div><div>Something like this:</div><div><br></div><div>def test_only_admin_can_see_this_page():</div><div><br></div><div>  for employee in Employee.query.all():</div><div>    login(employee)</div><div><br></div>




<div>    with self.app.test_request_context(&#39;/&#39;):</div><div>      response = self.test_client.get(ADMIN_PAGE)</div><div>      if employee.role == ROLE_ADMIN</div><div>        eq_(200, response.status_code)</div><div>




      else:</div><div>        eq_(401, response.status_code)</div><div><br></div><div>    logout(employee)</div><div>    </div><div>Is there a way to generate the fixture data so we don&#39;t have to remember to add a line to the fixtures every time we add a role? We have the canonical list of all roles as configuration elsewhere in the app, so I have that.</div>




<div><br></div><div>I&#39;m not wedded to any of this or the fixture module, so I&#39;m happy to hear suggestions!</div><div><br></div><div>I also asked this question over at StackOverflow, so if any of the code doesn&#39;t come through right, you can see it there: </div>




<div><a href="http://stackoverflow.com/questions/13480955/generating-fixture-data-with-pythons-fixture-module" target="_blank">http://stackoverflow.com/questions/13480955/generating-fixture-data-with-pythons-fixture-module</a></div>



<div>
<br></div><div>thanks in advance,</div><div>Rachel</div>
<br></div></div>_______________________________________________<br>
testing-in-python mailing list<br>
<a href="mailto:testing-in-python@lists.idyll.org" target="_blank">testing-in-python@lists.idyll.org</a><br>
<a href="http://lists.idyll.org/listinfo/testing-in-python" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
<br></blockquote></div><span><font color="#888888"><br><br clear="all"><div><br></div>-- <br>Martin<br><br>
</font></span></div>
</blockquote></div><br></div>
</div>