test: assignment rule on_submit / cancel

This commit is contained in:
barredterra 2023-08-15 15:17:15 +02:00
parent 88cbba5f21
commit c1901dbf72

View file

@ -274,6 +274,55 @@ class TestAutoAssign(FrappeTestCase):
assignment_rule.delete()
frappe.db.commit() # undo changes commited by DDL
def test_submittable_assignment(self):
# create a submittable doctype
submittable_doctype = "Assignment Test Submittable"
create_test_doctype(submittable_doctype)
dt = frappe.get_doc("DocType", submittable_doctype)
dt.is_submittable = 1
dt.save()
# create a rule for the submittable doctype
assignment_rule = frappe.new_doc("Assignment Rule")
assignment_rule.name = f"For {submittable_doctype}"
assignment_rule.document_type = submittable_doctype
assignment_rule.rule = "Round Robin"
assignment_rule.extend("assignment_days", self.days)
assignment_rule.append("users", {"user": "test@example.com"})
assignment_rule.assign_condition = "docstatus == 1"
assignment_rule.unassign_condition = "docstatus == 2"
assignment_rule.save()
# create a submittable doc
doc = frappe.new_doc(submittable_doctype)
doc.save()
doc.submit()
# check if todo is created
todos = frappe.get_all(
"ToDo",
filters={
"reference_type": submittable_doctype,
"reference_name": doc.name,
"status": "Open",
"allocated_to": "test@example.com",
},
)
self.assertEqual(len(todos), 1)
# check if todo is closed on cancel
doc.cancel()
todos = frappe.get_all(
"ToDo",
filters={
"reference_type": submittable_doctype,
"reference_name": doc.name,
"status": "Cancelled",
"allocated_to": "test@example.com",
},
)
self.assertEqual(len(todos), 1)
def clear_assignments():
frappe.db.delete("ToDo", {"reference_type": TEST_DOCTYPE})
@ -335,7 +384,7 @@ def _make_test_record(**kwargs):
def create_test_doctype(doctype: str):
"""Create custom doctype."""
frappe.db.delete("DocType", doctype)
frappe.delete_doc("DocType", doctype)
frappe.get_doc(
{