test: test for root deletion with/out allow_root_deletion
This commit is contained in:
parent
42fcf61cae
commit
9a897620fc
1 changed files with 19 additions and 0 deletions
|
|
@ -1,6 +1,8 @@
|
|||
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# License: MIT. See LICENSE
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
import frappe
|
||||
from frappe.core.doctype.doctype.test_doctype import new_doctype
|
||||
from frappe.query_builder import Field
|
||||
|
|
@ -238,3 +240,20 @@ class TestNestedSet(FrappeTestCase):
|
|||
def test_merge_group_into_leaf(self):
|
||||
with self.assertRaises(NestedSetInvalidMergeError):
|
||||
frappe.rename_doc("Test Tree DocType", "Parent 1", "Child 1", merge=True)
|
||||
|
||||
def test_root_deletion(self):
|
||||
for doc in ["Child 3", "Child 2", "Child 1", "Parent 2", "Parent 1"]:
|
||||
frappe.delete_doc("Test Tree DocType", doc)
|
||||
|
||||
root_node = frappe.get_doc("Test Tree DocType", "Root Node")
|
||||
|
||||
# root deletion with allow_root_deletion
|
||||
# patched as delete_doc create a new instance of Root Node (using get_doc)
|
||||
root_node.allow_root_deletion = False
|
||||
with patch("frappe.get_doc", return_value=root_node):
|
||||
with self.assertRaises(frappe.ValidationError):
|
||||
root_node.delete()
|
||||
|
||||
# root deletion without allow_root_deletion
|
||||
root_node.delete()
|
||||
self.assertFalse(frappe.db.exists("Test Tree DocType", "Root Node"))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue