You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.8 KiB

9 years ago
  1. # -*- coding: utf-8 -*-
  2. from openerp.tests import common
  3. from lxml import etree
  4. class TestBaseTechnicalFeatures(common.TransactionCase):
  5. def test_01_visible_menus(self):
  6. """ A technical feature is visible to the user with the technical \
  7. features group """
  8. menu_obj = self.env['ir.ui.menu'].with_context(
  9. {'ir.ui.menu.full_list': True})
  10. menu_id = menu_obj.search(
  11. [('groups_id', '=', self.env.ref('base.group_no_one').id)],
  12. limit=1).id
  13. self.env.user.groups_id -= self.env.ref(
  14. 'base_technical_features.group_technical_features')
  15. self.assertNotIn(menu_id, menu_obj._visible_menu_ids())
  16. self.env.user.groups_id += self.env.ref(
  17. 'base_technical_features.group_technical_features')
  18. self.assertIn(menu_id, menu_obj._visible_menu_ids())
  19. def test02_visible_fields(self):
  20. """ A technical field is visible when its form is loaded by a user \
  21. with the technical features group """
  22. def get_partner_field_invisible():
  23. xml = etree.fromstring(
  24. self.env['res.users'].fields_view_get(
  25. view_id=self.env.ref('base.view_users_form').id
  26. )['arch'].encode('utf-8'))
  27. return xml.xpath(
  28. '//div/group/field[@name="partner_id"]')[0].get('invisible')
  29. self.env['basemodel.monkeypatch']._register_hook()
  30. self.env.user.groups_id -= self.env.ref(
  31. 'base_technical_features.group_technical_features')
  32. self.assertEqual(get_partner_field_invisible(), '1')
  33. self.env.user.write({'groups_id': [(4, self.env.ref(
  34. 'base_technical_features.group_technical_features').id)]})
  35. self.assertEqual(get_partner_field_invisible(), None)