From 8e6b57f55b4fdcc5a66565a4e44dfe3045dc30b1 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Sat, 12 Mar 2016 13:55:11 +0100 Subject: [PATCH] [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 --- base_location_geonames_import/__openerp__.py | 3 - base_location_geonames_import/test/import.yml | 58 ------------------- .../tests/__init__.py | 4 ++ .../test_base_location_geonames_import.py | 45 ++++++++++++++ 4 files changed, 49 insertions(+), 61 deletions(-) delete mode 100644 base_location_geonames_import/test/import.yml create mode 100644 base_location_geonames_import/tests/__init__.py create mode 100644 base_location_geonames_import/tests/test_base_location_geonames_import.py diff --git a/base_location_geonames_import/__openerp__.py b/base_location_geonames_import/__openerp__.py index e545a844e..f7a30a90e 100644 --- a/base_location_geonames_import/__openerp__.py +++ b/base_location_geonames_import/__openerp__.py @@ -21,8 +21,5 @@ 'data': [ 'wizard/geonames_import_view.xml', ], - 'test': [ - 'test/import.yml' - ], 'installable': True, } diff --git a/base_location_geonames_import/test/import.yml b/base_location_geonames_import/test/import.yml deleted file mode 100644 index 9dc93c2f0..000000000 --- a/base_location_geonames_import/test/import.yml +++ /dev/null @@ -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'" diff --git a/base_location_geonames_import/tests/__init__.py b/base_location_geonames_import/tests/__init__.py new file mode 100644 index 000000000..b16fdcb7f --- /dev/null +++ b/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 diff --git a/base_location_geonames_import/tests/test_base_location_geonames_import.py b/base_location_geonames_import/tests/test_base_location_geonames_import.py new file mode 100644 index 000000000..c5005c6b1 --- /dev/null +++ b/base_location_geonames_import/tests/test_base_location_geonames_import.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# © 2016 Pedro M. Baeza +# 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())