From 9c35b2897cc2bcf8b65b9ee9850603255e6f7e5b Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Wed, 13 Feb 2013 20:26:45 +0530 Subject: [PATCH] raise holiday block list exception only when submitting --- hr/doctype/employee/test_employee.py | 18 +++++-- .../test_holiday_block_list.py | 2 +- .../test_leave_application.py | 53 +++++++++++++++---- 3 files changed, 58 insertions(+), 15 deletions(-) diff --git a/hr/doctype/employee/test_employee.py b/hr/doctype/employee/test_employee.py index a9c715b9d8..01c2087ec0 100644 --- a/hr/doctype/employee/test_employee.py +++ b/hr/doctype/employee/test_employee.py @@ -7,7 +7,7 @@ test_records = [[{ "gender": "Female", "status": "Active", "company": "_Test Company", - "user_id": "test@erpnext.com" + "user_id": "test@example.com" }], [{ "doctype":"Employee", @@ -18,5 +18,17 @@ test_records = [[{ "gender": "Male", "status": "Active", "company": "_Test Company", - "user_id": "test1@erpnext.com" -}]] \ No newline at end of file + "user_id": "test1@example.com" +}], +[{ + "doctype":"Employee", + "employee_name": "_Test Employee 2", + "naming_series": "_T-Employee-", + "date_of_joining": "2010-01-01", + "date_of_birth": "1980-01-01", + "gender": "Male", + "status": "Active", + "company": "_Test Company", + "user_id": "test2@example.com" +}] +] \ No newline at end of file diff --git a/hr/doctype/holiday_block_list/test_holiday_block_list.py b/hr/doctype/holiday_block_list/test_holiday_block_list.py index 5ec4dd1af5..e9f3b78472 100644 --- a/hr/doctype/holiday_block_list/test_holiday_block_list.py +++ b/hr/doctype/holiday_block_list/test_holiday_block_list.py @@ -15,6 +15,6 @@ test_records = [[{ "parent": "_Test Holiday Block List", "parenttype": "Holiday Block List", "parentfield": "holiday_block_list_allowed", - "allow_user": "test1@erpnext.com", + "allow_user": "test1@example.com", } ]] \ No newline at end of file diff --git a/hr/doctype/leave_application/test_leave_application.py b/hr/doctype/leave_application/test_leave_application.py index 8fe11d66cc..cd74d01399 100644 --- a/hr/doctype/leave_application/test_leave_application.py +++ b/hr/doctype/leave_application/test_leave_application.py @@ -4,8 +4,8 @@ import unittest from hr.doctype.leave_application.leave_application import LeaveDayBlockedError class TestLeaveApplication(unittest.TestCase): - def get_application(self): - application = webnotes.model_wrapper(test_records[1]) + def get_application(self, doclist): + application = webnotes.model_wrapper(doclist) application.doc.from_date = "2013-01-01" application.doc.to_date = "2013-01-05" return application @@ -15,25 +15,37 @@ class TestLeaveApplication(unittest.TestCase): webnotes.conn.set_value("Employee", "_T-Employee-0001", "department", "_Test Department with Block List") - application = self.get_application() - self.assertRaises(LeaveDayBlockedError, application.insert) + application = self.get_application(test_records[1]) + application.insert() + self.assertRaises(LeaveDayBlockedError, application.submit) - webnotes.session.user = "test1@erpnext.com" + webnotes.session.user = "test1@example.com" from webnotes.profile import add_role - add_role("test1@erpnext.com", "HR User") + add_role("test1@example.com", "HR User") + application = self.get_application(test_records[1]) self.assertTrue(application.insert()) def test_global_block_list(self): - application = self.get_application() + application = self.get_application(test_records[3]) + application.doc.leave_approver = "test@example.com" webnotes.conn.set_value("Holiday Block List", "_Test Holiday Block List", "applies_to_all_departments", 1) - webnotes.conn.set_value("Employee", "_T-Employee-0001", "department", + webnotes.conn.set_value("Employee", "_T-Employee-0002", "department", "_Test Department") - webnotes.session.user = "test@erpnext.com" + + webnotes.session.user = "test2@example.com" + from webnotes.profile import add_role + add_role("test2@example.com", "Employee") - self.assertRaises(LeaveDayBlockedError, application.insert) + application.insert() + + webnotes.session.user = "test@example.com" + from webnotes.profile import add_role + add_role("test@example.com", "Leave Approver") + + self.assertRaises(LeaveDayBlockedError, application.submit) test_records = [ [{ @@ -53,4 +65,23 @@ test_records = [ "fiscal_year": "_Test Fiscal Year 2013", "employee": "_T-Employee-0001", "company": "_Test Company" - }]] + }], + [{ + "doctype": "Leave Allocation", + "leave_type": "_Test Leave Type", + "fiscal_year": "_Test Fiscal Year 2013", + "employee":"_T-Employee-0002", + "new_leaves_allocated": 15, + "docstatus": 1 + }], + [{ + "doctype": "Leave Application", + "leave_type": "_Test Leave Type", + "from_date": "2013-05-01", + "to_date": "2013-05-05", + "posting_date": "2013-01-02", + "fiscal_year": "_Test Fiscal Year 2013", + "employee": "_T-Employee-0002", + "company": "_Test Company" + }] +]