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.

102 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.assertTrue(
  56. action["url"].startswith("https://www.google.com/maps?z="))
  57. self.assertIn("39.15837", action['url'])
  58. self.assertIn("-3.02145", action['url'])
  59. def test_exception_no_addr(self):
  60. self.partner.write({
  61. 'city': False,
  62. 'street': False,
  63. 'street2': False,
  64. 'state_id': False,
  65. 'country_id': False,
  66. })
  67. with self.assertRaises(UserError):
  68. self.partner.sudo(self.user.id).open_route_map()
  69. def test_exception_no_map_website(self):
  70. self.user.context_map_website_id = False
  71. with self.assertRaises(UserError):
  72. self.partner.sudo(self.user.id).open_map()
  73. def test_exception_no_map_route_website(self):
  74. self.user.context_route_start_partner_id = False
  75. with self.assertRaises(UserError):
  76. self.partner.sudo(self.user.id).open_route_map()
  77. def test_exception_no_starting_partner(self):
  78. self.user.context_route_map_website_id = False
  79. with self.assertRaises(UserError):
  80. self.partner.sudo(self.user.id).open_route_map()
  81. def test_exception_no_address_url(self):
  82. self.user.context_map_website_id.address_url = False
  83. with self.assertRaises(UserError):
  84. self.partner.sudo(self.user.id).open_map()
  85. def test_exception_no_route_address_url(self):
  86. self.user.context_map_website_id.route_address_url = False
  87. with self.assertRaises(UserError):
  88. self.partner.sudo(self.user.id).open_route_map()