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.

59 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 odoo.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. website = self.env['website']
  16. with mock.patch.object(website.__class__,
  17. 'search_pages') as search_pages:
  18. # The expected page dosn't exist
  19. search_pages.return_value = []
  20. info = help_online.get_page_url(model, 'form')
  21. self.assertDictEqual(
  22. {'exists': False,
  23. 'title': 'Create Help page for Partner',
  24. 'url': 'website/add/help-res-partner'}, info,
  25. "If the user is member of help_online_group_writer "
  26. "and the page doesn't exist, the module should return an url "
  27. "to create the page")
  28. # remove user of group writer.
  29. group_writer.write({'users': [(3, self.env.user.id)]})
  30. info = help_online.get_page_url(model, 'form')
  31. self.assertDictEqual(
  32. {}, info,
  33. "If the user is not member of help_online_group_writer "
  34. "and the page doesn't exist, the module should return an "
  35. "empty dict")
  36. # The expected page exists
  37. search_pages.return_value = [{'loc': 'pages/help-res-partner'}]
  38. self.assertTrue(
  39. user.has_group('help_online.help_online_group_reader'))
  40. info = help_online.get_page_url(model, 'form')
  41. self.assertDictEqual(
  42. {'exists': True,
  43. 'title': 'Help on Partner',
  44. 'url': 'pages/help-res-partner#form'}, info,
  45. "If the user is member of help_online_group_reader "
  46. "and the page exists, the module should return an url "
  47. "to the page")
  48. # remove user from group reader
  49. group_reader.write({'users': [(3, self.env.user.id)]})
  50. info = help_online.get_page_url(model, 'form')
  51. self.assertDictEqual(
  52. {}, info,
  53. "If the user is not member of help_online_group_reader "
  54. "and the page exists, the module should return an empty dict")