def test_create_email_with_valid_params_should_format_the_params_correctly(self): client = SignaturitClient('TOKEN') parser = Parser(client.CREATE_EMAIL_PARAMS, []) open(self.TEST_FILE_URL, 'a').close() email_params = {'subject': 'Certified email', 'body': 'Please, can you check this receipt? Just click the button!', 'recipients': [{'email': '*****@*****.**', 'fullname': 'Pau'}, {'email': '*****@*****.**', 'fullname': 'John'}], 'files': [self.TEST_FILE_URL]} expected_params = {'body': 'Please, can you check this receipt? Just click the button!', 'recipients[1][email]': '*****@*****.**', 'recipients[0][email]': '*****@*****.**', 'recipients[0][fullname]': 'Pau', 'recipients[1][fullname]': 'John', 'subject': 'Certified email'} parsed_data, files = parser.parse_data(email_params) self.assertEquals(expected_params, parsed_data) self.assertEquals(1, len(files)) os.unlink(self.TEST_FILE_URL)
def test_create_signature_with_valid_params_should_format_the_params_correctly(self): client = SignaturitClient('TOKEN') parser = Parser(client.CREATE_SIGN_PARAMS, []) open(self.TEST_FILE_URL, 'a').close() sign_params = {'subject': 'Receipt number 215', 'in_person_sign': 1, 'mandatory_photo': 1, 'sequential': 1, 'body': 'Please, can you sign this receipt? Just click the button!', 'mandatory_pages': [2, 5], 'recipients': [{'email': '*****@*****.**', 'fullname': 'Pau'}, {'email': '*****@*****.**', 'fullname': 'John'}], 'files': [self.TEST_FILE_URL]} expected_params = {'body': 'Please, can you sign this receipt? Just click the button!', 'mandatory_pages[0]': '2', 'mandatory_photo': '1', 'recipients[1][fullname]': 'John', 'mandatory_pages[1]': '5', 'recipients[1][email]': '*****@*****.**', 'sequential': '1', 'recipients[0][email]': '*****@*****.**', 'recipients[0][fullname]': 'Pau', 'in_person_sign': '1', 'subject': 'Receipt number 215'} parsed_data, files = parser.parse_data(sign_params) self.assertEquals(expected_params, parsed_data) self.assertEquals(1, len(files)) os.unlink(self.TEST_FILE_URL)
def test_put_branding_should_return_file_but_no_params(self): client = SignaturitClient("TOKEN") parser = Parser(client.TOUCH_BRANDING_PARAMS, []) open(self.TEST_FILE_URL, "a").close() params = {"files": self.TEST_FILE_URL} params, files = parser.parse_data(params) self.assertEquals(1, len(files)) self.assertEquals(1, len(params)) os.unlink(self.TEST_FILE_URL)
def create_email(self, files, recipients, subject, body, params={}): """ Create a new certified email @files Files to send ex: ['/documents/internet_contract.pdf', ... ] @recipients A dictionary with the email and fullname of the person you want to sign. If you wanna send only to one person: - [{"email": "*****@*****.**", "fullname": "John"}] For multiple recipients, yo need to submit a list of dicts: - [{"email": "*****@*****.**", "fullname": "John"}, {"email":"*****@*****.**", "fullname": "Bob"}] @subject Email subject @body Email body @params """ parameters = {} parser = Parser() documents = {} parser.fill_array(documents, files, 'files') recipients = recipients if isinstance(recipients, list) else [recipients] index = 0 for recipient in recipients: parser.fill_array(parameters, recipient, 'recipients[%i]' % index) index += 1 parser.fill_array(parameters, params, '') parameters['subject'] = subject parameters['body'] = body connection = Connection(self.token) connection.set_url(self.production, self.EMAILS_URL) connection.add_params(parameters) connection.add_files(documents) return connection.post_request()
def create_SMS(self, files, recipients, body, params={}): """ Create a new certified sms @files Files to send ex: ['/documents/internet_contract.pdf', ... ] @recipients A dictionary with the phone and name of the person you want to sign. Phone must be always with prefix If you wanna send only to one person: - [{"phone": "34123456", "name": "John"}] For multiple recipients, yo need to submit a list of dicts: - [{"email": "34123456, "name": "John"}, {"email":"34654321", "name": "Bob"}] @body Email body @params """ parameters = {} parser = Parser() documents = {} parser.fill_array(documents, files, 'files') recipients = recipients if isinstance(recipients, list) else [recipients] index = 0 for recipient in recipients: parser.fill_array(parameters, recipient, 'recipients[%i]' % index) index += 1 parser.fill_array(parameters, params, '') parameters['body'] = body connection = Connection(self.token) connection.set_url(self.production, self.SMS_URL) connection.add_params(parameters) connection.add_files(documents) return connection.post_request()
def create_signature(self, files, recipients, params): """ Create a new Signature request. @files Files to send ex: ['/documents/internet_contract.pdf', ... ] @recipients A dictionary with the email and fullname of the person you want to sign. If you wanna send only to one person: - [{"email": "*****@*****.**", "fullname": "John"}] For multiple recipients, yo need to submit a list of dicts: - [{"email": "*****@*****.**", "fullname": "John"}, {"email":"*****@*****.**", "fullname": "Bob"}] @params: An array of params """ parameters = {} parser = Parser() recipients = recipients if isinstance(recipients, list) else [recipients] index = 0 for recipient in recipients: parser.fill_array(parameters, recipient, 'recipients[%i]' % index) index += 1 parser.fill_array(parameters, params, '') documents = {} files = files if isinstance(files, list) else [files] parser.fill_array(documents, files, 'files') connection = Connection(self.token) connection.set_url(self.production, self.SIGNS_URL) connection.add_params(parameters) connection.add_files(documents) return connection.post_request()