Skip to content

Commit

Permalink
chore: fixed failing tests for self leave approval
Browse files Browse the repository at this point in the history
  • Loading branch information
asmitahase committed Dec 7, 2024
1 parent e0b69e9 commit c831870
Showing 1 changed file with 55 additions and 12 deletions.
67 changes: 55 additions & 12 deletions hrms/hr/doctype/leave_application/test_leave_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,42 +968,85 @@ def test_leave_approver_perms(self):
employee.save()

def test_self_leave_approval_allowed(self):
frappe.db.set_single_value("HR Settings", "allow_self_leave_approval", 1)

leave_approver = "test_leave_approver@example.com"
employee = get_employee()
make_employee(leave_approver, "_Test Company")

employee = get_employee()
if not employee.user_id:
employee.user_id = "test_employee@example.com"
employee.leave_approver = leave_approver
employee.user_id = "test_employee@example.com"
employee.save()

from frappe.utils.user import add_role

add_role(employee.user_id, "Leave Approver")

make_allocation_record(employee.name)
application = self.get_application(_test_records[0])
application = frappe.get_doc(
dict(
doctype="Leave Application",
employee=employee.name,
leave_type="_Test Leave Type",
from_date="2014-06-01",
to_date="2014-06-02",
posting_date="2014-05-30",
description="_Test Reason",
company="_Test Company",
leave_approver=leave_approver,
)
)
application.insert()
application.status = "Approved"

frappe.set_user("test_employee@example.com")
frappe.db.set_single_value("HR Settings", "allow_self_leave_approval", 1)
frappe.set_user(employee.user_id)
application.submit()

self.assertEqual(1, application.docstatus)

frappe.set_user("Administrator")

def test_self_leave_approval_not_allowed(self):
frappe.db.set_single_value("HR Settings", "allow_self_leave_approval", 0)

leave_approver = "test_leave_approver@example.com"
employee = get_employee()
make_employee(leave_approver, "_Test Company")

employee = get_employee()
employee.leave_approver = leave_approver
employee.user_id = "test_employee@example.com"
if not employee.user_id:
employee.user_id = "test_employee@example.com"
employee.save()

from frappe.utils.user import add_role

add_role(employee.user_id, "Leave Approver")

make_allocation_record(employee.name)
application = self.get_application(_test_records[0])
application = application = frappe.get_doc(
dict(
doctype="Leave Application",
employee=employee.name,
leave_type="_Test Leave Type",
from_date="2014-06-03",
to_date="2014-06-04",
posting_date="2014-05-30",
description="_Test Reason",
company="_Test Company",
leave_approver=leave_approver,
)
)
application.insert()
application.status = "Approved"

frappe.set_user("test_employee@example.com")
frappe.db.set_single_value("HR Settings", "allow_self_leave_approval", 0)
self.assertRaises(frappe.ValidationError, application.submit())
frappe.set_user(employee.user_id)
self.assertRaises(frappe.ValidationError, application.submit)

add_role(leave_approver, "Leave Approver")
frappe.set_user(leave_approver)
application.reload()
application.submit()

self.assertEqual(1, application.docstatus)

@set_holiday_list("Salary Slip Test Holiday List", "_Test Company")
Expand Down

0 comments on commit c831870

Please sign in to comment.