def test_insert_many(self): from frappe.frappeclient import FrappeClient frappe.db.sql( 'delete from `tabToDo` where description like "Test API%"') frappe.db.commit() server = FrappeClient(get_url(), "Administrator", "admin", verify=False) server.insert_many([ { "doctype": "ToDo", "description": "Test API 1" }, { "doctype": "ToDo", "description": "Test API 2" }, { "doctype": "ToDo", "description": "Test API 3" }, ]) self.assertTrue( frappe.db.get_value('ToDo', {'description': 'Test API 1'})) self.assertTrue( frappe.db.get_value('ToDo', {'description': 'Test API 2'})) self.assertTrue( frappe.db.get_value('ToDo', {'description': 'Test API 3'}))
def test_get_value(self): server = FrappeClient(get_url(), "Administrator", "admin", verify=False) frappe.db.sql("delete from `tabNote` where title = 'get_value'") frappe.db.commit() test_content = "test get value" server.insert_many([ { "doctype": "Note", "public": True, "title": "get_value", "content": test_content }, ]) self.assertEqual( server.get_value("Note", "content", { "title": "get_value" }).get('content'), test_content) name = server.get_value("Note", "name", { "title": "get_value" }).get('name') # test by name self.assertEqual( server.get_value("Note", "content", name).get('content'), test_content) self.assertRaises( FrappeException, server.get_value, "Note", "(select (password) from(__Auth) order by name desc limit 1)", {"title": "get_value"})
def test_insert_many(self): from frappe.frappeclient import FrappeClient frappe.db.sql('delete from `tabToDo` where description like "Test API%"') frappe.db.commit() host = get_url() if not host.startswith('http'): host = 'http://' + host if not host.endswith(':8000'): host = host + ':8000' server = FrappeClient(host, "Administrator", "admin", verify=False) server.insert_many([ {"doctype": "ToDo", "description": "Test API 1"}, {"doctype": "ToDo", "description": "Test API 2"}, {"doctype": "ToDo", "description": "Test API 3"}, ]) self.assertTrue(frappe.db.get_value('ToDo', {'description': 'Test API 1'})) self.assertTrue(frappe.db.get_value('ToDo', {'description': 'Test API 2'})) self.assertTrue(frappe.db.get_value('ToDo', {'description': 'Test API 3'}))
def test_insert_many(self): if os.environ.get('CI'): return from frappe.frappeclient import FrappeClient frappe.db.sql( "DELETE FROM `tabToDo` WHERE `description` LIKE 'Test API%'") frappe.db.commit() server = FrappeClient(get_url(), "Administrator", "admin", verify=False) server.insert_many([ { "doctype": "ToDo", "description": "Test API 1" }, { "doctype": "ToDo", "description": "Test API 2" }, { "doctype": "ToDo", "description": "Test API 3" }, ]) self.assertTrue( frappe.db.get_value('ToDo', {'description': 'Test API 1'})) self.assertTrue( frappe.db.get_value('ToDo', {'description': 'Test API 2'})) self.assertTrue( frappe.db.get_value('ToDo', {'description': 'Test API 3'}))
def test_update_child_doc(self): server = FrappeClient(get_url(), "Administrator", "admin", verify=False) frappe.db.sql( "delete from `tabContact` where first_name = 'George' and last_name = 'Steevens'" ) frappe.db.sql( "delete from `tabContact` where first_name = 'William' and last_name = 'Shakespeare'" ) frappe.db.sql( "delete from `tabCommunication` where reference_doctype = 'Event'") frappe.db.sql( "delete from `tabCommunication Link` where link_doctype = 'Contact'" ) frappe.db.sql( "delete from `tabEvent` where subject = 'Sing a song of sixpence'") frappe.db.sql( "delete from `tabEvent Participants` where reference_doctype = 'Contact'" ) frappe.db.commit() # create multiple contacts server.insert_many([{ "doctype": "Contact", "first_name": "George", "last_name": "Steevens" }, { "doctype": "Contact", "first_name": "William", "last_name": "Shakespeare" }]) # create an event with one of the created contacts event = server.insert({ "doctype": "Event", "subject": "Sing a song of sixpence", "event_participants": [{ "reference_doctype": "Contact", "reference_docname": "George Steevens" }] }) # update the event's contact to the second contact server.update({ "doctype": "Event Participants", "name": event.get("event_participants")[0].get("name"), "reference_docname": "William Shakespeare" }) # the change should run the parent document's validations and # create a Communication record with the new contact self.assertTrue( frappe.db.exists("Communication Link", {"link_name": "William Shakespeare"}))
def test_get_doc(self): server = FrappeClient(get_url(), "Administrator", "admin", verify=False) frappe.db.delete("Note", {"title": "get_this"}) frappe.db.commit() server.insert_many([ {"doctype": "Note", "public": True, "title": "get_this"}, ]) doc = server.get_doc("Note", "get_this") self.assertTrue(doc)
def test_delete_doc(self): server = FrappeClient(get_url(), "Administrator", "admin", verify=False) frappe.db.delete("Note", {"title": "delete"}) frappe.db.commit() server.insert_many([ {"doctype": "Note", "public": True, "title": "delete"}, ]) server.delete("Note", "delete") self.assertFalse(frappe.db.get_value('Note', {'title': 'delete'}))
def test_get_doc(self): server = FrappeClient(frappe.get_site_config().host_name, "Administrator", "admin", verify=False) frappe.db.sql('delete from `tabNote` where title = "get_this"') frappe.db.commit() server.insert_many([ { "doctype": "Note", "public": True, "title": "get_this" }, ]) doc = server.get_doc("Note", "get_this") self.assertTrue(doc)
def test_insert_many(self): from frappe.frappeclient import FrappeClient frappe.db.sql('delete from `tabToDo` where description like "Test API%"') frappe.db.commit() server = FrappeClient(get_url(), "Administrator", "admin", verify=False) server.insert_many([ {"doctype": "ToDo", "description": "Test API 1"}, {"doctype": "ToDo", "description": "Test API 2"}, {"doctype": "ToDo", "description": "Test API 3"}, ]) self.assertTrue(frappe.db.get_value('ToDo', {'description': 'Test API 1'})) self.assertTrue(frappe.db.get_value('ToDo', {'description': 'Test API 2'})) self.assertTrue(frappe.db.get_value('ToDo', {'description': 'Test API 3'}))
def test_insert_many(self): server = FrappeClient(get_url(), "Administrator", "admin", verify=False) frappe.db.delete("Note", {"title": ("in", ('Sing','a','song','of','sixpence'))}) frappe.db.commit() server.insert_many([ {"doctype": "Note", "public": True, "title": "Sing"}, {"doctype": "Note", "public": True, "title": "a"}, {"doctype": "Note", "public": True, "title": "song"}, {"doctype": "Note", "public": True, "title": "of"}, {"doctype": "Note", "public": True, "title": "sixpence"}, ]) self.assertTrue(frappe.db.get_value('Note', {'title': 'Sing'})) self.assertTrue(frappe.db.get_value('Note', {'title': 'a'})) self.assertTrue(frappe.db.get_value('Note', {'title': 'song'})) self.assertTrue(frappe.db.get_value('Note', {'title': 'of'})) self.assertTrue(frappe.db.get_value('Note', {'title': 'sixpence'}))
def test_delete_doc(self): server = FrappeClient(frappe.get_site_config().host_name, "Administrator", "admin", verify=False) frappe.db.sql('delete from `tabNote` where title = "delete"') frappe.db.commit() server.insert_many([ { "doctype": "Note", "public": True, "title": "delete" }, ]) server.delete("Note", "delete") self.assertFalse(frappe.db.get_value('Note', {'title': 'delete'}))
def test_insert_many(self): server = FrappeClient(get_url(), "Administrator", "admin", verify=False) frappe.db.sql( "delete from `tabNote` where title in ('Sing','a','song','of','sixpence')" ) frappe.db.commit() server.insert_many([ { "doctype": "Note", "public": True, "title": "Sing" }, { "doctype": "Note", "public": True, "title": "a" }, { "doctype": "Note", "public": True, "title": "song" }, { "doctype": "Note", "public": True, "title": "of" }, { "doctype": "Note", "public": True, "title": "sixpence" }, ]) self.assertTrue(frappe.db.get_value("Note", {"title": "Sing"})) self.assertTrue(frappe.db.get_value("Note", {"title": "a"})) self.assertTrue(frappe.db.get_value("Note", {"title": "song"})) self.assertTrue(frappe.db.get_value("Note", {"title": "of"})) self.assertTrue(frappe.db.get_value("Note", {"title": "sixpence"}))
def test_insert_many(self): server = FrappeClient(frappe.get_site_config().host_name, "Administrator", "admin", verify=False) frappe.db.sql( 'delete from `tabNote` where title in ("Sing","a","song","of","sixpence")' ) frappe.db.commit() server.insert_many([ { "doctype": "Note", "public": True, "title": "Sing" }, { "doctype": "Note", "public": True, "title": "a" }, { "doctype": "Note", "public": True, "title": "song" }, { "doctype": "Note", "public": True, "title": "of" }, { "doctype": "Note", "public": True, "title": "sixpence" }, ]) self.assertTrue(frappe.db.get_value('Note', {'title': 'Sing'})) self.assertTrue(frappe.db.get_value('Note', {'title': 'a'})) self.assertTrue(frappe.db.get_value('Note', {'title': 'song'})) self.assertTrue(frappe.db.get_value('Note', {'title': 'of'})) self.assertTrue(frappe.db.get_value('Note', {'title': 'sixpence'}))
def test_insert_many(self): from frappe.frappeclient import FrappeClient frappe.db.sql( 'delete from `tabToDo` where description like "Test API%"') frappe.db.commit() host = get_url() if not host.startswith('http'): host = 'http://' + host if not host.endswith(':8000'): host = host + ':8000' server = FrappeClient(host, "Administrator", "admin", verify=False) server.insert_many([ { "doctype": "ToDo", "description": "Test API 1" }, { "doctype": "ToDo", "description": "Test API 2" }, { "doctype": "ToDo", "description": "Test API 3" }, ]) self.assertTrue( frappe.db.get_value('ToDo', {'description': 'Test API 1'})) self.assertTrue( frappe.db.get_value('ToDo', {'description': 'Test API 2'})) self.assertTrue( frappe.db.get_value('ToDo', {'description': 'Test API 3'}))