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.

60 lines
2.5 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.user.write({'technical_features': False})
  30. self.assertEqual(get_partner_field_invisible(), '1')
  31. self.env.user.write({'technical_features': True})
  32. self.assertEqual(get_partner_field_invisible(), None)
  33. def test03_user_access(self):
  34. """ Setting the user pref raises an access error if the user is not \
  35. in group_no_one """
  36. user = self.env['res.users'].create({
  37. 'name': 'Test user technical features',
  38. 'login': 'testusertechnicalfeatures',
  39. 'groups_id': [(6, 0, [])]})
  40. with api.Environment.manage():
  41. env = api.Environment(
  42. self.env.cr, user.id, self.env.context)
  43. with self.assertRaises(AccessError):
  44. env['res.users'].browse(user.id).write(
  45. {'technical_features': True})
  46. with self.assertRaises(AccessError):
  47. user.write({'technical_features': True})
  48. user.write({'groups_id': [(4, self.env.ref('base.group_no_one').id)]})
  49. with api.Environment.manage():
  50. env = api.Environment(
  51. self.env.cr, user.id, self.env.context)
  52. env['res.users'].browse(user.id).write({
  53. 'technical_features': True})