From 9e3b6883332ac26d6aca89c147e1cda233709960 Mon Sep 17 00:00:00 2001 From: Mangesh-Khairnar Date: Mon, 27 May 2019 03:10:39 +0530 Subject: [PATCH] test: create leave policy --- .../doctype/leave_policy/test_leave_policy.py | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/erpnext/hr/doctype/leave_policy/test_leave_policy.py b/erpnext/hr/doctype/leave_policy/test_leave_policy.py index 2c6f1d0a21..fc868ea15a 100644 --- a/erpnext/hr/doctype/leave_policy/test_leave_policy.py +++ b/erpnext/hr/doctype/leave_policy/test_leave_policy.py @@ -12,16 +12,20 @@ class TestLeavePolicy(unittest.TestCase): if random_leave_type: random_leave_type = random_leave_type[0] leave_type = frappe.get_doc("Leave Type", random_leave_type.name) - old_max_leaves_allowed = leave_type.max_leaves_allowed leave_type.max_leaves_allowed = 2 leave_type.save() - leave_policy_details = { - "doctype": "Leave Policy", - "leave_policy_details": [{ - "leave_type": leave_type.name, - "annual_allocation": leave_type.max_leaves_allowed + 1 - }] - } + leave_policy = create_leave_policy(leave_type=leave_type.name, annual_allocation=leave_type.max_leaves_allowed + 1) - self.assertRaises(frappe.ValidationError, frappe.get_doc(leave_policy_details).insert) + self.assertRaises(frappe.ValidationError, leave_policy.insert) + +def create_leave_policy(**args): + ''' Returns an object of leave policy ''' + args = frappe._dict(args) + return frappe.get_doc({ + "doctype": "Leave Policy", + "leave_policy_details": [{ + "leave_type": args.leave_type or "_Test Leave Type", + "annual_allocation": args.annual_allocation or 10 + }] + }) \ No newline at end of file