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.

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