test: fix Shift Request test

- Use `get_value` instead of `get_doc`
- Remove unnecessary loop, only one shift assignment is made against a shift request
- Get value after cancel again. Get doc is not reliable since primary key changed after cancel
This commit is contained in:
marination 2021-08-11 13:29:44 +05:30
parent e5b0221693
commit bca30d6101
2 changed files with 24 additions and 11 deletions

View File

@ -19,6 +19,7 @@ class TestAttendanceRequest(unittest.TestCase):
frappe.db.rollback() frappe.db.rollback()
def test_on_duty_attendance_request(self): def test_on_duty_attendance_request(self):
"Test creation/updation of Attendace from Attendance Request, on duty."
today = nowdate() today = nowdate()
employee = get_employee() employee = get_employee()
attendance_request = frappe.new_doc("Attendance Request") attendance_request = frappe.new_doc("Attendance Request")
@ -58,6 +59,7 @@ class TestAttendanceRequest(unittest.TestCase):
self.assertEqual(attendance_docstatus, 2) self.assertEqual(attendance_docstatus, 2)
def test_work_from_home_attendance_request(self): def test_work_from_home_attendance_request(self):
"Test creation/updation of Attendace from Attendance Request, work from home."
today = nowdate() today = nowdate()
employee = get_employee() employee = get_employee()
attendance_request = frappe.new_doc("Attendance Request") attendance_request = frappe.new_doc("Attendance Request")

View File

@ -15,24 +15,35 @@ class TestShiftRequest(unittest.TestCase):
for doctype in ["Shift Request", "Shift Assignment"]: for doctype in ["Shift Request", "Shift Assignment"]:
frappe.db.sql("delete from `tab{doctype}`".format(doctype=doctype)) frappe.db.sql("delete from `tab{doctype}`".format(doctype=doctype))
def tearDown(self):
frappe.db.rollback()
def test_make_shift_request(self): def test_make_shift_request(self):
"Test creation/updation of Shift Assignment from Shift Request."
department = frappe.get_value("Employee", "_T-Employee-00001", 'department') department = frappe.get_value("Employee", "_T-Employee-00001", 'department')
set_shift_approver(department) set_shift_approver(department)
approver = frappe.db.sql("""select approver from `tabDepartment Approver` where parent= %s and parentfield = 'shift_request_approver'""", (department))[0][0] approver = frappe.db.sql("""select approver from `tabDepartment Approver` where parent= %s and parentfield = 'shift_request_approver'""", (department))[0][0]
shift_request = make_shift_request(approver) shift_request = make_shift_request(approver)
shift_assignments = frappe.db.sql(''' # Only one shift assignment is created against a shift request
SELECT shift_request, employee shift_assignment = frappe.db.get_value(
FROM `tabShift Assignment` "Shift Assignment",
WHERE shift_request = '{0}' filters={"shift_request": shift_request.name},
'''.format(shift_request.name), as_dict=1) fieldname=["employee", "docstatus"],
for d in shift_assignments: as_dict=True
employee = d.get('employee') )
self.assertEqual(shift_request.employee, employee) self.assertEqual(shift_request.employee, shift_assignment.employee)
self.assertEqual(shift_assignment.docstatus, 1)
shift_request.cancel() shift_request.cancel()
shift_assignment_doc = frappe.get_doc("Shift Assignment", {"shift_request": d.get('shift_request')})
self.assertEqual(shift_assignment_doc.docstatus, 2) shift_assignment_docstatus = frappe.db.get_value(
"Shift Assignment",
filters={"shift_request": shift_request.name},
fieldname="docstatus"
)
self.assertEqual(shift_assignment_docstatus, 2)
def test_shift_request_approver_perms(self): def test_shift_request_approver_perms(self):
employee = frappe.get_doc("Employee", "_T-Employee-00001") employee = frappe.get_doc("Employee", "_T-Employee-00001")