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"}))
class FrappeConnection(BaseConnection): def __init__(self, connector): self.connector = connector self.connection = FrappeClient(self.connector.hostname, self.connector.username, self.get_password()) self.name_field = 'name' def insert(self, doctype, doc): doc = frappe._dict(doc) doc.doctype = doctype return self.connection.insert(doc) def update(self, doctype, doc, migration_id): doc = frappe._dict(doc) doc.doctype = doctype doc.name = migration_id return self.connection.update(doc) def delete(self, doctype, migration_id): return self.connection.delete(doctype, migration_id) def get(self, doctype, fields='"*"', filters=None, start=0, page_length=20, parent=None): return self.connection.get_list(doctype, fields=fields, filters=filters, limit_start=start, limit_page_length=page_length, parent=parent)
def test_update_doc(self): server = FrappeClient(get_url(), "Administrator", "admin", verify=False) frappe.db.delete("Note", {"title": ("in", ("Sing", "sing"))}) frappe.db.commit() server.insert({"doctype":"Note", "public": True, "title": "Sing"}) doc = server.get_doc("Note", 'Sing') changed_title = "sing" doc["title"] = changed_title doc = server.update(doc) self.assertTrue(doc["title"] == changed_title)
def test_update_doc(self): server = FrappeClient(get_url(), "Administrator", "admin", verify=False) frappe.db.sql("delete from `tabNote` where title in ('Sing','sing')") frappe.db.commit() server.insert({"doctype":"Note", "public": True, "title": "Sing"}) doc = server.get_doc("Note", 'Sing') changed_title = "sing" doc["title"] = changed_title doc = server.update(doc) self.assertTrue(doc["title"] == changed_title)
class FrappeConnection(BaseConnection): def __init__(self, connector): self.connector = connector self.connection = FrappeClient(self.connector.hostname, self.connector.username, self.get_password()) self.name_field = 'name' def insert(self, doctype, doc): doc = frappe._dict(doc) doc.doctype = doctype return self.connection.insert(doc) def update(self, doctype, doc, migration_id): doc = frappe._dict(doc) doc.doctype = doctype doc.name = migration_id return self.connection.update(doc) def delete(self, doctype, migration_id): return self.connection.delete(doctype, migration_id) def get(self, doctype, fields='"*"', filters=None, start=0, page_length=20): return self.connection.get_list(doctype, fields=fields, filters=filters, limit_start=start, limit_page_length=page_length)