66import os
77import subprocess
88import unittest
9- from pprint import pprint
9+
1010from time import sleep
11+ from datetime import datetime
1112
1213import docusign_esign as docusign
13- from docusign_esign import AuthenticationApi , EnvelopesApi , TemplatesApi , DiagnosticsApi , FoldersApi , ApiException
14+ from docusign_esign import AuthenticationApi , EnvelopesApi , TemplatesApi , DiagnosticsApi , FoldersApi , ApiException , TemplateSummary
1415
1516Username = os .environ .get ("USER_NAME" )
1617IntegratorKey = os .environ .get ("INTEGRATOR_KEY_JWT" )
@@ -340,7 +341,7 @@ def testEmbeddedSigning(self):
340341 print ("\n Exception when calling DocuSign API: %s" % e )
341342 assert e is None # make the test case fail in case of an API exception
342343
343- def testCreateTemplate (self ):
344+ def testCreateTemplate (self ) -> TemplateSummary :
344345 with open (SignTest1File , 'rb' ) as sign_file :
345346 file_contents = sign_file .read ()
346347
@@ -377,7 +378,23 @@ def testCreateTemplate(self):
377378 scale_value = sign_scale_value )
378379
379380 sign_here_tabs = [sign_here ]
380- tabs = docusign .Tabs (sign_here_tabs = sign_here_tabs )
381+
382+ # Create a date tab somewhere on the document for the signer to know about current date
383+ date_document_id = '1'
384+ date_page_number = '1'
385+ date_x_position = '50'
386+ date_y_position = '50'
387+
388+ current_date_tab = docusign .Date (document_id = date_document_id ,
389+ page_number = date_page_number ,
390+ recipient_id = recipient_id ,
391+ x_position = date_x_position ,
392+ y_position = date_y_position ,
393+ value = datetime .utcnow ().date ())
394+ date_tabs = [current_date_tab ]
395+
396+ tabs = docusign .Tabs (sign_here_tabs = sign_here_tabs , date_tabs = date_tabs )
397+
381398 signer = docusign .Signer (email = email ,
382399 name = name ,
383400 recipient_id = recipient_id ,
@@ -403,6 +420,7 @@ def testCreateTemplate(self):
403420 assert template_summary is not None
404421 assert template_summary .template_id is not None
405422
423+ return template_summary
406424 except ApiException as e :
407425 print ("\n Exception when calling DocuSign API: %s" % e )
408426 assert e is None # make the test case fail in case of an API exception
@@ -853,6 +871,35 @@ def testMoveEnvelopes(self):
853871 print ("\n Exception when calling DocuSign API: %s" % e )
854872 assert e is None # make the test case fail in case of an API exception
855873
874+ def testTemplateDocumentTabsRetrieval (self ):
875+
876+ # Create Envelope template
877+ template_summary = self .testCreateTemplate ()
878+ template_id = template_summary .template_id
879+
880+ templates_api = TemplatesApi ()
881+
882+ # List all documents from the created template to find the documentId
883+ template_documents_list_result = templates_api .list_documents (self .user_info .accounts [0 ].account_id , template_id )
884+
885+ # Check if there are no documents within the template
886+ has_template_documents = template_documents_list_result is None or template_documents_list_result .template_documents is None or len (template_documents_list_result .template_documents ) == 0
887+ assert has_template_documents , 'No document found within created template'
888+
889+ document_id = template_documents_list_result .template_documents [0 ].document_id
890+
891+ try :
892+ # Get list of various document tabs
893+ document_tabs = templates_api .get_document_tabs (self .user_info .accounts [0 ].account_id , document_id , template_id )
894+
895+ assert document_tabs is not None
896+
897+ except ApiException as e :
898+ print ("\n Exception when calling DocuSign API: %s" % e )
899+ assert e is None # make the test case fail in case of an API exception
900+ except Exception as e :
901+ print ("\n Exception when calling DocuSign API: %s" % e )
902+ assert e is None # make the test case fail in case of an API exception
856903
857904if __name__ == '__main__' :
858905 unittest .main ()
0 commit comments