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.

58 lines
2.7 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. import mock
  5. import openerp.tests.common as common
  6. from .common import TestWizardCommon
  7. class TestHelpOnline(TestWizardCommon, common.TransactionCase):
  8. def test_get_page_url(self):
  9. model = 'res.partner'
  10. help_online = self.env['help.online']
  11. user = self.env.user
  12. group_writer = self.env.ref('help_online.help_online_group_writer')
  13. group_reader = self.env.ref('help_online.help_online_group_reader')
  14. self.assertTrue(user.has_group('help_online.help_online_group_writer'))
  15. with mock.patch('openerp.addons.website.models.website'
  16. '.website.search_pages') as search_pages:
  17. # The expected page dosn't exist
  18. search_pages.return_value = []
  19. info = help_online.get_page_url(model, 'form')
  20. self.assertDictEqual(
  21. {'exists': False,
  22. 'title': 'Create Help page for Partner',
  23. 'url': 'website/add/help-res-partner'}, info,
  24. "If the user is member of help_online_group_writer "
  25. "and the page doesn't exist, the module should return an url "
  26. "to create the page")
  27. # remove user of group writer.
  28. group_writer.write({'users': [(3, self.env.user.id)]})
  29. info = help_online.get_page_url(model, 'form')
  30. self.assertDictEqual(
  31. {}, info,
  32. "If the user is not member of help_online_group_writer "
  33. "and the page doesn't exist, the module should return an "
  34. "empty dict")
  35. # The expected page exists
  36. search_pages.return_value = [{'loc': 'pages/help-res-partner'}]
  37. self.assertTrue(
  38. user.has_group('help_online.help_online_group_reader'))
  39. info = help_online.get_page_url(model, 'form')
  40. self.assertDictEqual(
  41. {'exists': True,
  42. 'title': 'Help on Partner',
  43. 'url': 'pages/help-res-partner#form'}, info,
  44. "If the user is member of help_online_group_reader "
  45. "and the page exists, the module should return an url "
  46. "to the page")
  47. # remove user from group reader
  48. group_reader.write({'users': [(3, self.env.user.id)]})
  49. info = help_online.get_page_url(model, 'form')
  50. self.assertDictEqual(
  51. {}, info,
  52. "If the user is not member of help_online_group_reader "
  53. "and the page exists, the module should return an empty dict")