From d2bb29692f39f61b8c101244f0e8b667cb501362 Mon Sep 17 00:00:00 2001 From: Marc Durepos Date: Mon, 17 Jul 2023 11:32:07 -0400 Subject: [PATCH] Refactored tests. --- bemade_fsm/tests/test_bemade_fsm_common.py | 3 +- bemade_fsm/tests/test_task_template.py | 71 +++++++--------------- 2 files changed, 23 insertions(+), 51 deletions(-) diff --git a/bemade_fsm/tests/test_bemade_fsm_common.py b/bemade_fsm/tests/test_bemade_fsm_common.py index 3887470..a9f7e12 100644 --- a/bemade_fsm/tests/test_bemade_fsm_common.py +++ b/bemade_fsm/tests/test_bemade_fsm_common.py @@ -125,7 +125,7 @@ class BemadeFSMBaseTest(TransactionCase): @classmethod def _generate_task_template(cls, parent=None, structure=None, names=None, planned_hours=1, - equipment=None): + equipment=None, customer=None): """ Generates a task template with the specified structure and naming. :param parent: The parent task template for the top-level task template being generated @@ -150,6 +150,7 @@ class BemadeFSMBaseTest(TransactionCase): 'parent': parent and parent.id or False, 'planned_hours': planned_hours, 'equipment_ids': [Command.set(equipment and [equipment.id] or [])], + 'customer': customer and customer.id or False, }) parent = template while structure: diff --git a/bemade_fsm/tests/test_task_template.py b/bemade_fsm/tests/test_task_template.py index f7e9cbe..abde9cc 100644 --- a/bemade_fsm/tests/test_task_template.py +++ b/bemade_fsm/tests/test_task_template.py @@ -5,79 +5,50 @@ from odoo import Command from psycopg2.errors import ForeignKeyViolation -@tagged("-at_install", "post_install") -class TestTaskTemplateCommon(BemadeFSMBaseTest): - - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.PLANNED_HOURS = 6 - hours_uom = cls.env['uom.uom'].search([('name', '=', 'Hour')]) or False - # Test product to use with the various tests - cls.task1 = cls.env['project.task.template'].create({ - 'name': 'Template 1', - }) - - cls.project = cls.env.ref('industry_fsm.fsm_project') - - cls.product_task_global_project = cls._generate_product(name='Test Product 1', task_template=cls.task1) - cls.project_template = cls._generate_fsm_project('Test Project Template') - cls.product_task_in_project = cls._generate_product(name='Test Product 2', project=cls.project_template, - service_tracking='task_in_project', task_template=cls.task1) - - # Set up a task template tree with 2 children and 1 grandchild - cls.parent_task = cls._generate_task_template(structure=[2, 1], - names=['Parent Template', 'Child Template', - 'Grandchild Template']) - cls.child_task_1 = cls.parent_task.subtasks[0] - cls.child_task_2 = cls.parent_task.subtasks[1] - cls.grandchild_task = cls.child_task_1.subtasks[0] - - # Create products using the task tree we just created - cls.product_task_tree_global_project = cls._generate_product(name='Test Product 3', - task_template=cls.parent_task) - cls.product_task_tree_in_project = cls._generate_product(name="Test Product 2", project=cls.project_template, - service_tracking='task_in_project', - task_template=cls.parent_task) - - @tagged('-at_install', 'post_install') -class TestTaskTemplate(TestTaskTemplateCommon): +class TestTaskTemplate(BemadeFSMBaseTest): def test_delete_task_template(self): """User should never be able to delete a task template used on a product""" + task_template = self._generate_task_template(names=['Template 1']) + product = self._generate_product(name="Test Product 1", task_template=task_template) with self.assertRaises(ForeignKeyViolation): - self.task1.unlink() + task_template.unlink() def test_delete_subtask_template(self): """ Deletion of a child task should be OK even if the parent is on a product. Children of the deleted subtask should be deleted.""" - self.child_task_1.unlink() + parent_task = self._generate_task_template(structure=[2, 1], + names=['Parent Template', 'Child Template', + 'Grandchild Template']) + grandchild_task = parent_task.subtasks[0].subtasks[0] + + parent_task.subtasks[0].unlink() + # Reading deleted child's name field should be impossible with self.assertRaises(MissingError): - test = self.grandchild_task.name + test = grandchild_task.name def test_dissociating_customer_resets_equipment_appropriately(self): partner1 = self._generate_partner() partner2 = self._generate_partner() equipment1 = self._generate_equipment(partner=partner1) - form = Form(self.task1) - form.customer = partner1 - form.equipment_ids.add(equipment1) + task = self._generate_task_template(customer=partner1, equipment=equipment1) + form = Form(task) # Switching the partner should trigger on_change that makes sure equipments are linked to the new partner form.customer = partner2 + form.save() - self.assertFalse(equipment1 in self.task1.equipment_ids) + self.assertFalse(equipment1 in task.equipment_ids) @tagged('-at_install', 'post_install', 'slow') -class TestTaskTemplateTour(HttpCase, TestTaskTemplateCommon): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls._generate_project_manager_user('Mister PM', 'misterpm') +class TestTaskTemplateTour(HttpCase, BemadeFSMBaseTest): def test_task_template_tour(self): + user = self._generate_project_manager_user('Mister PM', 'misterpm') + task_template = self._generate_task_template(names=['Template 1']) + self._generate_product(name="Test Product 1", task_template=task_template) self.start_tour('/web', 'task_template_tour', - login='misterpm', ) + login=user.login, )