From ab363b7af20fb55f7b629325b647090921a4fbd7 Mon Sep 17 00:00:00 2001 From: Jaime Arroyo Date: Fri, 10 Jan 2020 12:40:30 +0100 Subject: [PATCH] [11.0][IMP] Add tests --- web_widget_child_selector/models/base.py | 2 +- .../readme/CONTRIBUTORS.rst | 1 + web_widget_child_selector/tests/__init__.py | 1 + .../tests/test_widget_child_selector.py | 33 +++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 web_widget_child_selector/tests/__init__.py create mode 100644 web_widget_child_selector/tests/test_widget_child_selector.py diff --git a/web_widget_child_selector/models/base.py b/web_widget_child_selector/models/base.py index a3de9d439..128fc6ba9 100644 --- a/web_widget_child_selector/models/base.py +++ b/web_widget_child_selector/models/base.py @@ -8,7 +8,7 @@ class Base(models.AbstractModel): _inherit = 'base' def _get_record_parents(self, field): - if not self: + if not self or not hasattr(self, self._parent_name): return [] return getattr( self, self._parent_name diff --git a/web_widget_child_selector/readme/CONTRIBUTORS.rst b/web_widget_child_selector/readme/CONTRIBUTORS.rst index 93ec993e0..94e7b0a40 100644 --- a/web_widget_child_selector/readme/CONTRIBUTORS.rst +++ b/web_widget_child_selector/readme/CONTRIBUTORS.rst @@ -1 +1,2 @@ * Enric Tobella +* Jaime Arroyo diff --git a/web_widget_child_selector/tests/__init__.py b/web_widget_child_selector/tests/__init__.py new file mode 100644 index 000000000..36886fb64 --- /dev/null +++ b/web_widget_child_selector/tests/__init__.py @@ -0,0 +1 @@ +from . import test_widget_child_selector diff --git a/web_widget_child_selector/tests/test_widget_child_selector.py b/web_widget_child_selector/tests/test_widget_child_selector.py new file mode 100644 index 000000000..9c7ea320a --- /dev/null +++ b/web_widget_child_selector/tests/test_widget_child_selector.py @@ -0,0 +1,33 @@ +# Copyright 2019 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestWidgetChildSelector(TransactionCase): + + def setUp(self): + super().setUp() + self.partner_1 = self.env['res.partner'].create({'name': 'P1'}) + self.partner_2 = self.env['res.partner'].create({ + 'name': 'P2', + 'parent_id': self.partner_1.id + }) + self.partner_3 = self.env['res.partner'].create({ + 'name': 'P3', + 'parent_id': self.partner_2.id + }) + # Model that doesnt have the parent/child structure + self.group = self.env['res.groups'].create({ + 'name': 'Group' + }) + + def test_widget_child_selector(self): + res = self.partner_2.get_record_direct_childs_parents( + {'child_selection_field': 'name'} + ) + self.assertIn((self.partner_1.id, self.partner_1.name), res['parents']) + self.assertIn((self.partner_3.id, self.partner_3.name), res['childs']) + res = self.group.get_record_direct_childs_parents({}) + self.assertFalse(res['parents']) + self.assertFalse(res['childs'])