raise holiday block list exception only when submitting

This commit is contained in:
Anand Doshi
2013-02-13 20:26:45 +05:30
parent 798c6b4fdb
commit 9c35b2897c
3 changed files with 58 additions and 15 deletions

View File

@@ -7,7 +7,7 @@ test_records = [[{
"gender": "Female", "gender": "Female",
"status": "Active", "status": "Active",
"company": "_Test Company", "company": "_Test Company",
"user_id": "test@erpnext.com" "user_id": "test@example.com"
}], }],
[{ [{
"doctype":"Employee", "doctype":"Employee",
@@ -18,5 +18,17 @@ test_records = [[{
"gender": "Male", "gender": "Male",
"status": "Active", "status": "Active",
"company": "_Test Company", "company": "_Test Company",
"user_id": "test1@erpnext.com" "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"
}]
]

View File

@@ -15,6 +15,6 @@ test_records = [[{
"parent": "_Test Holiday Block List", "parent": "_Test Holiday Block List",
"parenttype": "Holiday Block List", "parenttype": "Holiday Block List",
"parentfield": "holiday_block_list_allowed", "parentfield": "holiday_block_list_allowed",
"allow_user": "test1@erpnext.com", "allow_user": "test1@example.com",
} }
]] ]]

View File

@@ -4,8 +4,8 @@ import unittest
from hr.doctype.leave_application.leave_application import LeaveDayBlockedError from hr.doctype.leave_application.leave_application import LeaveDayBlockedError
class TestLeaveApplication(unittest.TestCase): class TestLeaveApplication(unittest.TestCase):
def get_application(self): def get_application(self, doclist):
application = webnotes.model_wrapper(test_records[1]) application = webnotes.model_wrapper(doclist)
application.doc.from_date = "2013-01-01" application.doc.from_date = "2013-01-01"
application.doc.to_date = "2013-01-05" application.doc.to_date = "2013-01-05"
return application return application
@@ -15,25 +15,37 @@ class TestLeaveApplication(unittest.TestCase):
webnotes.conn.set_value("Employee", "_T-Employee-0001", "department", webnotes.conn.set_value("Employee", "_T-Employee-0001", "department",
"_Test Department with Block List") "_Test Department with Block List")
application = self.get_application() application = self.get_application(test_records[1])
self.assertRaises(LeaveDayBlockedError, application.insert) 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 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()) self.assertTrue(application.insert())
def test_global_block_list(self): 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", webnotes.conn.set_value("Holiday Block List", "_Test Holiday Block List",
"applies_to_all_departments", 1) "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") "_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 = [ test_records = [
[{ [{
@@ -53,4 +65,23 @@ test_records = [
"fiscal_year": "_Test Fiscal Year 2013", "fiscal_year": "_Test Fiscal Year 2013",
"employee": "_T-Employee-0001", "employee": "_T-Employee-0001",
"company": "_Test Company" "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"
}]
]