-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathunit_tests.py
More file actions
916 lines (743 loc) · 40.9 KB
/
unit_tests.py
File metadata and controls
916 lines (743 loc) · 40.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
# coding: utf-8
from __future__ import absolute_import, print_function
import base64
import os
import subprocess
import unittest
import tempfile
from time import sleep
from datetime import datetime
import docusign_esign as docusign
from docusign_esign import AuthenticationApi, EnvelopesApi, TemplatesApi, DiagnosticsApi, FoldersApi, ApiException, TemplateSummary
Username = os.environ.get("USER_NAME")
IntegratorKey = os.environ.get("INTEGRATOR_KEY_JWT")
BaseUrl = "https://demo.docusign.net/restapi"
OauthHostName = "account-d.docusign.com"
SignTest1File = "{}/docs/SignTest1.pdf".format(os.path.dirname(os.path.abspath(__file__)))
brandFile = "{}/docs/brand.xml".format(os.path.dirname(os.path.abspath(__file__)))
TemplateId = os.environ.get("TEMPLATE_ID")
UserId = os.environ.get("USER_ID")
BrandId = os.environ.get("BRAND_ID")
PrivateKeyBytes = base64.b64decode(os.environ.get("PRIVATE_KEY"))
class SdkUnitTests(unittest.TestCase):
def setUp(self):
self.api_client = docusign.ApiClient(base_path=BaseUrl, oauth_host_name=OauthHostName)
self.api_client.rest_client.pool_manager.clear()
docusign.configuration.api_client = self.api_client
try:
email_subject = 'Please Sign my Python SDK Envelope'
email_blurb = 'Hello, Please sign my Python SDK Envelope.'
template_id = TemplateId
role_name = 'Needs to sign'
name = 'Pat Developer'
email = Username
t_role = docusign.TemplateRole(role_name=role_name,
name=name,
email=email)
# send the envelope by setting |status| to "sent". To save as a draft set to "created"
status = 'sent'
# create an envelope definition
envelope_definition = docusign.EnvelopeDefinition(email_subject=email_subject,
email_blurb=email_blurb,
template_id=template_id,
template_roles=[t_role],
status=status)
envelopes_api = EnvelopesApi()
self.api_client.host = BaseUrl
token = (self.api_client.request_jwt_user_token(client_id=IntegratorKey,
user_id=UserId,
oauth_host_name=OauthHostName,
private_key_bytes=PrivateKeyBytes,
expires_in=3600))
self.user_info = self.api_client.get_user_info(token.access_token)
self.api_client.rest_client.pool_manager.clear()
docusign.configuration.api_client = self.api_client
envelope_summary = envelopes_api.create_envelope(self.user_info.accounts[0].account_id,
envelope_definition=envelope_definition)
self.api_client.rest_client.pool_manager.clear()
self.envelope_id = envelope_summary.envelope_id
except ApiException as e:
print("\nException when calling DocuSign API: %s" % e)
except Exception as e:
print("\nException when calling DocuSign API: %s" % e)
self.api_client.rest_client.pool_manager.clear()
def tearDown(self):
self.api_client.rest_client.pool_manager.clear()
def testLogin(self):
auth_api = AuthenticationApi()
try:
login_info = auth_api.login(api_password='true', include_account_id_guid='true')
assert login_info is not None
assert len(login_info.login_accounts) > 0
login_accounts = login_info.login_accounts
assert login_accounts[0].account_id is not None
# parse first account's baseUrl
base_url, _ = login_accounts[0].base_url.split('/v2')
# below code required for production, no effect in demo (same domain)
self.api_client.host = base_url
docusign.configuration.api_client = self.api_client
except ApiException as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
except Exception as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
def testTemplateGet(self):
try:
from docusign_esign import TemplatesApi
template_api = TemplatesApi(self.api_client)
template_obj = template_api.get(self.user_info.accounts[0].account_id, template_id=TemplateId).to_dict()
assert template_obj is not None
assert template_obj['uri'] is not None
except ApiException as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
except Exception as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
def testPutUpdateBrandResourceByContentType(self):
try:
from docusign_esign import AccountsApi
acc_api = AccountsApi(self.api_client)
acc_obj = acc_api.update_brand_resources_by_content_type(self.user_info.accounts[0].account_id, BrandId, "email", brandFile)
assert acc_obj is not None
assert acc_obj.resources_content_uri is not None
except ApiException as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
except Exception as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
def testRequestASignature(self):
with open(SignTest1File, 'rb') as sign_file:
file_contents = sign_file.read()
# Set properties and create an envelope later on
email_subject = 'Please Sign my Python SDK Envelope'
email_blurb = 'Hello, Please sign my Python SDK Envelope.'
# add a document to the envelope
doc = docusign.Document()
base64_doc = base64.b64encode(file_contents).decode("utf-8")
doc.document_base64 = base64_doc
doc.name = 'TestFile.pdf'
doc.document_id = '1'
documents = [doc]
# Create a SignHere tab somewhere on the document for the signer to sign
document_id = '1'
page_number = '1'
recipient_id = '1'
x_position = '100'
y_position = '100'
scale_value = '0.5'
sign_here = docusign.SignHere(document_id=document_id,
page_number=page_number,
recipient_id=recipient_id,
x_position=x_position,
y_position=y_position,
scale_value=scale_value)
sign_here_tabs = [sign_here]
tabs = docusign.Tabs(sign_here_tabs=sign_here_tabs)
# Add a recipient to sign the document
email = Username
name = 'Pat Developer'
recipient_id = '1'
signer = docusign.Signer(email=email,
name=name,
recipient_id=recipient_id,
tabs=tabs)
signers = [signer]
recipients = docusign.Recipients(signers=signers)
status = 'sent'
# create the envelope definition with the properties set
envelope_definition = docusign.EnvelopeDefinition(email_subject=email_subject,
email_blurb=email_blurb,
documents=documents,
recipients=recipients,
status=status)
envelopes_api = EnvelopesApi()
try:
envelope_summary = envelopes_api.create_envelope(self.user_info.accounts[0].account_id,
envelope_definition=envelope_definition)
assert envelope_summary is not None
assert envelope_summary.envelope_id is not None
assert envelope_summary.status == 'sent'
except ApiException as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
except Exception as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
def testRequestSignatureFromTemplate(self):
template_role_name = 'Needs to sign'
# Set properties and create an envelope later on
email_subject = 'Please Sign my Python SDK Envelope'
email_blurb = 'Hello, Please sign my Python SDK Envelope.'
# assign template information including ID and role(s)
template_id = TemplateId
# create a template role with a valid templateId and roleName and assign signer info
role_name = template_role_name
name = 'Pat Developer'
email = Username
t_role = docusign.TemplateRole(role_name=role_name,
name=name,
email=email)
# create a list of template roles and add our newly created role
# assign template role(s) to the envelope
template_roles = [t_role]
# send the envelope by setting |status| to "sent". To save as a draft set to "created"
status = 'sent'
# create the envelope definition with the properties set
envelope_definition = docusign.EnvelopeDefinition(email_subject=email_subject,
email_blurb=email_blurb,
template_id=template_id,
template_roles=template_roles,
status=status)
envelopes_api = EnvelopesApi()
try:
envelope_summary = envelopes_api.create_envelope(self.user_info.accounts[0].account_id,
envelope_definition=envelope_definition)
assert envelope_summary is not None
assert envelope_summary.envelope_id is not None
assert envelope_summary.status == 'sent'
except ApiException as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
except Exception as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
def testEmbeddedSigning(self):
with open(SignTest1File, 'rb') as sign_file:
file_contents = sign_file.read()
# Set properties and create an envelope later on
email_subject = 'Please Sign my Python SDK Envelope'
email_blurb = 'Hello, Please sign my Python SDK Envelope.'
# add a document to the envelope
base64_doc = base64.b64encode(file_contents).decode("utf-8")
name = 'TestFile.pdf'
document_id = '1'
doc = docusign.Document(document_base64=base64_doc,
name=name,
document_id=document_id)
documents = [doc]
# Add a recipient to sign the document
email = Username
name = 'Pat Developer'
recipient_id_for_doc = '1'
# this value represents the client's unique identifier for the signer
client_user_id = '2939'
# Create a SignHere tab somewhere on the document for the signer to sign
document_id = '1'
page_number = '1'
recipient_id = '1'
x_position = '100'
y_position = '100'
scale_value = '0.5'
# create sign here object with the properties
sign_here = docusign.SignHere(document_id=document_id,
page_number=page_number,
recipient_id=recipient_id,
x_position=x_position,
y_position=y_position,
scale_value=scale_value)
sign_here_tabs = [sign_here]
tabs = docusign.Tabs(sign_here_tabs=sign_here_tabs)
signer = docusign.Signer(email=email,
name=name,
recipient_id=recipient_id_for_doc,
client_user_id=client_user_id,
tabs=tabs)
signers = [signer]
recipients = docusign.Recipients(signers=signers)
status = 'sent'
# create the envelope definition with the properties set
envelope_definition = docusign.EnvelopeDefinition(email_subject=email_subject,
email_blurb=email_blurb,
documents=documents,
recipients=recipients,
status=status)
envelopes_api = EnvelopesApi()
try:
return_url = 'http://www.docusign.com/developer-center'
recipient_view_request = docusign.RecipientViewRequest()
recipient_view_request.return_url = return_url
recipient_view_request.client_user_id = client_user_id
recipient_view_request.authentication_method = 'email'
recipient_view_request.user_name = 'Pat Developer'
recipient_view_request.email = Username
envelope_summary = envelopes_api.create_envelope(self.user_info.accounts[0].account_id,
envelope_definition=envelope_definition)
envelope_id = envelope_summary.envelope_id
view_url = envelopes_api.create_recipient_view(self.user_info.accounts[0].account_id, envelope_id,
recipient_view_request=recipient_view_request)
# This Url should work in an Iframe or browser to allow signing
assert view_url is not None
assert view_url.url is not None
except ApiException as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
except Exception as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
def testCreateTemplate(self) -> TemplateSummary:
with open(SignTest1File, 'rb') as sign_file:
file_contents = sign_file.read()
# Set properties
email_subject = 'Please Sign my Python SDK Envelope (Embedded Signer)'
email_blurb = 'Hello, Please sign my Python SDK Envelope.'
# add a document to the template
base64_doc = base64.b64encode(file_contents).decode("utf-8")
name = 'TestFile.pdf'
document_id = '1'
doc = docusign.Document(document_base64=base64_doc,
name=name,
document_id=document_id)
documents = [doc]
# Add a recipient to sign the document
email = Username
name = 'Pat Developer'
recipient_id = '1'
# Create a SignHere tab somewhere on the document for the signer to sign
sign_document_id = '1'
sign_page_number = '1'
sign_recipient_id = '1'
sign_x_position = '100'
sign_y_position = '100'
sign_scale_value = '0.5'
sign_here = docusign.SignHere(document_id=sign_document_id,
page_number=sign_page_number,
recipient_id=sign_recipient_id,
x_position=sign_x_position,
y_position=sign_y_position,
scale_value=sign_scale_value)
sign_here_tabs = [sign_here]
# Create a date tab somewhere on the document for the signer to know about current date
date_document_id = '1'
date_page_number = '1'
date_x_position = '50'
date_y_position = '50'
current_date_tab = docusign.Date(document_id=date_document_id,
page_number=date_page_number,
recipient_id=recipient_id,
x_position=date_x_position,
y_position=date_y_position,
value=datetime.utcnow().date())
date_tabs = [current_date_tab]
tabs = docusign.Tabs(sign_here_tabs=sign_here_tabs, date_tabs=date_tabs)
signer = docusign.Signer(email=email,
name=name,
recipient_id=recipient_id,
tabs=tabs)
signers = [signer]
recipients = docusign.Recipients(signers=signers)
template_name = 'myTemplate'
# Create the Envelope template
envelope_template = docusign.EnvelopeTemplate(email_subject=email_subject,
email_blurb=email_blurb,
documents=documents,
recipients=recipients,
name=template_name)
templates_api = TemplatesApi()
try:
template_summary = templates_api.create_template(self.user_info.accounts[0].account_id,
envelope_template=envelope_template)
assert template_summary is not None
assert template_summary.template_id is not None
return template_summary
except ApiException as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
except Exception as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
def testDownLoadEnvelopeDocuments(self):
with open(SignTest1File, 'rb') as sign_file:
file_contents = sign_file.read()
# Set properties and create an envelope to be signed
email_subject = 'Please Sign my Python SDK Envelope'
email_blurb = 'Hello, Please sign my Python SDK Envelope.'
# add a document to the envelope
base64_doc = base64.b64encode(file_contents).decode("utf-8")
document_name = 'TestFile.pdf'
document_id = '1'
doc = docusign.Document(document_base64=base64_doc,
name=document_name,
document_id=document_id)
documents = [doc]
# this value represents the client's unique identifier for the signer
client_user_id = '2939'
# Create a Text tab somewhere on the document for the signer to sign
text_document_id = '1'
page_number = '1'
recipient_id = '1'
x_position = '100'
y_position = '100'
text = docusign.Text(document_id=text_document_id,
page_number=page_number,
recipient_id=recipient_id,
x_position=x_position,
y_position=y_position)
text_tabs = [text]
tabs = docusign.Tabs(text_tabs=text_tabs)
# Add a recipient to sign the document
email = Username
name = 'Pat Developer'
recipient_id = '1'
signer = docusign.Signer(email=email,
name=name,
recipient_id=recipient_id,
client_user_id=client_user_id,
tabs=tabs)
signers = [signer]
recipients = docusign.Recipients(signers=signers)
# send the envelope (otherwise it will be "created" in the Draft folder)
status = 'sent'
# create an envelope to be signed
envelope_definition = docusign.EnvelopeDefinition(email_subject=email_subject,
email_blurb=email_blurb,
documents=documents,
recipients=recipients,
status=status)
envelopes_api = EnvelopesApi()
try:
docusign.configuration.api_client = self.api_client
file1 = envelopes_api.get_document(self.user_info.accounts[0].account_id, 'combined', self.envelope_id)
temporary_file = tempfile.NamedTemporaryFile(delete=False)
with open(temporary_file.name + ".pdf", "wb") as f:
f.write(file1)
subprocess.call('open ' + temporary_file.name + ".pdf", shell=True)
except ApiException as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
except Exception as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
def testListDocuments(self):
auth_api = AuthenticationApi()
envelopes_api = EnvelopesApi()
try:
login_info = auth_api.login()
assert login_info is not None
assert len(login_info.login_accounts) > 0
login_accounts = login_info.login_accounts
assert login_accounts[0].account_id is not None
base_url, _ = login_accounts[0].base_url.split('/v2')
self.api_client.host = base_url
docusign.configuration.api_client = self.api_client
docs_list = envelopes_api.list_documents(login_accounts[0].account_id, self.envelope_id)
assert docs_list is not None
assert (docs_list.envelope_id == self.envelope_id)
except ApiException as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
except Exception as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
def testResendEnvelope(self):
with open(SignTest1File, 'rb') as sign_file:
file_contents = sign_file.read()
# Set properties and create an envelope to be signed later on
email_subject = 'Please Sign my Python SDK Envelope'
email_blurb = 'Hello, Please sign my Python SDK Envelope.'
# add a document to the envelope
base64_doc = base64.b64encode(file_contents).decode("utf-8")
name = 'TestFile.pdf'
document_id = '1'
doc = docusign.Document(document_base64=base64_doc,
name=name,
document_id=document_id)
documents = [doc]
# this value represents the client's unique identifier for the signer
client_user_id = '2939'
# Create a SignHere tab somewhere on the document for the signer to sign
document_id = '1'
page_number = '1'
recipient_id = '1'
x_position = '100'
y_position = '100'
scale_value = '0.5'
sign_here = docusign.SignHere(document_id=document_id,
page_number=page_number,
recipient_id=recipient_id,
x_position=x_position,
y_position=y_position,
scale_value=scale_value)
sign_here_tabs = [sign_here]
tabs = docusign.Tabs(sign_here_tabs=sign_here_tabs)
# Add a recipient to sign the document
email = Username
name = 'Pat Developer'
signer_recipient_id = '1'
# Create the signer with the information created previous
signer = docusign.Signer(tabs=tabs,
email=email,
name=name,
recipient_id=signer_recipient_id,
client_user_id=client_user_id)
signers = [signer]
recipients = docusign.Recipients(signers=signers)
# send the envelope (otherwise it will be "created" in the Draft folder)
status = 'sent'
# create an envelope to be signed
envelope_definition = docusign.EnvelopeDefinition(email_subject=email_subject,
email_blurb=email_blurb,
documents=documents,
recipients=recipients,
status=status)
envelopes_api = EnvelopesApi()
try:
docusign.configuration.api_client = self.api_client
recipients_update_summary = envelopes_api.update_recipients(self.user_info.accounts[0].account_id,
self.envelope_id, recipients=recipients,
resend_envelope='true')
assert recipients_update_summary is not None
assert len(recipients_update_summary.recipient_update_results) > 0
assert ( None == recipients_update_summary.recipient_update_results[0].error_details)
except ApiException as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
except Exception as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
def testGetDiagnosticLogs(self):
with open(SignTest1File, 'rb') as sign_file:
file_contents = sign_file.read()
# Set properties for envelope and create an envelope to be signed later on
email_subject = 'Please Sign my Python SDK Envelope'
email_blurb = 'Hello, Please sign my Python SDK Envelope.'
# add a document to the envelope
base64_doc = base64.b64encode(file_contents).decode("utf-8")
name = 'TestFile.pdf'
document_id = '1'
doc = docusign.Document(document_base64=base64_doc,
name=name,
document_id=document_id)
documents = [doc]
# Create a SignHere tab somewhere on the document for the signer to sign
document_id = '1'
page_number = '1'
recipient_id = '1'
x_position = '100'
y_position = '100'
scale_value = '0.5'
sign_here = docusign.SignHere(document_id=document_id,
page_number=page_number,
recipient_id=recipient_id,
x_position=x_position,
y_position=y_position,
scale_value=scale_value)
sign_here_tabs = [sign_here]
tabs = docusign.Tabs(sign_here_tabs=sign_here_tabs)
# Add a recipient to sign the document
signer_email = Username
signer_name = 'Pat Developer'
signer_recipient_id = '1'
# this value represents the client's unique identifier for the signer
signer_client_user_id = '2939'
signer_tabs = tabs
signer = docusign.Signer(email=signer_email,
name=signer_name,
recipient_id=signer_recipient_id,
client_user_id=signer_client_user_id,
tabs=signer_tabs)
signers = [signer]
recipients = docusign.Recipients(signers=signers)
# send the envelope (otherwise it will be "created" in the Draft folder)
status = 'sent'
# create an envelope to be signed
envelope_definition = docusign.EnvelopeDefinition(email_subject=email_subject,
email_blurb=email_blurb,
documents=documents,
recipients=recipients,
status=status)
envelopes_api = EnvelopesApi()
diag_api = DiagnosticsApi()
try:
docusign.configuration.api_client = self.api_client
diagnostics_settings_information = docusign.DiagnosticsSettingsInformation()
diagnostics_settings_information.api_request_logging = 'true'
diag_api.update_request_log_settings(diagnostics_settings_information=diagnostics_settings_information)
envelope_summary = envelopes_api.create_envelope(self.user_info.accounts[0].account_id,
envelope_definition=envelope_definition)
envelope_id = envelope_summary.envelope_id
file1 = envelopes_api.get_document(self.user_info.accounts[0].account_id, 'combined', envelope_id)
temporary_file1 = tempfile.NamedTemporaryFile(delete=False)
with open(temporary_file1.name + ".pdf", "wb") as f:
f.write(file1)
assert len(file1) > 0
subprocess.call('open ' + temporary_file1.name + ".pdf", shell=True)
logs_list = diag_api.list_request_logs()
request_log_id = logs_list.api_request_logs[0].request_log_id
file2 = diag_api.get_request_log(request_log_id)
temporary_file2 = tempfile.NamedTemporaryFile(delete=False)
with open(temporary_file2.name + ".txt", "wb") as f:
f.write(file2)
assert len(file2) > 0
subprocess.call('open ' + temporary_file2.name + ".txt", shell=True)
except ApiException as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
except Exception as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
def testGetFormData(self):
try:
envelopes_api = EnvelopesApi()
form_data = envelopes_api.get_form_data(account_id=self.user_info.accounts[0].account_id,
envelope_id=self.envelope_id)
assert form_data is not None
assert form_data.prefill_form_data is not None
assert form_data.prefill_form_data.form_data[0] is not None
assert form_data.prefill_form_data.form_data[0].name is not None
except ApiException as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
except Exception as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
def testListTabs(self):
# For this the template Role should be manager
template_role_name = 'Manager'
# Set properties and create an envelope later on
email_subject = 'Please Sign my Python SDK Envelope'
email_blurb = 'Hello, Please sign my Python SDK Envelope.'
# assign template information including ID and role(s)
template_id = TemplateId
# create a template role with a valid templateId and roleName and assign signer info
role_name = template_role_name
name = 'Pat Developer'
email = Username
t_role = docusign.TemplateRole(role_name=role_name,
name=name,
email=email)
# create a list of template roles and add our newly created role
# assign template role(s) to the envelope
template_roles = [t_role]
# send the envelope by setting |status| to "sent". To save as a draft set to "created"
status = 'sent'
# create the envelope definition with the properties set
envelope_definition = docusign.EnvelopeDefinition(email_subject=email_subject,
email_blurb=email_blurb,
template_id=template_id,
template_roles=template_roles,
status=status)
try:
envelopes_api = EnvelopesApi()
# Create Envelope with the new role
envelope_summary = envelopes_api.create_envelope(self.user_info.accounts[0].account_id,
envelope_definition=envelope_definition)
# Read the new Envelope
created_envelope = envelopes_api.get_envelope(account_id=self.user_info.accounts[0].account_id,
envelope_id=envelope_summary.envelope_id)
recipients = envelopes_api.list_recipients(account_id=self.user_info.accounts[0].account_id,
envelope_id=created_envelope.envelope_id)
tabs = envelopes_api.list_tabs(account_id=self.user_info.accounts[0].account_id,
envelope_id=created_envelope.envelope_id,
recipient_id=recipients.signers[2].recipient_id)
list_tabs = tabs.list_tabs
assert list_tabs is not None
except ApiException as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
except Exception as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
def testMoveEnvelopes(self):
with open(SignTest1File, 'rb') as sign_file:
file_contents = sign_file.read()
# Set properties for envelope and create an envelope to be signed later on
email_subject = 'Please Sign my Python SDK Envelope'
email_blurb = 'Hello, Please sign my Python SDK Envelope.'
# add a document to the envelope
base64_doc = base64.b64encode(file_contents).decode("utf-8")
name = 'TestFile.pdf'
document_id = '1'
doc = docusign.Document(document_base64=base64_doc,
name=name,
document_id=document_id)
documents = [doc]
# Add a recipient to sign the document
email = Username
name = 'Pat Developer'
recipient_id = '1'
signer = docusign.Signer(email=email,
name=name,
recipient_id=recipient_id)
# Create a SignHere tab somewhere on the document for the signer to sign
document_id = '1'
page_number = '1'
recipient_id = '1'
x_position = '100'
y_position = '100'
scale_value = '0.5'
sign_here = docusign.SignHere(document_id=document_id,
page_number=page_number,
recipient_id=recipient_id,
x_position=x_position,
y_position=y_position,
scale_value=scale_value)
sign_here_tabs = [sign_here]
tabs = docusign.Tabs(sign_here_tabs=sign_here_tabs)
signer.tabs = tabs
signers = [signer]
recipients = docusign.Recipients(signers=signers)
status = 'sent'
# Now setting all the properties in previous steps create the envelope now
envelope_definition = docusign.EnvelopeDefinition(email_subject=email_subject,
email_blurb=email_blurb,
documents=documents,
recipients=recipients,
status=status)
envelopes_api = EnvelopesApi()
try:
envelope_summary = envelopes_api.create_envelope(self.user_info.accounts[0].account_id,
envelope_definition=envelope_definition)
assert envelope_summary is not None
assert envelope_summary.envelope_id is not None
assert envelope_summary.status == 'sent'
folders_api = FoldersApi()
folders_request = docusign.FoldersRequest(envelope_ids=[envelope_summary.envelope_id], from_folder_id="sentitems")
to_folder_id = "draft"
folders_api.move_envelopes(self.user_info.accounts[0].account_id, to_folder_id,
folders_request=folders_request)
# Wait for 3 second to make sure the newly created envelope was moved to the 'sentitems' folder
# Note: It's discouraged to use sleep statement or to poll DocuSign for envelope status or folder id
# In production, use DocuSign Connect to get notified when the status of the envelope have changed.
# 3 Seconds because sometimes when not in public or slow networks, the call takes more time and fails for 1 second.
sleep(3)
# Test if we moved the envelope to the correct folder
search_options = "true"
list_from_drafts_folder = folders_api.list_items(self.user_info.accounts[0].account_id, to_folder_id, include_items=search_options)
assert list_from_drafts_folder is not None
for folder in list_from_drafts_folder.folders:
for list_item in folder.folder_items:
if list_item.envelope_id == envelope_summary.envelope_id:
return
assert False
except ApiException as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
except Exception as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
def testTemplateDocumentTabsRetrieval(self):
# Create Envelope template
template_summary = self.testCreateTemplate()
template_id = template_summary.template_id
templates_api = TemplatesApi()
# List all documents from the created template to find the documentId
template_documents_list_result = templates_api.list_documents(self.user_info.accounts[0].account_id, template_id)
# Check if there are no documents within the template
has_template_documents = template_documents_list_result is not None and template_documents_list_result.template_documents is not None and len(template_documents_list_result.template_documents) > 0
assert has_template_documents, 'No document found within created template'
document_id = template_documents_list_result.template_documents[0].document_id
try:
# Get list of various document tabs
document_tabs = templates_api.get_document_tabs(self.user_info.accounts[0].account_id, document_id, template_id)
assert document_tabs is not None
except ApiException as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
except Exception as e:
print("\nException when calling DocuSign API: %s" % e)
assert e is None # make the test case fail in case of an API exception
if __name__ == '__main__':
unittest.main()