[TIP] Generating fixture data with the fixture module
rachel at trustrachel.com
Wed Nov 21 09:54:33 PST 2012
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.
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.
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
I created a DataSet that has each type of role (there's about 15 roles in
storable = Employee
username = "engineer"
role = ROLE_ENGINEER
username = "manager"
role = ROLE_MANAGER
username = "admin"
role = ROLE_ADMIN
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.)
Something like this:
for employee in Employee.query.all():
response = self.test_client.get(ADMIN_PAGE)
if employee.role == ROLE_ADMIN
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.
I'm not wedded to any of this or the fixture module, so I'm happy to hear
I also asked this question over at StackOverflow, so if any of the code
doesn't come through right, you can see it there:
thanks in advance,
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the testing-in-python