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.

46 lines
1.8 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo.tests import common
  5. class TestBaseLocationGeonamesImport(common.TransactionCase):
  6. def setUp(self):
  7. super(TestBaseLocationGeonamesImport, self).setUp()
  8. self.country = self.env.ref('base.mc')
  9. self.wizard = self.env['better.zip.geonames.import'].create({
  10. 'country_id': self.country.id,
  11. })
  12. def test_import_country(self):
  13. max_import = 10
  14. self.wizard.with_context(max_import=max_import).run_import()
  15. # Look if there are imported states for the country
  16. state_count = self.env['res.country.state'].search_count([
  17. ('country_id', '=', self.country.id)
  18. ])
  19. self.assertTrue(state_count)
  20. # Look if the are imported zips
  21. zip_count = self.env['res.better.zip'].search_count([
  22. ('country_id', '=', self.country.id)
  23. ])
  24. self.assertEqual(zip_count, max_import)
  25. # Reimport again to see that there's no duplicates
  26. self.wizard.with_context(max_import=max_import).run_import()
  27. state_count2 = self.env['res.country.state'].search_count([
  28. ('country_id', '=', self.country.id)
  29. ])
  30. self.assertEqual(state_count, state_count2)
  31. zip_count = self.env['res.better.zip'].search_count([
  32. ('country_id', '=', self.country.id)
  33. ])
  34. self.assertEqual(zip_count, max_import)
  35. def test_delete_old_entries(self):
  36. zip_entry = self.env['res.better.zip'].create({
  37. 'city': 'Test city',
  38. 'country_id': self.country.id,
  39. })
  40. self.wizard.run_import()
  41. self.assertFalse(zip_entry.exists())