Testing access security

In fact, our tests should be failing right now due to the missing access rules. They aren't because they are done with the Admin user. In databases with demo data enabled, we also make available a Demo user, with "typical" backend access. We should change the tests so that they are performed using the Demo user.

We can modify our tests to take this into account. Edit the tests/test_todo.py file to add a setUp method:

    def setUp(self, *args, **kwargs): 
        result = super(TestTodo, self).setUp(*args, **kwargs) 
        user_demo = self.env.ref('base.user_demo') 
        self.env= self.env(user=user_demo) 
        return result 

This first instruction calls the setUp code of the parent class. The next ones change the environment used to run the tests, ...

Get Odoo 11 Development Essentials - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.