|
| 1 | +import unittest |
| 2 | +try: |
| 3 | + from unittest import mock |
| 4 | +except ImportError: # Python 2 fallback. |
| 5 | + import mock |
| 6 | + |
| 7 | +from pydocusign import DocuSignClient, Signer |
| 8 | + |
| 9 | + |
| 10 | +class DocuSignTestClient(DocuSignClient): |
| 11 | + def login_information(self): |
| 12 | + self.account_id = 'test' |
| 13 | + self.account_url = '{root}/accounts/test'.format(root=self.root_url) |
| 14 | + |
| 15 | + |
| 16 | +class ClientRequestTest(unittest.TestCase): |
| 17 | + def test_create_envelope_recipients(self): |
| 18 | + client = DocuSignTestClient() |
| 19 | + |
| 20 | + with mock.patch.object(client, 'post') as post_mock: |
| 21 | + signers = [ |
| 22 | + Signer(clientUserId='userid_2', email='signer1@example.com', |
| 23 | + name='Signer 2'), |
| 24 | + Signer(clientUserId='userid_2', email='signer2@example.com', |
| 25 | + name='Signer 2'), |
| 26 | + ] |
| 27 | + client.add_envelope_recipients('ABC123', signers) |
| 28 | + |
| 29 | + url = '/accounts/{account_id}/envelopes/ABC123/recipients'.format( |
| 30 | + account_id=client.account_id) |
| 31 | + |
| 32 | + post_mock.assert_called_once_with( |
| 33 | + url, data={'signers': [signers[0].to_dict(), signers[1].to_dict()]} |
| 34 | + ) |
| 35 | + |
| 36 | + with mock.patch.object(client, 'post') as post_mock: |
| 37 | + client.add_envelope_recipients('ABC123', [], resend_envelope=True) |
| 38 | + |
| 39 | + post_mock.assert_called_once_with( |
| 40 | + '/accounts/{}/envelopes/ABC123/recipients' |
| 41 | + '?resend_envelope=true'.format(client.account_id), |
| 42 | + data={'signers': []} |
| 43 | + ) |
| 44 | + |
| 45 | + def test_update_envelope_recipients(self): |
| 46 | + client = DocuSignTestClient() |
| 47 | + |
| 48 | + with mock.patch.object(client, 'put') as put_mock: |
| 49 | + signers = [ |
| 50 | + Signer(clientUserId='userid_2', email='signer1@example.com', |
| 51 | + name='Signer 2'), |
| 52 | + Signer(clientUserId='userid_2', email='signer2@example.com', |
| 53 | + name='Signer 2'), |
| 54 | + ] |
| 55 | + client.update_envelope_recipients('ABC123', signers) |
| 56 | + |
| 57 | + url = '/accounts/{account_id}/envelopes/ABC123/recipients'.format( |
| 58 | + account_id=client.account_id) |
| 59 | + |
| 60 | + put_mock.assert_called_once_with( |
| 61 | + url, data={'signers': [signers[0].to_dict(), signers[1].to_dict()]} |
| 62 | + ) |
| 63 | + |
| 64 | + with mock.patch.object(client, 'put') as put_mock: |
| 65 | + client.update_envelope_recipients('ABC123', [], resend_envelope=True) |
| 66 | + |
| 67 | + put_mock.assert_called_once_with( |
| 68 | + '/accounts/{}/envelopes/ABC123/recipients' |
| 69 | + '?resend_envelope=true'.format(client.account_id), |
| 70 | + data={'signers': []} |
| 71 | + ) |
| 72 | + |
| 73 | + def test_delete_envelope_recipient(self): |
| 74 | + client = DocuSignTestClient() |
| 75 | + |
| 76 | + with mock.patch.object(client, 'delete') as delete_mock: |
| 77 | + client.delete_envelope_recipient('ABC123', '1') |
| 78 | + |
| 79 | + url = '/accounts/{account_id}/envelopes/ABC123/recipients/1'.format( |
| 80 | + account_id=client.account_id) |
| 81 | + |
| 82 | + delete_mock.assert_called_once_with(url) |
| 83 | + |
| 84 | + def test_delete_envelope_recipients(self): |
| 85 | + client = DocuSignTestClient() |
| 86 | + |
| 87 | + with mock.patch.object(client, 'delete') as delete_mock: |
| 88 | + client.delete_envelope_recipients('ABC123', ['1', '2']) |
| 89 | + |
| 90 | + url = '/accounts/{account_id}/envelopes/ABC123/recipients'.format( |
| 91 | + account_id=client.account_id) |
| 92 | + |
| 93 | + delete_mock.assert_called_once_with( |
| 94 | + url, data={'signers': [{'recipientId': '1'}, {'recipientId': '2'}]} |
| 95 | + ) |
0 commit comments