test: shift assignment

This commit is contained in:
Anurag Mishra 2020-06-18 17:44:44 +05:30
parent dd46d19765
commit a6ec7e31d2

View File

@ -5,7 +5,7 @@ from __future__ import unicode_literals
import frappe import frappe
import unittest import unittest
from frappe.utils import nowdate from frappe.utils import nowdate, add_days
test_dependencies = ["Shift Type"] test_dependencies = ["Shift Type"]
@ -20,8 +20,61 @@ class TestShiftAssignment(unittest.TestCase):
"shift_type": "Day Shift", "shift_type": "Day Shift",
"company": "_Test Company", "company": "_Test Company",
"employee": "_T-Employee-00001", "employee": "_T-Employee-00001",
"date": nowdate() "start_date": nowdate()
}).insert() }).insert()
shift_assignment.submit() shift_assignment.submit()
self.assertEqual(shift_assignment.docstatus, 1) self.assertEqual(shift_assignment.docstatus, 1)
def test_overlapping_for_ongoing_shift(self):
# shift should be Ongoing if Only start_date is present and status = Active
shift_assignment_1 = frappe.get_doc({
"doctype": "Shift Assignment",
"shift_type": "Day Shift",
"company": "_Test Company",
"employee": "_T-Employee-00001",
"start_date": nowdate(),
"status": 'Active'
}).insert()
shift_assignment_1.submit()
self.assertEqual(shift_assignment_1.docstatus, 1)
shift_assignment = frappe.get_doc({
"doctype": "Shift Assignment",
"shift_type": "Day Shift",
"company": "_Test Company",
"employee": "_T-Employee-00001",
"start_date": add_days(nowdate(), 2)
})
self.assertRaises(frappe.ValidationError, shift_assignment.save)
def test_overlapping_for_fixed_period_shift(self):
# shift should is for Fixed period if Only start_date and end_date both are present and status = Active
shift_assignment_1 = frappe.get_doc({
"doctype": "Shift Assignment",
"shift_type": "Day Shift",
"company": "_Test Company",
"employee": "_T-Employee-00001",
"start_date": nowdate(),
"end_date": add_days(nowdate(), 30),
"status": 'Active'
}).insert()
shift_assignment_1.submit()
# it should not allowed within period of any shift.
shift_assignment_3 = frappe.get_doc({
"doctype": "Shift Assignment",
"shift_type": "Day Shift",
"company": "_Test Company",
"employee": "_T-Employee-00001",
"start_date":add_days(nowdate(), 10),
"end_date": add_days(nowdate(), 35),
"status": 'Active'
})
self.assertRaises(frappe.ValidationError, shift_assignment_3.save)