From e357502fe9690397937939c91758ae9b4160be43 Mon Sep 17 00:00:00 2001 From: Kaynnan Bardauil Date: Tue, 21 Mar 2023 01:42:39 -0300 Subject: [PATCH] [IMP] maintenance_request_repair: add tests --- maintenance_request_repair/tests/__init__.py | 1 + .../tests/test_repair_order.py | 6 ++- .../tests/test_result_views.py | 41 +++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 maintenance_request_repair/tests/test_result_views.py diff --git a/maintenance_request_repair/tests/__init__.py b/maintenance_request_repair/tests/__init__.py index bf6f8ef58..403a75e16 100644 --- a/maintenance_request_repair/tests/__init__.py +++ b/maintenance_request_repair/tests/__init__.py @@ -1 +1,2 @@ from . import test_repair_order +from . import test_result_views diff --git a/maintenance_request_repair/tests/test_repair_order.py b/maintenance_request_repair/tests/test_repair_order.py index 67518c409..98226760d 100644 --- a/maintenance_request_repair/tests/test_repair_order.py +++ b/maintenance_request_repair/tests/test_repair_order.py @@ -48,7 +48,11 @@ def setUp(self): def test_compute_maintenance_request_count(self): self.repair_order._compute_maintenance_request_count() - assert self.repair_order.maintenance_request_count == 2 + self.assertEqual( + self.repair_order.maintenance_request_count, + len(self.repair_order.maintenance_request_ids), + "Computed maintenance request count is incorrect", + ) def test_action_view_maintenance_request(self): diff --git a/maintenance_request_repair/tests/test_result_views.py b/maintenance_request_repair/tests/test_result_views.py new file mode 100644 index 000000000..4cf186584 --- /dev/null +++ b/maintenance_request_repair/tests/test_result_views.py @@ -0,0 +1,41 @@ +# Copyright 2023 - TODAY, Kaynnan Lemes +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests import common + + +class TestResultViews(common.TransactionCase): + def test_existing_views(self): + result = {"views": [("state1", "view1"), ("state2", "form")]} + form_view = [("state3", "view3"), ("state4", "view4")] + expected_result = { + "views": form_view + + [("state1", "view1"), ("state3", "view3"), ("state4", "view4")] + } + + if "views" in result: + views_set = {view for state, view in result["views"]} + result["views"] = form_view + [ + (state, view) for state, view in result["views"] if view != "form" + ] + for state, view in form_view: + if view not in views_set: + result["views"].append((state, view)) + else: + result["views"] = form_view + + self.assertEqual(result, expected_result) + + def test_non_existing_views(self): + result = {} + form_view = [("state3", "view3"), ("state4", "view4")] + expected_result = {"views": form_view} + + if "views" in result: + result["views"] = form_view + [ + (state, view) for state, view in result["views"] if view != "form" + ] + else: + result["views"] = form_view + + self.assertEqual(result, expected_result)