Skip to content

Commit

Permalink
[CHG] add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Nemry (ACSONE) committed Nov 4, 2015
1 parent 2c226f6 commit 5669a3a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
2 changes: 2 additions & 0 deletions mozaik_thesaurus/tests/__init__.py
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import test_thesaurus_terms_loader
55 changes: 55 additions & 0 deletions 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 (<http://acsone.eu>)
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################

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')
9 changes: 5 additions & 4 deletions mozaik_thesaurus/wizard/thesaurus_terms_loader.py
Expand Up @@ -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))
Expand All @@ -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):
"""
Expand All @@ -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):
"""
Expand All @@ -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: [['', '', '']]
Expand Down Expand Up @@ -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):
"""
"""
Expand Down

0 comments on commit 5669a3a

Please sign in to comment.