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.

61 lines
2.6 KiB

  1. # -*- coding: utf-8 -*-
  2. from openerp import api
  3. from openerp.exceptions import AccessError
  4. from openerp.tests import common
  5. from lxml import etree
  6. class TestBaseTechnicalFeatures(common.TransactionCase):
  7. def test_01_visible_menus(self):
  8. """ A technical feature is visible to the user with the technical \
  9. features group """
  10. menu_obj = self.env['ir.ui.menu'].with_context(
  11. {'ir.ui.menu.full_list': True})
  12. menu_id = menu_obj.search(
  13. [('groups_id', '=', self.env.ref('base.group_no_one').id)],
  14. limit=1).id
  15. self.env.user.write({'technical_features': False})
  16. self.assertNotIn(menu_id, menu_obj._visible_menu_ids())
  17. self.env.user.write({'technical_features': True})
  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.write({'technical_features': False})
  31. self.assertEqual(get_partner_field_invisible(), '1')
  32. self.env.user.write({'technical_features': True})
  33. self.assertEqual(get_partner_field_invisible(), None)
  34. def test03_user_access(self):
  35. """ Setting the user pref raises an access error if the user is not \
  36. in group_no_one """
  37. user = self.env['res.users'].create({
  38. 'name': 'Test user technical features',
  39. 'login': 'testusertechnicalfeatures',
  40. 'groups_id': [(6, 0, [])]})
  41. with api.Environment.manage():
  42. env = api.Environment(
  43. self.env.cr, user.id, self.env.context)
  44. with self.assertRaises(AccessError):
  45. env['res.users'].browse(user.id).write(
  46. {'technical_features': True})
  47. with self.assertRaises(AccessError):
  48. user.write({'technical_features': True})
  49. user.write({'groups_id': [(4, self.env.ref('base.group_no_one').id)]})
  50. with api.Environment.manage():
  51. env = api.Environment(
  52. self.env.cr, user.id, self.env.context)
  53. env['res.users'].browse(user.id).write({
  54. 'technical_features': True})