Browse Source

[FIX] base_location_geonames_import: Test logic changed

For avoiding constant problems with this test, as Monaco data changes a lot,
what we are testing now is the existence of the data, not the exact match of them.
pull/323/head
Pedro M. Baeza 8 years ago
parent
commit
7933351451
  1. 2
      base_location_geonames_import/__manifest__.py
  2. 39
      base_location_geonames_import/tests/test_base_location_geonames_import.py
  3. 2
      base_location_geonames_import/wizard/geonames_import.py

2
base_location_geonames_import/__manifest__.py

@ -6,7 +6,7 @@
{
'name': 'Base Location Geonames Import',
'version': '9.0.1.0.0',
'version': '9.0.1.0.1',
'category': 'Partner Management',
'license': 'AGPL-3',
'summary': 'Import better zip entries from Geonames',

39
base_location_geonames_import/tests/test_base_location_geonames_import.py

@ -14,27 +14,28 @@ class TestBaseLocationGeonamesImport(common.TransactionCase):
})
def test_import_country(self):
self.wizard.with_context(max_import=10).run_import()
state_domain = [
('code', '=', '01'),
max_import = 10
self.wizard.with_context(max_import=max_import).run_import()
# Look if there are imported states for the country
state_count = self.env['res.country.state'].search_count([
('country_id', '=', self.country.id)
]
states = self.env['res.country.state'].search(state_domain)
self.assertEqual(len(states), 1)
zip_domain = [
('name', '=', '98000'),
('city', '=', 'Jardin Exotique'),
('state_id', '=', states[0].id),
('country_id', '=', self.country.id),
]
zips = self.env['res.better.zip'].search(zip_domain)
self.assertEqual(len(zips), 1)
])
self.assertTrue(state_count)
# Look if the are imported zips
zip_count = self.env['res.better.zip'].search_count([
('country_id', '=', self.country.id)
])
self.assertEqual(zip_count, max_import)
# Reimport again to see that there's no duplicates
self.wizard.with_context(max_import=10).run_import()
states = self.env['res.country.state'].search(state_domain)
self.assertEqual(len(states), 1)
zips = self.env['res.better.zip'].search(zip_domain)
self.assertEqual(len(zips), 1)
self.wizard.with_context(max_import=max_import).run_import()
state_count2 = self.env['res.country.state'].search_count([
('country_id', '=', self.country.id)
])
self.assertEqual(state_count, state_count2)
zip_count = self.env['res.better.zip'].search_count([
('country_id', '=', self.country.id)
])
self.assertEqual(zip_count, max_import)
def test_delete_old_entries(self):
zip_entry = self.env['res.better.zip'].create({

2
base_location_geonames_import/wizard/geonames_import.py

@ -133,7 +133,7 @@ class BetterZipGeonamesImport(models.TransientModel):
zip_code = self.create_better_zip(row, self.country_id)
if zip_code in zips_to_delete:
zips_to_delete -= zip_code
if max_import and i == max_import:
if max_import and (i + 1) == max_import:
break
data_file.close()
if zips_to_delete and not max_import:

Loading…
Cancel
Save