From a6f0550d4058387c23d5753c2cdd4589f0081412 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 12 Oct 2011 17:04:31 +0530 Subject: [PATCH] test cases for leave --- erpnext/sandbox/test_leave.py | 55 ++++++++++++++++++++++++++++++ erpnext/sandbox/testdata/leaves.py | 54 +++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 erpnext/sandbox/test_leave.py create mode 100644 erpnext/sandbox/testdata/leaves.py diff --git a/erpnext/sandbox/test_leave.py b/erpnext/sandbox/test_leave.py new file mode 100644 index 0000000000..cc2149f473 --- /dev/null +++ b/erpnext/sandbox/test_leave.py @@ -0,0 +1,55 @@ +import unittest + +import webnotes +import webnotes.profile +webnotes.user = webnotes.profile.Profile() + + +from webnotes.model.doc import Document +from webnotes.model.code import get_obj +from webnotes.utils import cstr, flt +from webnotes.model.doclist import getlist +sql = webnotes.conn.sql + +from sandbox.testdata import leaves +#---------------------------------------------------------- + + +class TestStockEntry(unittest.TestCase): + #=========================================================================== + def setUp(self): + webnotes.conn.begin() + leaves.emp.save(new = 1, make_autoname = 0) + + def test_leave_bal(self): + leaves.l_all.save(1) + leaves.l_app1.save(1) + leaves.l_app2.save(1) + + la1 = get_obj('Leave Application', leaves.l_app1.name, with_children=1) + la1.validate() + la1.doc.docstatus = 1 + la1.doc.save() + + self.assertTrue(la1.doc.total_leave_days == 2) + + la1.doc.half_day = 1 + la1.validate() + la1.doc.save() + + self.assertTrue(la1.doc.total_leave_days == .5) + + print "Test case for leave applied no of days" + + + la2 = get_obj('Leave Application', leaves.l_app2.name, with_children=1) + la2.validate() + bal = la2.get_leave_balance() + self.assertTrue(bal, 18) + print "Test case for leave balance" + + + + + def tearDown(self): + webnotes.conn.rollback() diff --git a/erpnext/sandbox/testdata/leaves.py b/erpnext/sandbox/testdata/leaves.py new file mode 100644 index 0000000000..8d44ffba78 --- /dev/null +++ b/erpnext/sandbox/testdata/leaves.py @@ -0,0 +1,54 @@ +from webnotes.model.doc import Document + +emp = Document( + fielddata = { + 'doctype': 'Employee', + 'name': 'emp1', + 'employee_name': 'Nijil', + 'status': 'Active', + 'date_of_joining': '2011-01-01' + } +) + + + +l_all = Document( + fielddata = { + 'doctype' : 'Leave Allocation', + 'name': 'l_all', + 'employee' : 'emp1', + 'leave_type' : 'Casual Leave', + 'posting_date': '2011-03-01', + 'fiscal_year': '2011-2012', + 'total_leaves_allocated': 20, + 'docstatus': 1 + } +) + +l_app1 = Document( + fielddata = { + 'doctype' : 'Leave Application', + 'name': 'l_app1', + 'employee' : 'emp1', + 'leave_type' : 'Casual Leave', + 'posting_date': '2011-03-01', + 'fiscal_year': '2011-2012', + 'from_date': '2011-08-01', + 'to_date': '2011-08-02', + 'total_leave_days': 2 + } +) + +l_app2 = Document( + fielddata = { + 'doctype' : 'Leave Application', + 'name': 'l_app2', + 'employee' : 'emp1', + 'leave_type' : 'Casual Leave', + 'posting_date': '2011-03-01', + 'fiscal_year': '2011-2012', + 'from_date': '2011-08-15', + 'to_date': '2011-08-17', + 'total_leave_days': 3 + } +)