test: fix holiday list creation causing flaky tests (#30260)
This commit is contained in:
parent
76187d175f
commit
f090e63e54
@ -3,7 +3,7 @@
|
||||
|
||||
import frappe
|
||||
from frappe.tests.utils import FrappeTestCase
|
||||
from frappe.utils import add_days, get_first_day, getdate, now_datetime, nowdate
|
||||
from frappe.utils import add_days, get_year_ending, get_year_start, getdate, now_datetime, nowdate
|
||||
|
||||
from erpnext.hr.doctype.attendance.attendance import (
|
||||
get_month_map,
|
||||
@ -16,6 +16,13 @@ from erpnext.hr.doctype.leave_application.test_leave_application import get_firs
|
||||
test_records = frappe.get_test_records('Attendance')
|
||||
|
||||
class TestAttendance(FrappeTestCase):
|
||||
def setUp(self):
|
||||
from erpnext.payroll.doctype.salary_slip.test_salary_slip import make_holiday_list
|
||||
|
||||
from_date = get_year_start(getdate())
|
||||
to_date = get_year_ending(getdate())
|
||||
self.holiday_list = make_holiday_list(from_date=from_date, to_date=to_date)
|
||||
|
||||
def test_mark_absent(self):
|
||||
employee = make_employee("test_mark_absent@example.com")
|
||||
date = nowdate()
|
||||
@ -31,12 +38,9 @@ class TestAttendance(FrappeTestCase):
|
||||
|
||||
employee = make_employee('test_unmarked_days@example.com', date_of_joining=add_days(first_day, -1))
|
||||
frappe.db.delete('Attendance', {'employee': employee})
|
||||
frappe.db.set_value('Employee', employee, 'holiday_list', self.holiday_list)
|
||||
|
||||
from erpnext.payroll.doctype.salary_slip.test_salary_slip import make_holiday_list
|
||||
holiday_list = make_holiday_list()
|
||||
frappe.db.set_value('Employee', employee, 'holiday_list', holiday_list)
|
||||
|
||||
first_sunday = get_first_sunday(holiday_list, for_date=first_day)
|
||||
first_sunday = get_first_sunday(self.holiday_list, for_date=first_day)
|
||||
mark_attendance(employee, first_day, 'Present')
|
||||
month_name = get_month_name(first_day)
|
||||
|
||||
@ -58,11 +62,9 @@ class TestAttendance(FrappeTestCase):
|
||||
employee = make_employee('test_unmarked_days@example.com', date_of_joining=add_days(first_day, -1))
|
||||
frappe.db.delete('Attendance', {'employee': employee})
|
||||
|
||||
from erpnext.payroll.doctype.salary_slip.test_salary_slip import make_holiday_list
|
||||
holiday_list = make_holiday_list()
|
||||
frappe.db.set_value('Employee', employee, 'holiday_list', holiday_list)
|
||||
frappe.db.set_value('Employee', employee, 'holiday_list', self.holiday_list)
|
||||
|
||||
first_sunday = get_first_sunday(holiday_list, for_date=first_day)
|
||||
first_sunday = get_first_sunday(self.holiday_list, for_date=first_day)
|
||||
mark_attendance(employee, first_day, 'Present')
|
||||
month_name = get_month_name(first_day)
|
||||
|
||||
@ -87,9 +89,7 @@ class TestAttendance(FrappeTestCase):
|
||||
relieving_date=relieving_date)
|
||||
frappe.db.delete('Attendance', {'employee': employee})
|
||||
|
||||
from erpnext.payroll.doctype.salary_slip.test_salary_slip import make_holiday_list
|
||||
holiday_list = make_holiday_list()
|
||||
frappe.db.set_value('Employee', employee, 'holiday_list', holiday_list)
|
||||
frappe.db.set_value('Employee', employee, 'holiday_list', self.holiday_list)
|
||||
|
||||
attendance_date = add_days(first_day, 2)
|
||||
mark_attendance(employee, attendance_date, 'Present')
|
||||
|
@ -82,7 +82,11 @@ class TestLeaveApplication(unittest.TestCase):
|
||||
set_leave_approver()
|
||||
|
||||
frappe.db.delete("Attendance", {"employee": "_T-Employee-00001"})
|
||||
self.holiday_list = make_holiday_list()
|
||||
frappe.db.set_value("Employee", "_T-Employee-00001", "holiday_list", "")
|
||||
|
||||
from_date = get_year_start(getdate())
|
||||
to_date = get_year_ending(getdate())
|
||||
self.holiday_list = make_holiday_list(from_date=from_date, to_date=to_date)
|
||||
|
||||
if not frappe.db.exists("Leave Type", "_Test Leave Type"):
|
||||
frappe.get_doc(dict(
|
||||
@ -316,6 +320,7 @@ class TestLeaveApplication(unittest.TestCase):
|
||||
|
||||
leave_application = make_leave_application(employee.name, first_sunday, add_days(first_sunday, 3), leave_type.name, employee.company)
|
||||
leave_application.reload()
|
||||
|
||||
# holiday should be excluded while marking attendance
|
||||
self.assertEqual(leave_application.total_leave_days, 3)
|
||||
self.assertEqual(frappe.db.count("Attendance", {"leave_application": leave_application.name}), 3)
|
||||
|
@ -7,6 +7,7 @@ import frappe
|
||||
|
||||
def execute():
|
||||
frappe.reload_doc('hr', 'doctype', 'leave_policy_assignment')
|
||||
frappe.reload_doc('hr', 'doctype', 'employee_grade')
|
||||
employee_with_assignment = []
|
||||
leave_policy = []
|
||||
|
||||
|
@ -411,7 +411,7 @@ class TestSalarySlip(unittest.TestCase):
|
||||
def test_email_salary_slip(self):
|
||||
frappe.db.sql("delete from `tabEmail Queue`")
|
||||
|
||||
make_employee("test_email_salary_slip@salary.com")
|
||||
make_employee("test_email_salary_slip@salary.com", company="_Test Company")
|
||||
ss = make_employee_salary_slip("test_email_salary_slip@salary.com", "Monthly", "Test Salary Slip Email")
|
||||
ss.company = "_Test Company"
|
||||
ss.save()
|
||||
@ -1091,18 +1091,19 @@ def setup_test():
|
||||
def make_holiday_list(list_name=None, from_date=None, to_date=None):
|
||||
fiscal_year = get_fiscal_year(nowdate(), company=erpnext.get_default_company())
|
||||
name = list_name or "Salary Slip Test Holiday List"
|
||||
holiday_list = frappe.db.exists("Holiday List", name)
|
||||
if not holiday_list:
|
||||
holiday_list = frappe.get_doc({
|
||||
"doctype": "Holiday List",
|
||||
"holiday_list_name": name,
|
||||
"from_date": from_date or fiscal_year[1],
|
||||
"to_date": to_date or fiscal_year[2],
|
||||
"weekly_off": "Sunday"
|
||||
}).insert()
|
||||
holiday_list.get_weekly_off_dates()
|
||||
holiday_list.save()
|
||||
holiday_list = holiday_list.name
|
||||
|
||||
frappe.delete_doc_if_exists("Holiday List", name, force=True)
|
||||
|
||||
holiday_list = frappe.get_doc({
|
||||
"doctype": "Holiday List",
|
||||
"holiday_list_name": name,
|
||||
"from_date": from_date or fiscal_year[1],
|
||||
"to_date": to_date or fiscal_year[2],
|
||||
"weekly_off": "Sunday"
|
||||
}).insert()
|
||||
holiday_list.get_weekly_off_dates()
|
||||
holiday_list.save()
|
||||
holiday_list = holiday_list.name
|
||||
|
||||
return holiday_list
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user