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.

84 lines
3.4 KiB

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