From 0d9a6adcd9840f318b844c7451a8518e692ca11c Mon Sep 17 00:00:00 2001 From: phot0n Date: Wed, 11 May 2022 23:59:21 +0530 Subject: [PATCH] test: test for insert_many client function --- frappe/tests/test_client.py | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/frappe/tests/test_client.py b/frappe/tests/test_client.py index 677f59a366..b5a1771800 100644 --- a/frappe/tests/test_client.py +++ b/frappe/tests/test_client.py @@ -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)