test_copy_user_access.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # -*- coding: utf-8 -*-
  2. # © 2016 OpenSynergy Indonesia
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp.tests.common import TransactionCase
  5. from lxml import etree
  6. class TestCopyUserAccess(TransactionCase):
  7. def setUp(self, *args, **kwargs):
  8. super(TestCopyUserAccess, self).setUp(*args, **kwargs)
  9. # Objects
  10. self.obj_res_users = self.env['res.users']
  11. self.obj_wizard = self.env['base.copy_user_access']
  12. # Data
  13. self.demo_user = self.env.ref('base.user_demo')
  14. def _prepare_user_data(self):
  15. data = {
  16. 'login': 'test_user@test.com',
  17. 'name': 'test lagi',
  18. 'password': 'a'
  19. }
  20. return data
  21. def test_copy_user_access(self):
  22. # Create New User
  23. data = self._prepare_user_data()
  24. user = self.obj_res_users.create(data)
  25. # Check create new user
  26. self.assertIsNotNone(user)
  27. # Fill Context
  28. context = self.obj_res_users.context_get()
  29. ctx = context.copy()
  30. ctx.update({'active_ids': user.ids})
  31. # Create Wizard
  32. wizard = self.obj_wizard\
  33. .with_context(ctx).create({'user_id': self.demo_user.id})
  34. # Check fields_view_get
  35. view = wizard.fields_view_get()
  36. doc = etree.XML(view['arch'])
  37. for node in doc.xpath("//field[@name='user_id']"):
  38. domain = node.get('domain')
  39. test_domain = "[('id', 'not in', " + str(user.ids) + ")]"
  40. self.assertEquals(domain, test_domain)
  41. # Check group_ids(new_user) with group_ids(demo_user)
  42. wizard.with_context(ctx).copy_access_right()
  43. self.assertEquals(set(self.demo_user.groups_id.ids),
  44. set(user.groups_id.ids))