Skip to content

Commit 7dd640c

Browse files
added tests
1 parent 11572c0 commit 7dd640c

7 files changed

Lines changed: 834 additions & 0 deletions

app/tests/__init__.py

Whitespace-only changes.
724 KB
Binary file not shown.
57 KB
Binary file not shown.
37.8 KB
Binary file not shown.
29.2 KB
Binary file not shown.

app/tests/test_helper.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import os
2+
import base64
3+
import json
4+
from docusign_esign import ApiClient
5+
6+
from ..ds_config import DS_CONFIG, DS_JWT
7+
8+
DATA = {
9+
"signer_client_id": '1000',
10+
"return_url": DS_CONFIG["app_url"] + "/ds-return",
11+
"ping_url": DS_CONFIG["app_url"] + "/",
12+
"private_key_filename": "../config/private.key",
13+
"base_path": 'https://demo.docusign.net/restapi',
14+
"oauth_base_path": 'account-d.docusign.com',
15+
"redirect_uri": 'https://www.docusign.com/api',
16+
"scopes": ["signature", "impersonation"],
17+
"expires_in": 3600,
18+
"test_pdf_file": './tests/docs/World_Wide_Corp_lorem.pdf',
19+
"test_docx_file": './tests/docs/World_Wide_Corp_Battle_Plan_Trafalgar.docx',
20+
"test_template_pdf_file": './tests/docs/World_Wide_Corp_fields.pdf',
21+
"test_template_docx_file": './tests/docs/World_Wide_Corp_salary.docx',
22+
"template_name": 'Example Signer and CC template',
23+
"cc_name": 'Test Name',
24+
"cc_email": 'test@mail.com',
25+
"item": 'Item',
26+
"quantity": '5'
27+
}
28+
29+
class TestHelper:
30+
@staticmethod
31+
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()
34+
35+
api_client = ApiClient()
36+
api_client.host = DATA["base_path"]
37+
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+
)
49+
50+
access_token = token_response.access_token
51+
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"
57+
58+
return {"access_token": access_token, "account_id": api_account_id, "base_path": base_path}
59+
60+
@staticmethod
61+
def read_as_base64(path):
62+
with open(path, "rb") as file:
63+
content_bytes = file.read()
64+
base64_file_content = base64.b64encode(content_bytes).decode("ascii")
65+
66+
return base64_file_content
67+

0 commit comments

Comments
 (0)