Debian Codegraph @

addons/hr_timesheet/tests/test_project_task_quick_create.py

raw
1 # -*- coding: utf-8 -*-
2 # Part of Odoo. See LICENSE file for full copyright and licensing details.
3
4 from odoo.addons.hr_timesheet.tests.test_timesheet import TestCommonTimesheet
5 from odoo.tests import Form, tagged
6
7 @tagged('-at_install', 'post_install')
8 class TestProjectTaskQuickCreate(TestCommonTimesheet):
9 @classmethod
10 def setUpClass(cls):
11 super().setUpClass()
12 cls.project_customer.write({'allow_timesheets': True})
13
14 def test_create_task_with_valid_expressions(self):
15 # tuple format = (display name, [expected name, expected tags count, expected users count, expected priority, expected planned hours])
16 valid_expressions = {
17 'task A 30H 2.5h #tag1 @user_employee2 2H #tag2 @user_employee 5h !': ('task A', 2, 2, "1", 39.5),
18 'task A 30.H 2.h 1H #tag2 ! @user_employee ! @user_employee2 2.13h !': ('task A 30.H 2.h', 1, 2, "1", 3.13),
19 }
20
21 for expression, values in valid_expressions.items():
22 task_form = Form(self.env['project.task'].with_context({'tracking_disable': True, 'default_project_id': self.project_customer.id}), view="project.quick_create_task_form")
23 task_form.display_name = expression
24 task = task_form.save()
25 results = (task.name, len(task.tag_ids), len(task.user_ids), task.priority, task.allocated_hours)
26 self.assertEqual(results, values)
27
28 def test_create_task_with_invalid_expressions(self):
29 invalid_expressions = (
30 '30H #tag1 @raouf1 @raouf2 !',
31 '30h #tag1 @raouf1 @raouf2 !',
32 )
33
34 for expression in invalid_expressions:
35 task_form = Form(self.env['project.task'].with_context({'tracking_disable': True, 'default_project_id': self.project_customer.id}), view="project.quick_create_task_form")
36 task_form.display_name = expression
37 task = task_form.save()
38 results = (task.name, len(task.tag_ids), len(task.user_ids), task.priority, task.allocated_hours)
39 self.assertEqual(results, (expression, 0, 0, '0', 0))