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.

101 lines
4.1 KiB

  1. # Copyright 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo.tests import common
  4. from odoo.exceptions import UserError
  5. from ..hooks import set_default_map_settings
  6. class TestPartnerExternalMap(common.TransactionCase):
  7. def setUp(self):
  8. super(TestPartnerExternalMap, self).setUp()
  9. self.user = self.env['res.users'].create({
  10. 'name': 'Test user',
  11. 'login': 'test_login',
  12. 'context_map_website_id': self.ref(
  13. 'partner_external_map.google_maps'),
  14. 'context_route_map_website_id': self.ref(
  15. 'partner_external_map.google_maps'),
  16. })
  17. self.user.partner_id.city = 'Tomelloso'
  18. self.partner = self.env['res.partner'].create({
  19. 'name': 'Test partner',
  20. 'city': 'Madrid',
  21. 'street': 'street_test',
  22. 'street2': 'street2_test',
  23. 'state_id': self.ref('base.state_es_m'),
  24. 'country_id': self.ref('base.es'),
  25. })
  26. def test_post_init_hook(self):
  27. # Call this again for coverage purposes, but it has been already run
  28. set_default_map_settings(self.cr, self.registry)
  29. usrs = self.env['res.users'].search([])
  30. self.assertTrue(all([u.context_map_website_id.id for u in usrs]))
  31. self.assertTrue(all([u.context_route_map_website_id.id for u in usrs]))
  32. self.assertEqual(self.env.user.partner_id,
  33. self.env.user.context_route_start_partner_id)
  34. def test_create_user(self):
  35. self.assertEqual(
  36. self.user.partner_id, self.user.context_route_start_partner_id)
  37. def test_open_map(self):
  38. action = self.partner.sudo(self.user.id).open_map()
  39. self.assertEqual(
  40. action['url'], "https://www.google.com/maps?ie=UTF8"
  41. "&q=street_test street2_test Madrid Madrid Spain")
  42. def test_open_route_map(self):
  43. action = self.partner.sudo(self.user.id).open_route_map()
  44. self.assertEqual(
  45. action['url'], "https://www.google.com/maps?saddr=Tomelloso"
  46. "&daddr=street_test street2_test Madrid Madrid "
  47. "Spain&directionsmode=driving")
  48. def test_open_map_with_coordinates(self):
  49. # Simulate that we have the base_geolocalize module installed creating
  50. # by hand the variables - This can't be done with routes
  51. partner = self.partner.sudo(self.user.id)
  52. partner.partner_latitude = 39.15837
  53. partner.partner_longitude = -3.02145
  54. action = partner.open_map()
  55. self.assertEqual(
  56. action['url'],
  57. "https://www.google.com/maps?z=15&q=39.15837,-3.02145")
  58. def test_exception_no_addr(self):
  59. self.partner.write({
  60. 'city': False,
  61. 'street': False,
  62. 'street2': False,
  63. 'state_id': False,
  64. 'country_id': False,
  65. })
  66. with self.assertRaises(UserError):
  67. self.partner.sudo(self.user.id).open_route_map()
  68. def test_exception_no_map_website(self):
  69. self.user.context_map_website_id = False
  70. with self.assertRaises(UserError):
  71. self.partner.sudo(self.user.id).open_map()
  72. def test_exception_no_map_route_website(self):
  73. self.user.context_route_start_partner_id = False
  74. with self.assertRaises(UserError):
  75. self.partner.sudo(self.user.id).open_route_map()
  76. def test_exception_no_starting_partner(self):
  77. self.user.context_route_map_website_id = False
  78. with self.assertRaises(UserError):
  79. self.partner.sudo(self.user.id).open_route_map()
  80. def test_exception_no_address_url(self):
  81. self.user.context_map_website_id.address_url = False
  82. with self.assertRaises(UserError):
  83. self.partner.sudo(self.user.id).open_map()
  84. def test_exception_no_route_address_url(self):
  85. self.user.context_map_website_id.route_address_url = False
  86. with self.assertRaises(UserError):
  87. self.partner.sudo(self.user.id).open_route_map()