diff options
| author | Yannick Tivisse <yti@odoo.com> | 2019-11-04 16:34:54 +0100 |
|---|---|---|
| committer | Yannick Tivisse <yti@odoo.com> | 2019-11-05 13:08:03 +0100 |
| commit | b1689d7c7e4576b5deda0b13f8014d9e80d2e80d (patch) | |
| tree | 2cfad0b05cc7c238018867ec051d7b95eb3082ef /addons | |
| parent | 886cc7600af0bd8108eeb412e054bb58169bbfe0 (diff) | |
[IMP] hr_holidays: Adapt tests to work with/without demo data
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/hr_holidays/tests/common.py | 1 | ||||
| -rw-r--r-- | addons/hr_holidays/tests/test_automatic_leave_dates.py | 4 | ||||
| -rw-r--r-- | addons/hr_holidays/tests/test_holidays_flow.py | 52 | ||||
| -rw-r--r-- | addons/hr_holidays/tests/test_out_of_office.py | 3 |
4 files changed, 53 insertions, 7 deletions
diff --git a/addons/hr_holidays/tests/common.py b/addons/hr_holidays/tests/common.py index 7fed7fa4b33..018e4971be7 100644 --- a/addons/hr_holidays/tests/common.py +++ b/addons/hr_holidays/tests/common.py @@ -9,6 +9,7 @@ class TestHrHolidaysBase(common.TransactionCase): def setUp(self): super(TestHrHolidaysBase, self).setUp() + self.env.user.tz = 'Europe/Brussels' # Test users to use through the various tests self.user_hruser = mail_new_test_user(self.env, login='armande', groups='base.group_user,hr_holidays.group_hr_holidays_user') diff --git a/addons/hr_holidays/tests/test_automatic_leave_dates.py b/addons/hr_holidays/tests/test_automatic_leave_dates.py index a709be09f9a..cacb1975b7d 100644 --- a/addons/hr_holidays/tests/test_automatic_leave_dates.py +++ b/addons/hr_holidays/tests/test_automatic_leave_dates.py @@ -154,6 +154,7 @@ class TestAutomaticLeaveDates(TestHrHolidaysBase): self.assertEqual(leave_form.number_of_hours_display, 8) def test_attendance_next_day(self): + self.env.user.tz = 'Europe/Brussels' calendar = self.env['resource.calendar'].create({ 'name': 'auto next day', 'attendance_ids': [(5, 0, 0), @@ -183,6 +184,7 @@ class TestAutomaticLeaveDates(TestHrHolidaysBase): self.assertEqual(leave_form.date_to, datetime(2019, 9, 2, 10, 0, 0)) def test_attendance_previous_day(self): + self.env.user.tz = 'Europe/Brussels' calendar = self.env['resource.calendar'].create({ 'name': 'auto next day', 'attendance_ids': [(5, 0, 0), @@ -212,6 +214,7 @@ class TestAutomaticLeaveDates(TestHrHolidaysBase): self.assertEqual(leave_form.date_to, datetime(2019, 9, 3, 10, 0, 0)) def test_2weeks_calendar(self): + self.env.user.tz = 'Europe/Brussels' calendar = self.env['resource.calendar'].create({ 'name': 'auto next day', 'two_weeks_calendar': True, @@ -265,6 +268,7 @@ class TestAutomaticLeaveDates(TestHrHolidaysBase): self.assertEqual(leave_form.date_to, datetime(2019, 9, 9, 10, 0, 0)) def test_2weeks_calendar_next_week(self): + self.env.user.tz = 'Europe/Brussels' calendar = self.env['resource.calendar'].create({ 'name': 'auto next day', 'two_weeks_calendar': True, diff --git a/addons/hr_holidays/tests/test_holidays_flow.py b/addons/hr_holidays/tests/test_holidays_flow.py index 54e039cc6e7..2096e3998d4 100644 --- a/addons/hr_holidays/tests/test_holidays_flow.py +++ b/addons/hr_holidays/tests/test_holidays_flow.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. - +import time from datetime import datetime from dateutil.relativedelta import relativedelta from psycopg2 import IntegrityError @@ -84,6 +84,30 @@ class TestHolidaysFlow(TestHrHolidaysBase): Allocations = self.env['hr.leave.allocation'] HolidaysStatus = self.env['hr.leave.type'] + holiday_status_paid_time_off = self.env['hr.leave.type'].create({ + 'name': 'Paid Time Off', + 'allocation_type': 'fixed', + 'validation_type': 'both', + 'validity_start': time.strftime('%Y-%m-01'), + 'responsible_id': self.env.ref('base.user_admin').id, + }) + + self.env['hr.leave.allocation'].create([ + { + 'name': 'Paid Time off for David', + 'holiday_status_id': holiday_status_paid_time_off.id, + 'number_of_days': 20, + 'employee_id': self.employee_emp_id, + 'state': 'validate', + }, { + 'name': 'Paid Time off for David', + 'holiday_status_id': holiday_status_paid_time_off.id, + 'number_of_days': 20, + 'employee_id': self.ref('hr.employee_admin'), + 'state': 'validate', + } + ]) + def _check_holidays_status(holiday_status, ml, lt, rl, vrl): self.assertEqual(holiday_status.max_leaves, ml, 'hr_holidays: wrong type days computation') @@ -172,7 +196,7 @@ class TestHolidaysFlow(TestHrHolidaysBase): employee_id = self.ref('hr.employee_admin') # cl can be of maximum 20 days for employee_admin - hol3_status = self.env.ref('hr_holidays.holiday_status_cl').with_context(employee_id=employee_id) + hol3_status = holiday_status_paid_time_off.with_context(employee_id=employee_id) # I assign the dates in the holiday request for 1 day hol3 = Requests.create({ 'name': 'Sick Time Off', @@ -201,11 +225,11 @@ class TestHolidaysFlow(TestHrHolidaysBase): # Print the HR Holidays(Summary Employee) Report through the wizard ctx = { 'model': 'hr.employee', - 'active_ids': [self.ref('hr.employee_admin'), self.ref('hr.employee_qdp'), self.ref('hr.employee_al')] + 'active_ids': [self.ref('hr.employee_admin')] } data_dict = { 'date_from': datetime.today().strftime('%Y-%m-01'), - 'emp': [(6, 0, [self.ref('hr.employee_admin'), self.ref('hr.employee_qdp'), self.ref('hr.employee_al')])], + 'emp': [(6, 0, [self.ref('hr.employee_admin')])], 'holiday_type': 'Approved' } self.env.company.external_report_layout_id = self.env.ref('web.external_layout_standard').id @@ -216,9 +240,25 @@ class TestHolidaysFlow(TestHrHolidaysBase): # error message is triggered if the date_from is after # date_to. Coming from a bug due to the new ORM 13.0 + holiday_status_paid_time_off = self.env['hr.leave.type'].create({ + 'name': 'Paid Time Off', + 'allocation_type': 'fixed', + 'validation_type': 'both', + 'validity_start': time.strftime('%Y-%m-01'), + 'responsible_id': self.env.ref('base.user_admin').id, + }) + + self.env['hr.leave.allocation'].create({ + 'name': 'Paid Time off for David', + 'holiday_status_id': holiday_status_paid_time_off.id, + 'number_of_days': 20, + 'employee_id': self.ref('hr.employee_admin'), + 'state': 'validate', + }) + leave_vals = { 'name': 'Sick Time Off', - 'holiday_status_id': self.env.ref('hr_holidays.holiday_status_cl').id, + 'holiday_status_id': holiday_status_paid_time_off.id, 'date_from': datetime.today().strftime('%Y-%m-11 19:00:00'), 'date_to': datetime.today().strftime('%Y-%m-10 10:00:00'), 'employee_id': self.ref('hr.employee_admin'), @@ -231,7 +271,7 @@ class TestHolidaysFlow(TestHrHolidaysBase): leave_vals = { 'name': 'Sick Time Off', - 'holiday_status_id': self.env.ref('hr_holidays.holiday_status_cl').id, + 'holiday_status_id': holiday_status_paid_time_off.id, 'date_from': datetime.today().strftime('%Y-%m-10 10:00:00'), 'date_to': datetime.today().strftime('%Y-%m-11 19:00:00'), 'employee_id': self.ref('hr.employee_admin'), diff --git a/addons/hr_holidays/tests/test_out_of_office.py b/addons/hr_holidays/tests/test_out_of_office.py index b2d4d26fda4..86e3f95063c 100644 --- a/addons/hr_holidays/tests/test_out_of_office.py +++ b/addons/hr_holidays/tests/test_out_of_office.py @@ -4,6 +4,7 @@ from datetime import datetime from dateutil.relativedelta import relativedelta +from odoo.addons.base.tests.common import TransactionCaseWithUserDemo from odoo.tests.common import tagged, users, warmup, Form from odoo.addons.hr_holidays.tests.common import TestHrHolidaysBase @@ -54,7 +55,7 @@ class TestOutOfOffice(TestHrHolidaysBase): self.assertEqual(infos[0]['direct_partner'][0]['out_of_office_date_end'], leave_date_end) @tagged('out_of_office') -class TestOutOfOfficePerformance(TestHrHolidaysBase): +class TestOutOfOfficePerformance(TestHrHolidaysBase, TransactionCaseWithUserDemo): def setUp(self): super(TestOutOfOfficePerformance, self).setUp() |
