def test_create_signature(self): open(self.TEST_FILE_URL, 'a').close() httpretty.register_uri( httpretty.POST, "https://api.sandbox.signaturit.com/v3/signatures.json", body='{' '"id": "SIGNATURE_ID", ' + '"recipients": [{"email": "*****@*****.**", "fullname": "Mr Test"}],' + '"subject": "Testing"' '}') signaturit_client = SignaturitClient('SOME_CLIENT') response = signaturit_client.create_signature( [self.TEST_FILE_URL], [{ "email": "*****@*****.**", "fullname": "Mr Test" }], {}) self.assertEqual('Testing', response['subject']) self.assertEqual('SIGNATURE_ID', response['id']) self.assertEqual([{ "email": "*****@*****.**", "fullname": "Mr Test" }], response['recipients']) os.unlink(self.TEST_FILE_URL)
def inbox(): from signaturit_sdk.signaturit_client import SignaturitClient # Get data from signaturit using special ID: response = SignaturitClient( frappe.db.sql("SELECT MIN(token) FROM `tabJohn Hancock Settings`;")[0] [0]).get_signatures() tabInbox_values = [] # frappe.errprint(response) for pos, data in enumerate(response): # If row doesn't exist then add it, else don't: if frappe.db.sql( "SELECT COUNT(1) FROM tabInbox WHERE name = '{}';".format( data["documents"][0]["id"]))[0][0] == 0: for x in ["id", "status", "email", "created_at", "file"]: # Values we want to look for in signaturit data for key in data["documents"][0]: if key == x: if x == "file": tabInbox_values.append( data["documents"][0][key]["name"]) else: tabInbox_values.append(data["documents"][0][key]) # Insert into frappe database for inbox doctype a new row frappe.errprint(tabInbox_values) frappe.db.sql( "INSERT INTO tabInbox (id, name, status, recipients, date, document_title) VALUES ({}, '{}', '{}', '{}', '{}', '{}');" .format(pos + 1, *tabInbox_values)) tabInbox_values = []
def test_send_signature_reminder(self): httpretty.register_uri( httpretty.POST, "https://api.sandbox.signaturit.com/v3/signatures/SIGNATURE_ID/reminder.json", body='{}', content_type="application/json") signaturit_client = SignaturitClient('SOME_TOKEN') signaturit_client.send_signature_reminder('SIGNATURE_ID')
def send(html, recipient, recipient_name, subject, body): from signaturit_sdk.signaturit_client import SignaturitClient file_path = [to_pdf(html)] recipients = [{"name": recipient_name, "email": recipient}] sign_params = {"subject": subject, "body": body} frappe.errprint( SignaturitClient( frappe.db.sql("SELECT MIN(token) FROM `tabJohn Hancock Settings`;") [0][0]).create_signature(file_path, recipients, sign_params))
def test_count_emails(self): httpretty.register_uri( httpretty.GET, "https://api.sandbox.signaturit.com/v3/emails/count.json", body='3', content_type="application/json") signaturit_client = SignaturitClient('SOME_TOKEN') response = signaturit_client.count_emails() self.assertEqual(3, response)
def inbox(*args): #====== download signatures ======# # Get data from signaturit using special ID: response = SignaturitClient("UtCJVghItkyqYAxwkgsQtsxrqzrndGBrcRnAvfppczXUmYhKZoEIgOTuPwWSFBaKELHLMsqjdVZIBqMsvGKHxD").get_signatures() tabInbox_values = [] for pos, data in enumerate(response): # If that row is not already there then add it else don't: if frappe.db.sql("SELECT COUNT(1) FROM tabInbox WHERE name = '{}';".format(data["documents"][0]["id"]))[0][0] == 0: for x in ["id", "status", "email", "created_at", "file"]: # Values we want to look for in signaturit data for key in data["documents"][0]: if key == x: if x == "file": tabInbox_values.append(data["documents"][0][key]["name"]) else: tabInbox_values.append(data["documents"][0][key]) # Insert into frappe database for inbox doctype a new row frappe.db.sql("INSERT INTO tabInbox (id, name, status, recipients, date, document_title) VALUES ({}, '{}', '{}', '{}', '{}', '{}');".format(pos+1, *tabInbox_values)) #frappe.errprint tabInbox_values = [] #tabInbox_values = ["tabInbox_name", "tabInbox_owner", "tabInbox_status", "tabInbox_recipients", "tabInbox_created_by", "tabInbox_date", "tabInbox_document_title"] #frappe.errprint('INSERT INTO tabInbox (name, owner, status, recipients, created_by, date, document_title) VALUES ({}, {}, {}, {}, {}, {}, {});'.format(*tabInbox_values)) #====== download signed pdf ======# # document = client.download_signed_document("590648a5-f442-11e6-868f-0680f0041fef", "5924a612-f442-11e6-868f-0680f0041fef") # file = open("document.pdf", 'w') # file.write(document) # file.close() #====== get signatures ======# # client = SignaturitClient(self.signaturit_client) # file_path = ["/Users/elliotschep/frappe-bench/apps/erpnext_plus_signaturit/erpnext_plus_signaturit/files/doc.pdf"] # recipients = [{ # "name": self.recipient_name, # "email": self.recipient # }] # # sign_params = { # "subject": self.subject, # "body": self.body # } # # response = client.create_signature(file_path, recipients, {'delivery_type': 'url'}) # # response = client.create_signature(file_path, recipients, sign_params) # response = [file_path[0], recipients[0], sign_params]
def test_get_emails(self): httpretty.register_uri( httpretty.GET, "https://api.sandbox.signaturit.com/v3/emails.json", body= '{"recipients": [{"email": "*****@*****.**", "fullname": "Mr Test"}],"subject": "Testing"}', content_type="application/json") signaturit_client = SignaturitClient('SOME_TOKEN') response = signaturit_client.get_emails() self.assertEqual('Testing', response['subject']) self.assertEqual([{ "email": "*****@*****.**", "fullname": "Mr Test" }], response['recipients'])
def test_cancel_signature(self): httpretty.register_uri( httpretty.PATCH, "http://api.sandbox.signaturit.com/v2/signs/SIGN_ID/cancel.json", body= '{"id": "SIGN_ID", "recipients": [{"email": "*****@*****.**", "fullname": "Mr Test"}], "subject": "Testing"}', content_type="application/json") signaturit_client = SignaturitClient('SOME_TOKEN') response = signaturit_client.cancel_signature('SIGN_ID') self.assertEqual('Testing', response['subject']) self.assertEqual([{ "email": "*****@*****.**", "fullname": "Mr Test" }], response['recipients'])
def get_email(self): httpretty.register_uri( httpretty.GET, "http://api.sandbox.signaturit.com/v2/email/EMAIL_ID.json", body='{"id": "SIGN_ID", ' + '"recipients": [{"email": "*****@*****.**", "fullname": "Mr Test"}], ' + '"subject": "Testing"}', content_type="application/json") signaturit_client = SignaturitClient('SOME_TOKEN') response = signaturit_client.get_email('SIGN_ID') self.assertEqual('Testing', response['subject']) self.assertEqual('SIGN_ID', response['id']) self.assertEqual([{ "email": "*****@*****.**", "fullname": "Mr Test" }], response['recipients'])
def test_create_email_with_invalid_params_should_raise_exception(self): client = SignaturitClient('TOKEN') self.assertRaises(Exception, client.create_email, {'testing': 'some_value'})
def validate(self): if "error" in SignaturitClient(self.token).count_signatures(): frappe.throw("Invalid OAuth token.")