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.

94 lines
3.3 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  4. from odoo.tests import common
  5. class TestBaseLocationGeonamesImport(common.SavepointCase):
  6. @classmethod
  7. def setUpClass(cls):
  8. super(TestBaseLocationGeonamesImport, cls).setUpClass()
  9. cls.country = cls.env.ref('base.mc')
  10. cls.country.enforce_cities = True
  11. cls.wizard = cls.env['better.zip.geonames.import'].create({
  12. 'country_id': cls.country.id,
  13. })
  14. def test_import_country(self):
  15. max_import = 10
  16. self.wizard.with_context(max_import=max_import).run_import()
  17. # Look if there are imported states for the country
  18. state_count = self.env['res.country.state'].search_count([
  19. ('country_id', '=', self.country.id)
  20. ])
  21. self.assertTrue(state_count)
  22. # Look if there are imported zips
  23. zip_count = self.env['res.better.zip'].search_count([
  24. ('country_id', '=', self.country.id)
  25. ])
  26. self.assertEqual(zip_count, max_import)
  27. # Look if there are imported cities
  28. city_count = self.env['res.city'].search_count([
  29. ('country_id', '=', self.country.id)
  30. ])
  31. self.assertTrue(city_count)
  32. # Reimport again to see that there's no duplicates
  33. self.wizard.with_context(max_import=max_import).run_import()
  34. state_count2 = self.env['res.country.state'].search_count([
  35. ('country_id', '=', self.country.id)
  36. ])
  37. self.assertEqual(state_count, state_count2)
  38. city_count2 = self.env['res.city'].search_count([
  39. ('country_id', '=', self.country.id)
  40. ])
  41. self.assertEqual(city_count, city_count2)
  42. zip_count = self.env['res.better.zip'].search_count([
  43. ('country_id', '=', self.country.id)
  44. ])
  45. self.assertEqual(zip_count, max_import)
  46. def test_delete_old_entries(self):
  47. zip_entry = self.env['res.better.zip'].create({
  48. 'city': 'Test city',
  49. 'country_id': self.country.id,
  50. })
  51. self.wizard.run_import()
  52. self.assertFalse(zip_entry.exists())
  53. city_entry = self.env['res.city'].create({
  54. 'name': 'Test city',
  55. 'country_id': self.country.id,
  56. })
  57. self.wizard.run_import()
  58. self.assertFalse(city_entry.exists())
  59. def test_import_title(self):
  60. self.wizard.letter_case = 'title'
  61. self.wizard.with_context(max_import=1).run_import()
  62. zip = self.env['res.better.zip'].search(
  63. [('country_id', '=', self.country.id)], limit=1
  64. )
  65. self.assertEqual(zip.city, zip.city.title())
  66. city = self.env['res.city'].search(
  67. [('country_id', '=', self.country.id)], limit=1
  68. )
  69. self.assertEqual(city.name, city.name.title())
  70. def test_import_upper(self):
  71. self.wizard.letter_case = 'upper'
  72. self.wizard.with_context(max_import=1).run_import()
  73. zip = self.env['res.better.zip'].search(
  74. [('country_id', '=', self.country.id)], limit=1
  75. )
  76. self.assertEqual(zip.city, zip.city.upper())
  77. city = self.env['res.city'].search(
  78. [('country_id', '=', self.country.id)], limit=1
  79. )
  80. self.assertEqual(city.name, city.name.upper())