From f5a1417b68455928dd7da6d51b8c7296ab6db44a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Todorovich?= Date: Mon, 18 Dec 2017 10:43:44 -0300 Subject: [PATCH] Add tests --- kpi/tests/__init__.py | 4 ++ kpi/tests/test_kpi.py | 87 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 kpi/tests/__init__.py create mode 100644 kpi/tests/test_kpi.py diff --git a/kpi/tests/__init__.py b/kpi/tests/__init__.py new file mode 100644 index 000000000..c9e401ab7 --- /dev/null +++ b/kpi/tests/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_kpi diff --git a/kpi/tests/test_kpi.py b/kpi/tests/test_kpi.py new file mode 100644 index 000000000..4ac3c0b1e --- /dev/null +++ b/kpi/tests/test_kpi.py @@ -0,0 +1,87 @@ +# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp.tests.common import TransactionCase + + +class TestKPI(TransactionCase): + + def setUp(self): + super(TestKPI, self).setUp() + + def test_invalid_threshold_range(self): + range1 = self.env['kpi.threshold.range'].create({ + 'name': 'Range1', + 'min_type': 'static', + 'max_type': 'static', + 'min_fixed_value': 3, + 'max_fixed_value': 1, + }) + range2 = self.env['kpi.threshold.range'].create({ + 'name': 'Range2', + 'min_type': 'static', + 'max_type': 'static', + 'min_fixed_value': 4, + 'max_fixed_value': 10, + }) + self.assertFalse(range1.valid) + self.assertTrue(range2.valid) + + def test_invalid_threshold(self): + range1 = self.env['kpi.threshold.range'].create({ + 'name': 'Range1', + 'min_type': 'static', + 'max_type': 'static', + 'min_fixed_value': 1, + 'max_fixed_value': 4, + }) + range2 = self.env['kpi.threshold.range'].create({ + 'name': 'Range2', + 'min_type': 'static', + 'max_type': 'static', + 'min_fixed_value': 4, + 'max_fixed_value': 10, + }) + range3 = self.env['kpi.threshold.range'].create({ + 'name': 'Range3', + 'min_type': 'static', + 'max_type': 'static', + 'min_fixed_value': 1, + 'max_fixed_value': 3, + }) + range_invalid = self.env['kpi.threshold.range'].create({ + 'name': 'RangeInvalid', + 'min_type': 'static', + 'max_type': 'static', + 'min_fixed_value': 3, + 'max_fixed_value': 1, + }) + + threshold1 = self.env['kpi.threshold'].create({ + 'name': 'Threshold1', + 'range_ids': [(6, 0, [range1.id, range2.id])], + }) + + threshold2 = self.env['kpi.threshold'].create({ + 'name': 'Threshold1', + 'range_ids': [(6, 0, [range3.id, range2.id])], + }) + + threshold3 = self.env['kpi.threshold'].create({ + 'name': 'Threshold1', + 'range_ids': [(6, 0, [range_invalid.id, range2.id])], + }) + + self.assertFalse(threshold1.valid) + self.assertTrue(threshold2.valid) + self.assertFalse(threshold3.valid) + + def test_invalid_threshold_range_exception(self): + range_error = self.env['kpi.threshold.range'].create({ + 'name': 'RangeError', + 'min_type': 'python', + 'min_code': '', + 'max_type': 'static', + 'max_fixed_value': 1, + }) + self.assertFalse(range_error.valid)