From c1901dbf72347d56712a2a86d3e829c3fbcd25c9 Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Tue, 15 Aug 2023 15:17:15 +0200 Subject: [PATCH] test: assignment rule on_submit / cancel --- .../assignment_rule/test_assignment_rule.py | 51 ++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/frappe/automation/doctype/assignment_rule/test_assignment_rule.py b/frappe/automation/doctype/assignment_rule/test_assignment_rule.py index 2460c40e8a..aadd28fbea 100644 --- a/frappe/automation/doctype/assignment_rule/test_assignment_rule.py +++ b/frappe/automation/doctype/assignment_rule/test_assignment_rule.py @@ -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( {