test: test for insert_many client function

This commit is contained in:
phot0n 2022-05-11 23:59:21 +05:30
parent b1a2007024
commit 0d9a6adcd9

View file

@ -178,3 +178,50 @@ class TestClient(unittest.TestCase):
# cleanup
frappe.delete_doc("Note", note1.name)
frappe.delete_doc("Note", note2.name)
def test_client_insert_many(self):
from frappe.client import insert, insert_many
def get_random_title():
return "test-{0}".format(frappe.generate_hash(length=5))
# insert a (parent) doc
note1 = {"doctype": "Note", "title": get_random_title(), "content": "test"}
note1 = insert(note1)
doc_list = [
{
"doctype": "Note Seen By",
"user": "Administrator",
"parenttype": "Note",
"parent": note1.name,
"parentfield": "seen_by",
},
{
"doctype": "Note Seen By",
"user": "Administrator",
"parenttype": "Note",
"parent": note1.name,
"parentfield": "seen_by",
},
{
"doctype": "Note Seen By",
"user": "Administrator",
"parenttype": "Note",
"parent": note1.name,
"parentfield": "seen_by",
},
{"doctype": "Note", "title": get_random_title(), "content": "test"},
{"doctype": "Note", "title": get_random_title(), "content": "test"},
]
# insert all docs
docs = insert_many(doc_list)
# make sure only 1 name is returned for the parent upon insertion of child docs
self.assertEqual(len(docs), 3)
self.assertIn(note1.name, docs)
# cleanup
for doc in docs:
frappe.delete_doc("Note", doc)