Browse Source

[MIG] Update test cases for testing (unlink role and role line) to new api

14.0
Duc Dao 7 years ago
committed by Jesús Alan Ramos Rodríguez
parent
commit
7b41c362d2
  1. 6
      base_user_role/README.rst
  2. 1
      base_user_role/data/ir_cron.xml
  3. 54
      base_user_role/tests/test_user_role.py

6
base_user_role/README.rst

@ -1,4 +1,4 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: https://www.gnu.org/licenses/agpl :target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3 :alt: License: AGPL-3
@ -49,7 +49,7 @@ Bug Tracker
=========== ===========
Bugs are tracked on `GitHub Issues Bugs are tracked on `GitHub Issues
<https://github.com/OCA/server-tools/issues>`_. In case of trouble, please
<https://github.com/OCA/server-backend/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first, check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback. help us smash it by providing detailed and welcomed feedback.
@ -67,6 +67,8 @@ Contributors
* Sébastien Alix <sebastien.alix@osiell.com> * Sébastien Alix <sebastien.alix@osiell.com>
* Duc, Dao Dong <duc.dd@komit-consulting.com> (https://komit-consulting.com) * Duc, Dao Dong <duc.dd@komit-consulting.com> (https://komit-consulting.com)
Do not contact contributors directly about support or help with technical issues.
Maintainer Maintainer
---------- ----------

1
base_user_role/data/ir_cron.xml

@ -13,7 +13,6 @@
<field name="model_id" ref="base_user_role.model_res_users_role"/> <field name="model_id" ref="base_user_role.model_res_users_role"/>
<field name="state">code</field> <field name="state">code</field>
<field name="code">model.cron_update_users()</field> <field name="code">model.cron_update_users()</field>
<field name="args">()</field>
</record> </record>
</odoo> </odoo>

54
base_user_role/tests/test_user_role.py

@ -95,50 +95,48 @@ class TestUserRole(TransactionCase):
def test_role_unlink(self): def test_role_unlink(self):
# Get role1 groups # Get role1 groups
role1 = self.role_model.browse(self.cr, self.uid, self.role1_id)
role1_group_ids = role1.implied_ids.ids
role1_group_ids.append(role1.group_id.id)
role1_group_ids = self.role1_id.implied_ids.ids
role1_group_ids.append(self.role1_id.group_id.id)
role1_group_ids = sorted(set(role1_group_ids)) role1_group_ids = sorted(set(role1_group_ids))
# Get role2
role2 = self.role_model.browse(self.cr, self.uid, self.role2_id)
# Configure the user with role1 and role2 # Configure the user with role1 and role2
self.user_model.write(
self.cr, self.uid, [self.user_id],
self.user_id.write(
{'role_line_ids': [ {'role_line_ids': [
(0, 0, {'role_id': self.role1_id}),
(0, 0, {'role_id': self.role2_id}),
(0, 0, {'role_id': self.role1_id.id}),
(0, 0, {'role_id': self.role2_id.id}),
]}) ]})
user = self.user_model.browse(self.cr, self.uid, self.user_id)
# Remove role2 # Remove role2
role2.unlink()
user_group_ids = sorted(set([group.id for group in user.groups_id]))
self.role2_id.unlink()
user_group_ids = sorted(set([
group.id for group in self.user_id.groups_id]))
self.assertEqual(user_group_ids, role1_group_ids) self.assertEqual(user_group_ids, role1_group_ids)
# Remove role1 # Remove role1
role1.unlink()
user_group_ids = sorted(set([group.id for group in user.groups_id]))
self.role1_id.unlink()
user_group_ids = sorted(set([
group.id for group in self.user_id.groups_id]))
self.assertEqual(user_group_ids, []) self.assertEqual(user_group_ids, [])
def test_role_line_unlink(self): def test_role_line_unlink(self):
# Get role1 groups # Get role1 groups
role1 = self.role_model.browse(self.cr, self.uid, self.role1_id)
role1_group_ids = role1.implied_ids.ids
role1_group_ids.append(role1.group_id.id)
role1_group_ids = self.role1_id.implied_ids.ids
role1_group_ids.append(self.role1_id.group_id.id)
role1_group_ids = sorted(set(role1_group_ids)) role1_group_ids = sorted(set(role1_group_ids))
# Configure the user with role1 and role2 # Configure the user with role1 and role2
self.user_model.write(
self.cr, self.uid, [self.user_id],
self.user_id.write(
{'role_line_ids': [ {'role_line_ids': [
(0, 0, {'role_id': self.role1_id}),
(0, 0, {'role_id': self.role2_id}),
(0, 0, {'role_id': self.role1_id.id}),
(0, 0, {'role_id': self.role2_id.id}),
]}) ]})
user = self.user_model.browse(self.cr, self.uid, self.user_id)
# Remove role2 from the user # Remove role2 from the user
user.role_line_ids.filtered(
lambda l: l.role_id.id == self.role2_id).unlink()
user_group_ids = sorted(set([group.id for group in user.groups_id]))
self.user_id.role_line_ids.filtered(
lambda l: l.role_id.id == self.role2_id.id).unlink()
user_group_ids = sorted(set([
group.id for group in self.user_id.groups_id]))
self.assertEqual(user_group_ids, role1_group_ids) self.assertEqual(user_group_ids, role1_group_ids)
# Remove role1 from the user # Remove role1 from the user
user.role_line_ids.filtered(
lambda l: l.role_id.id == self.role1_id).unlink()
user_group_ids = sorted(set([group.id for group in user.groups_id]))
self.user_id.role_line_ids.filtered(
lambda l: l.role_id.id == self.role1_id.id).unlink()
user_group_ids = sorted(set([
group.id for group in self.user_id.groups_id]))
self.assertEqual(user_group_ids, []) self.assertEqual(user_group_ids, [])
Loading…
Cancel
Save