<div>I'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'm finding the fixture module a bit clunky, and I'm hoping it's just because I'm going at this wrong. This is a Flask/SQLAlchemy app in Python 2.7, and we're using nose as a test runner.</div>
<div><br></div><div>So I have a set of employees. Employees have roles. There's a few pages in our app with complex permissions, and I'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'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 = "engineer"</div><div>
role = ROLE_ENGINEER</div><div><br></div><div> class manager:</div><div> username = "manager"</div><div> role = ROLE_MANAGER</div><div><br></div><div> class admin:</div><div> username = "admin"</div>
<div> role = ROLE_ADMIN</div><div> </div><div>and what I'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('/'):</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'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'm not wedded to any of this or the fixture module, so I'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'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">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>