Skip to content

Commit babf6da

Browse files
updated tests
1 parent fbd0770 commit babf6da

4 files changed

Lines changed: 46 additions & 68 deletions

File tree

app/eSignature/examples/eg016_set_tab_values.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ def worker(cls, args):
5555
results = envelopes_api.create_envelope(account_id=args["account_id"], envelope_definition=envelope_definition)
5656

5757
envelope_id = results.envelope_id
58-
app.logger.info(f"Envelope was created. EnvelopeId {envelope_id}")
5958

6059
# 3. Create the RecipientViewRequest object
6160
recipient_view_request = RecipientViewRequest(

app/eSignature/views/eg016_set_tab_values.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from os import path
44

55
from docusign_esign.client.api_exception import ApiException
6-
from flask import render_template, redirect, session, Blueprint
6+
from flask import render_template, redirect, session, Blueprint, current_app
77

88
from ..examples.eg016_set_tab_values import Eg016SetTabValuesController
99
from ...docusign import authenticate, ensure_manifest, get_example_by_number
@@ -35,6 +35,7 @@ def set_tab_values():
3535
try:
3636
# 2. Call the worker method for setting tab values
3737
results = Eg016SetTabValuesController.worker(args)
38+
current_app.logger.info(f"Envelope was created. EnvelopeId {results['envelope_id']}")
3839
except ApiException as err:
3940
return process_error(err)
4041

app/tests/test_helper.py

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import base64
3-
import json
43
from docusign_esign import ApiClient
4+
from docusign_esign.client.api_exception import ApiException
55

66
from ..ds_config import DS_CONFIG, DS_JWT
77

@@ -26,36 +26,49 @@
2626
"quantity": '5'
2727
}
2828

29+
2930
class TestHelper:
3031
@staticmethod
3132
def authenticate():
32-
private_key_file = open(os.path.abspath(os.path.join("../", DS_JWT["private_key_file"])), "r")
33-
private_key = private_key_file.read()
33+
try:
34+
private_key_file = open(os.path.abspath(os.path.join("../", DS_JWT["private_key_file"])), "r")
35+
private_key = private_key_file.read()
36+
37+
api_client = ApiClient()
38+
api_client.host = DATA["base_path"]
39+
40+
api_client = ApiClient()
41+
api_client.set_base_path(DATA["base_path"])
42+
api_client.set_oauth_host_name(DATA["oauth_base_path"])
43+
token_response = api_client.request_jwt_user_token(
44+
client_id=DS_JWT["ds_client_id"],
45+
user_id=DS_JWT["ds_impersonated_user_id"],
46+
oauth_host_name=DATA["oauth_base_path"],
47+
private_key_bytes=private_key,
48+
expires_in=4000,
49+
scopes=DATA["scopes"]
50+
)
3451

35-
api_client = ApiClient()
36-
api_client.host = DATA["base_path"]
52+
access_token = token_response.access_token
3753

38-
api_client = ApiClient()
39-
api_client.set_base_path(DATA["base_path"])
40-
api_client.set_oauth_host_name(DATA["oauth_base_path"])
41-
token_response = api_client.request_jwt_user_token(
42-
client_id=DS_JWT["ds_client_id"],
43-
user_id=DS_JWT["ds_impersonated_user_id"],
44-
oauth_host_name=DATA["oauth_base_path"],
45-
private_key_bytes=private_key,
46-
expires_in=4000,
47-
scopes=DATA["scopes"]
48-
)
54+
# Save API account ID
55+
user_info = api_client.get_user_info(access_token)
56+
accounts = user_info.get_accounts()
57+
api_account_id = accounts[0].account_id
58+
base_path = accounts[0].base_uri + "/restapi"
4959

50-
access_token = token_response.access_token
60+
return {"access_token": access_token, "account_id": api_account_id, "base_path": base_path}
61+
except ApiException as err:
62+
body = err.body.decode('utf8')
5163

52-
# Save API account ID
53-
user_info = api_client.get_user_info(access_token)
54-
accounts = user_info.get_accounts()
55-
api_account_id = accounts[0].account_id
56-
base_path = accounts[0].base_uri + "/restapi"
64+
if "consent_required" in body:
65+
url_scopes = "+".join(DATA["scopes"])
66+
url = f"https://{DS_JWT['authorization_server']}/oauth/auth?response_type=code&" \
67+
f"scope={url_scopes}&client_id={DS_JWT['ds_client_id']}&redirect_uri={DATA['redirect_uri']}"
5768

58-
return {"access_token": access_token, "account_id": api_account_id, "base_path": base_path}
69+
consent_message = f"You should grant access by making the following call: {url}"
70+
print(consent_message)
71+
raise Exception(f"You should grant access by making the following call: {url}")
5972

6073
@staticmethod
6174
def read_as_base64(path):

app/tests/tests.py

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import unittest
22
import base64
33
import os
4-
import datetime
54
from docusign_esign import Document, Signer, EnvelopeDefinition, SignHere, Tabs, \
65
Recipients, CarbonCopy, EnvelopeTemplate, Checkbox, List, ListItem, Text, Radio, RadioGroup, Number, TemplateRole, \
76
CompositeTemplate, ServerTemplate, InlineTemplate, CustomFields, TextCustomField
@@ -14,8 +13,6 @@
1413
from app.eSignature.examples.eg016_set_tab_values import Eg016SetTabValuesController
1514
from .test_helper import TestHelper, DATA, DS_CONFIG
1615

17-
unittest.TestLoader.sortTestMethodsUsing = None
18-
1916

2017
class Testing(unittest.TestCase):
2118
TEMPLATE_ID = ""
@@ -27,7 +24,6 @@ def setUpClass(cls):
2724
cls.access_token = results["access_token"]
2825
cls.account_id = results["account_id"]
2926
cls.base_path = results["base_path"]
30-
cls.test_helper = TestHelper()
3127

3228
def test_embedded_signing_worker(self):
3329
envelope_args = {
@@ -87,39 +83,6 @@ def test_embedded_signing_make_envelope(self):
8783
)]
8884
)
8985

90-
expected = {
91-
"emailSubject": "Please sign this document",
92-
"documents": [
93-
{
94-
"documentBase64": base64_file_content,
95-
"name": "Lorem Ipsum",
96-
"fileExtension": "pdf",
97-
"documentId": "3",
98-
}
99-
],
100-
"recipients": {
101-
"signers": [
102-
{
103-
"email": DS_CONFIG["signer_email"],
104-
"name": DS_CONFIG["signer_name"],
105-
"clientUserId": DATA["signer_client_id"],
106-
"recipientId": '1',
107-
"tabs": {
108-
"signHereTabs": [
109-
{
110-
"anchorString": "/sn1/",
111-
"anchorYOffset": "10",
112-
"anchorUnits": "pixels",
113-
"anchorXOffset": "20"
114-
}
115-
]
116-
}
117-
}
118-
]
119-
},
120-
"status": 'sent'
121-
}
122-
12386
results = Eg001EmbeddedSigningController.make_envelope(envelope_args)
12487

12588
self.assertIsNotNone(results)
@@ -140,7 +103,8 @@ def test_sign_via_email(self):
140103
"envelope_args": envelope_args
141104
}
142105

143-
results = Eg002SigningViaEmailController.worker(args, DATA["test_docx_file"], DATA["test_pdf_file"])
106+
results = Eg002SigningViaEmailController.worker(args, os.path.join("../../", DATA["test_docx_file"]),
107+
os.path.join("../../", DATA["test_pdf_file"]))
144108

145109
self.assertIsNotNone(results)
146110
self.assertIsNotNone(results["envelope_id"])
@@ -235,7 +199,8 @@ def test_sign_via_email_make_envelope(self):
235199
)
236200
)
237201

238-
envelope = Eg002SigningViaEmailController.make_envelope(envelope_args, os.path.abspath(DATA["test_docx_file"]), os.path.abspath(DATA["test_pdf_file"]))
202+
envelope = Eg002SigningViaEmailController.make_envelope(envelope_args, os.path.abspath(DATA["test_docx_file"]),
203+
os.path.abspath(DATA["test_pdf_file"]))
239204

240205
self.assertIsNotNone(envelope)
241206
self.assertEquals(envelope, expected)
@@ -447,7 +412,6 @@ def test_use_template(self):
447412
self.assertIsNotNone(result)
448413
self.assertIsNotNone(result["envelope_id"])
449414

450-
451415
def test_use_template_make_envelope(self):
452416
envelope_args = {
453417
"signer_email": DS_CONFIG["signer_email"],
@@ -479,7 +443,7 @@ def test_use_template_make_envelope(self):
479443
self.assertIsNotNone(result)
480444
self.assertEquals(result, expected)
481445

482-
def test_add_doc_to_template(self):
446+
def test_include_doc_to_template(self):
483447
envelope_args = {
484448
"signer_email": DS_CONFIG["signer_email"],
485449
"signer_name": DS_CONFIG["signer_name"],
@@ -504,7 +468,7 @@ def test_add_doc_to_template(self):
504468
self.assertIsNotNone(result["envelope_id"])
505469
self.assertIsNotNone(result["redirect_url"])
506470

507-
def test_add_doc_to_template_make_envelope(self):
471+
def test_include_doc_to_template_make_envelope(self):
508472
envelope_args = {
509473
"signer_email": DS_CONFIG["signer_email"],
510474
"signer_name": DS_CONFIG["signer_name"],
@@ -615,7 +579,7 @@ def test_add_doc_to_template_make_envelope(self):
615579
self.assertIsNotNone(envelope)
616580
self.assertEquals(envelope, expected)
617581

618-
def test_add_doc_to_template_html_doc(self):
582+
def test_include_doc_to_template_html_doc(self):
619583
envelope_args = {
620584
"signer_email": DS_CONFIG["signer_email"],
621585
"signer_name": DS_CONFIG["signer_name"],
@@ -755,5 +719,6 @@ def test_set_tab_values_make_envelope(self):
755719
self.assertIsNotNone(envelope)
756720
self.assertEquals(envelope, expected)
757721

722+
758723
if __name__ == '__main__':
759724
unittest.main()

0 commit comments

Comments
 (0)