From 5669a3a96b337f77bb98328ddfdb6da224a01668 Mon Sep 17 00:00:00 2001 From: "Jonathan Nemry (ACSONE)" Date: Wed, 4 Nov 2015 17:31:57 +0100 Subject: [PATCH] [CHG] add tests --- mozaik_thesaurus/tests/__init__.py | 2 + .../tests/test_thesaurus_terms_loader.py | 55 +++++++++++++++++++ .../wizard/thesaurus_terms_loader.py | 9 +-- 3 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 mozaik_thesaurus/tests/__init__.py create mode 100644 mozaik_thesaurus/tests/test_thesaurus_terms_loader.py diff --git a/mozaik_thesaurus/tests/__init__.py b/mozaik_thesaurus/tests/__init__.py new file mode 100644 index 000000000..933e8bade --- /dev/null +++ b/mozaik_thesaurus/tests/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import test_thesaurus_terms_loader diff --git a/mozaik_thesaurus/tests/test_thesaurus_terms_loader.py b/mozaik_thesaurus/tests/test_thesaurus_terms_loader.py new file mode 100644 index 000000000..375fa2bbe --- /dev/null +++ b/mozaik_thesaurus/tests/test_thesaurus_terms_loader.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This file is part of mozaik_coordinate, an Odoo module. +# +# Copyright (c) 2015 ACSONE SA/NV () +# +# mozaik_coordinate is free software: +# you can redistribute it and/or +# modify it under the terms of the GNU Affero General Public License +# as published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# mozaik_coordinate is distributed in the hope that it will +# be useful but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the +# GNU Affero General Public License +# along with mozaik_coordinate. +# If not, see . +# +############################################################################## + +from anybox.testing.openerp import SharedSetupTransactionCase + + +class TestThesaurusTermsLoader(SharedSetupTransactionCase): + + def setUp(self): + super(TestThesaurusTermsLoader, self).setUp() + self.thesaurus_terms_loader_model = self.env['thesaurus.terms.loader'] + self.thesaurus_term_model = self.env['thesaurus.term'] + self.thesaurus = self.env['thesaurus'] + + def test_cu_terms(self): + data_file = [ + ['100000000', 'Name1', 'other'], + ['100000001', 'Name2', 'other'], + ['100000002', 'Name3', 'other'], + ['100000003', 'Name4', 'other'], + ] + domain = [ + '|', '|', '|', + ('ext_identifier', '=', '100000000'), + ('ext_identifier', '=', '100000001'), + ('ext_identifier', '=', '100000002'), + ('ext_identifier', '=', '100000003'), + ] + t_ids = self.thesaurus_term_model.search(domain) + self.assertFalse(t_ids) + self.thesaurus_terms_loader_model.cu_terms(data_file) + t_ids = self.thesaurus_term_model.search(domain) + self.assertEqual(len(t_ids), 4, 'Should have 4 terms created') diff --git a/mozaik_thesaurus/wizard/thesaurus_terms_loader.py b/mozaik_thesaurus/wizard/thesaurus_terms_loader.py index bf8f6eb06..b681ff3e0 100644 --- a/mozaik_thesaurus/wizard/thesaurus_terms_loader.py +++ b/mozaik_thesaurus/wizard/thesaurus_terms_loader.py @@ -46,6 +46,7 @@ class FileTermsLoader(models.TransientModel): @api.multi def _get_tmp_file(self): + self.ensure_one() tmp = tempfile.NamedTemporaryFile( prefix='ImportTerms', suffix='.csv', delete=False) tmp.write(base64.decodestring(self.file_terms)) @@ -69,7 +70,7 @@ def _get_data(self): return datas - @api.one + @api.models def _update_terms( self, datas, to_update_identifiers, thesaurus_term_ids): """ @@ -93,7 +94,7 @@ def _update_terms( if data_name != t_term_id.name: t_term_id.name = data_name - @api.one + @api.models def _create_terms( self, datas, to_create_identifiers): """ @@ -109,7 +110,7 @@ def _create_terms( vals = dict(datas[identifier], state='confirm') self.env['thesaurus.term'].create(vals) - @api.one + @api.models def cu_terms(self, datas_file): """ :type datas_file: [['', '', '']] @@ -137,7 +138,7 @@ def cu_terms(self, datas_file): self._create_terms(identifier_datas, to_create_identifiers) _logger.info('New Terms Created') - @api.one + @api.models def set_relation_terms(self, datas_file): """ """