官术网_书友最值得收藏!

Testing access security

Access security can also be checked to confirm that users have the correct privileges granted.

By default, tests are executed with the Odoo internal user, __system__, which bypasses access security. So we need to change the user running the tests, to check whether the right access security has been given to them. This is done by modifying the execution environment, in self.env, by setting the user attribute to the user we want to run the tests with.

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

def setUp(self, *args, **kwargs): 
        result = super().setUp(*args, **kwargs) 
        user_admin = self.env.ref('base.user_admin') 
        self.env= self.env(user=user_admin)
self.Book = self.env['library.book']
self.book_ode = self.Book.create({
'name': 'Odoo Development Essentials',
'isbn': '879-1-78439-279-6'})
return result

This first instruction calls the setUp code of the parent class. The next one changes the environment used to run the tests, self.env, to a new one that uses the admin user. No further changes are needed for the tests we already wrote.

主站蜘蛛池模板: 托克托县| 鸡西市| 金山区| 南城县| 鸡东县| 嵊泗县| 盱眙县| 巩留县| 从化市| 襄汾县| 余姚市| 丰原市| 米易县| 富川| 辛集市| 赣州市| 枣阳市| 古田县| 资源县| 四会市| 金华市| 嘉义县| 双辽市| 田林县| 漯河市| 祁连县| 迁西县| 兴城市| 文山县| 呼伦贝尔市| 新巴尔虎右旗| 松原市| 湘乡市| 丽江市| 平原县| 潼南县| 连城县| 武陟县| 齐河县| 石屏县| 淄博市|