Browse Source

[IMP] base_location_geonames_import: Convert tests to Python + switch imported country

Monaco country is very little and it allows to save some downloaded bytes plus making
a test for entries deletion
pull/253/head
Pedro M. Baeza 9 years ago
parent
commit
c857f5fc3f
  1. 3
      base_location_geonames_import/__openerp__.py
  2. 58
      base_location_geonames_import/test/import.yml
  3. 4
      base_location_geonames_import/tests/__init__.py
  4. 45
      base_location_geonames_import/tests/test_base_location_geonames_import.py

3
base_location_geonames_import/__openerp__.py

@ -21,8 +21,5 @@
'data': [
'wizard/geonames_import_view.xml',
],
'test': [
'test/import.yml'
],
'installable': True,
}

58
base_location_geonames_import/test/import.yml

@ -1,58 +0,0 @@
-
I create the wizard
-
!record {model: better.zip.geonames.import, id: import_wizard_1, view: better_zip_geonames_import_form}:
country_id: base.it
-
I run the import
-
!python {model: better.zip.geonames.import}: |
ctx = context.copy()
ctx['max_import'] = 10
self.run_import(cr, uid, [ref('import_wizard_1')], context=ctx)
-
I check the data
-
!python {model: res.better.zip}: |
state_obj = self.pool['res.country.state']
state_ids = state_obj.search(cr, uid, [
('code', '=', 'AB'),
('country_id', '=', ref('base.it')),
], context=context)
assert len(state_ids) == 1, "There must be 1 LG"
zip_ids = self.search(cr, uid, [
('name', '=', '67010'),
('city', '=', 'Barete'),
('state_id', '=', state_ids[0]),
('country_id', '=', ref('base.it'))
], context=context)
assert len(zip_ids) == 1, "There must be 1 'Isola Del Cantone'"
-
I create the wizard again
-
!record {model: better.zip.geonames.import, id: import_wizard_2, view: better_zip_geonames_import_form}:
country_id: base.it
-
I run the import again
-
!python {model: better.zip.geonames.import}: |
ctx = context.copy()
ctx['max_import'] = 10
self.run_import(cr, uid, [ref('import_wizard_2')], context=ctx)
-
I check the data
-
!python {model: res.better.zip}: |
state_obj = self.pool['res.country.state']
state_ids = state_obj.search(cr, uid, [
('code', '=', 'AB'),
('country_id', '=', ref('base.it')),
], context=context)
assert len(state_ids) == 1, "There must be 1 LG"
zip_ids = self.search(cr, uid, [
('name', '=', '67010'),
('city', '=', 'Barete'),
('state_id', '=', state_ids[0]),
('country_id', '=', ref('base.it'))
], context=context)
assert len(zip_ids) == 1, "There must be 1 'Isola Del Cantone'"

4
base_location_geonames_import/tests/__init__.py

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_base_location_geonames_import

45
base_location_geonames_import/tests/test_base_location_geonames_import.py

@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
# © 2016 Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp.tests import common
class TestBaseLocationGeonamesImport(common.TransactionCase):
def setUp(self):
super(TestBaseLocationGeonamesImport, self).setUp()
self.country = self.env.ref('base.mc')
self.wizard = self.env['better.zip.geonames.import'].create({
'country_id': self.country.id,
})
def test_import_country(self):
self.wizard.with_context(max_import=10).run_import()
state_domain = [
('code', '=', '01'),
('country_id', '=', self.country.id)
]
states = self.env['res.country.state'].search(state_domain)
self.assertEqual(len(states), 1)
zip_domain = [
('name', '=', '98000'),
('city', '=', 'Ciappaira'),
('state_id', '=', states[0].id),
('country_id', '=', self.country.id),
]
zips = self.env['res.better.zip'].search(zip_domain)
self.assertEqual(len(zips), 1)
# 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)
def test_delete_old_entries(self):
zip_entry = self.env['res.better.zip'].create({
'city': 'Test city',
'country_id': self.country.id,
})
self.wizard.run_import()
self.assertFalse(zip_entry.exists())
Loading…
Cancel
Save