Generating Instrument Data Using the Python Module

This is my first time working with a device module, trying to get a better set of device data so that I can make our functional tests more complete.

I find the instrument module a little awkward and I hope that there will be a better way to do what I do. This is a Flask / SQLAlchemy application in Python 2.7, and we use the nose as a test runner.

So, I have a set of employees. Employees have roles. There are several pages with fairly complex permissions, and I would like to make sure they are tested.

I created a DataSet that has every role type (about 15 roles in our application):

class EmployeeData(DataSet): class Meta: storable = Employee class engineer: username = "engineer" role = ROLE_ENGINEER class manager: username = "manager" role = ROLE_MANAGER class admin: username = "admin" role = ROLE_ADMIN 

and what I would like to do is write a functional test that only checks those who have access to the page. (Actual permissions are much more complicated, I just wanted to show you a toy example.)

Something like that:

 def test_only_admin_can_see_this_page(): for employee in Employee.query.all(): login(employee) with self.app.test_request_context('/'): response = self.test_client.get(ADMIN_PAGE) if employee.role == ROLE_ADMIN eq_(200, response.status_code) else: eq_(401, response.status_code) logout(employee) 

Is there a way to generate binding data, so my developers donโ€™t need to remember adding a row to fixtures every time we add a role? We have a canonical list of all roles as a configuration elsewhere in the application, so I have it.

I am not attached to any of this or to the instrument module, so I am glad to hear the suggestions!

+4
source share
1 answer

Try https://github.com/klen/mixer . Very simple and quick creation of fixtures.

+1
source

Source: https://habr.com/ru/post/1447326/


All Articles