Skip to content

Commit fb5ced4

Browse files
Added unit/integration tests for 6 code examples (#114)
* added tests * fixed linter errors and updated tests
1 parent 8fd5cde commit fb5ced4

File tree

9 files changed

+387
-37
lines changed

9 files changed

+387
-37
lines changed

app/eSignature/examples/eg008_create_template.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ def get_args():
1818
return {
1919
"account_id": session["ds_account_id"],
2020
"base_path": session["ds_base_path"],
21-
"access_token": session["ds_access_token"]
21+
"access_token": session["ds_access_token"],
22+
"template_args": {
23+
"doc_file": path.join(demo_docs_path, doc_file),
24+
"template_name": template_name
25+
}
2226
}
2327

2428
@classmethod
@@ -44,7 +48,7 @@ def worker(cls, args):
4448

4549
# Template not found -- so create it
4650
# 2. create the template
47-
template_req_object = cls.make_template_req()
51+
template_req_object = cls.make_template_req(args["template_args"])
4852
res = templates_api.create_template(account_id=args["account_id"], envelope_template=template_req_object)
4953
template_id = res.template_id
5054
results_template_name = res.name
@@ -58,15 +62,15 @@ def worker(cls, args):
5862
}
5963

6064
@classmethod
61-
def make_template_req(cls):
65+
def make_template_req(cls, args):
6266
"""Creates template req object"""
6367

6468
# document 1 (pdf)
6569
#
6670
# The template has two recipient roles.
6771
# recipient 1 - signer
6872
# recipient 2 - cc
69-
with open(path.join(demo_docs_path, doc_file), "rb") as file:
73+
with open(args["doc_file"], "rb") as file:
7074
content_bytes = file.read()
7175
base64_file_content = base64.b64encode(content_bytes).decode("ascii")
7276

@@ -191,7 +195,7 @@ def make_template_req(cls):
191195
documents=[document], email_subject="Please sign this document",
192196
recipients=Recipients(signers=[signer], carbon_copies=[cc]),
193197
description="Example template created via the API",
194-
name=template_name,
198+
name=args["template_name"],
195199
shared="false",
196200
status="created"
197201
)

app/eSignature/examples/eg016_set_tab_values.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def get_args():
2323
"signer_name": signer_name,
2424
"signer_client_id": signer_client_id,
2525
"ds_return_url": url_for("ds.ds_return", _external=True),
26+
"doc_file": path.join(demo_docs_path, DS_CONFIG["doc_salary_docx"])
2627
}
2728
args = {
2829
"account_id": session["ds_account_id"],
@@ -87,7 +88,7 @@ def make_envelope(cls, args):
8788
#
8889
# The envelope has one recipient:
8990
# recipient 1 - signer
90-
with open(path.join(demo_docs_path, DS_CONFIG["doc_salary_docx"]), "rb") as file:
91+
with open(args["doc_file"], "rb") as file:
9192
content_bytes = file.read()
9293
base64_file_content = base64.b64encode(content_bytes).decode("ascii")
9394

app/eSignature/examples/eg031_bulk_send.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def get_args():
3030
"account_id": session["ds_account_id"], # Represents your {ACCOUNT_ID}
3131
"base_path": session["ds_base_path"],
3232
"access_token": session["ds_access_token"], # Represents your {ACCESS_TOKEN}
33+
"doc_pdf": path.join(demo_docs_path, DS_CONFIG["doc_pdf"]),
3334
"signers": [
3435
{
3536
"signer_name": signer_name_1,
@@ -78,7 +79,7 @@ def worker(cls, args):
7879
# Create an envelope
7980
# Step 4-1 start
8081
envelope_api = EnvelopesApi(api_client)
81-
envelope_definition = cls.make_draft_envelope()
82+
envelope_definition = cls.make_draft_envelope(args["doc_pdf"])
8283
envelope = envelope_api.create_envelope(account_id=args["account_id"], envelope_definition=envelope_definition)
8384
envelope_id = envelope.envelope_id
8485
# Step 4-1 end
@@ -158,13 +159,13 @@ def create_bulk_sending_list(cls, args):
158159

159160
# Step 4-2 start
160161
@classmethod
161-
def make_draft_envelope(cls):
162+
def make_draft_envelope(cls, doc_pdf):
162163
"""
163164
Creates the envelope
164165
"""
165166

166167
# Open the example file
167-
with open(path.join(demo_docs_path, DS_CONFIG["doc_pdf"]), "rb") as file:
168+
with open(doc_pdf, "rb") as file:
168169
content_bytes = file.read()
169170
base64_file_content = base64.b64encode(content_bytes).decode("ascii")
170171

app/rooms/examples/eg006_create_external_form_fill_session.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ def worker(args):
8585
# Step 1. Create an API client with headers
8686
api_client = create_rooms_api_client(access_token=args["access_token"])
8787

88-
request_body=ExternalFormFillSessionForCreate(
88+
request_body = ExternalFormFillSessionForCreate(
8989
room_id=args['room_id'],
9090
form_id=args['form_id'],
91-
x_frame_allowed_url = args['x_frame_allowed_url']
91+
x_frame_allowed_url=args['x_frame_allowed_url']
9292
)
9393

9494
# Step 2. Create an external form fill session

app/tests/click_tests.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import datetime
2+
import unittest
3+
4+
from app.click.examples.eg001_create_clickwrap import Eg001CreateClickwrapController
5+
from app.click.examples.eg002_activate_clickwrap import Eg002ActivateClickwrapController
6+
from .test_helper import TestHelper, CONFIG, ApiType
7+
8+
9+
class ClickTesting(unittest.TestCase):
10+
@classmethod
11+
def setUpClass(cls):
12+
results = TestHelper.authenticate([ApiType.CLICK.value])
13+
14+
cls.access_token = results["access_token"]
15+
cls.account_id = results["account_id"]
16+
cls.base_path = results["base_path"]
17+
18+
def test_create_clickwrap_worker(self):
19+
args = {
20+
"account_id": self.account_id,
21+
"access_token": self.access_token,
22+
"clickwrap_name": f"{CONFIG['clickwrap_name']}_{int(datetime.datetime.utcnow().timestamp())}"
23+
}
24+
25+
results = Eg001CreateClickwrapController.worker(args)
26+
27+
self.assertIsNotNone(results)
28+
self.assertIsNotNone(results.clickwrap_id)
29+
30+
def test_activate_clickwrap_worker(self):
31+
args = {
32+
"account_id": self.account_id,
33+
"base_path": self.base_path,
34+
"access_token": self.access_token
35+
}
36+
results = Eg002ActivateClickwrapController.get_inactive_clickwraps(args)
37+
clickwrap = results.clickwraps[0]
38+
39+
clickwrap_args = f"{{\"clickwrap_id\": \"{clickwrap.clickwrap_id}\",\"version_number\": \"{clickwrap.version_number}\"}}"
40+
args["clickwrap"] = clickwrap_args
41+
42+
results = Eg002ActivateClickwrapController.worker(args)
43+
44+
self.assertIsNotNone(results)
45+
self.assertEqual(results.status, "active")
46+
47+
def test_activate_clickwrap_get_inactive_clickwraps(self):
48+
args = {
49+
"account_id": self.account_id,
50+
"base_path": self.base_path,
51+
"access_token": self.access_token
52+
}
53+
54+
results = Eg002ActivateClickwrapController.get_inactive_clickwraps(args)
55+
56+
self.assertIsNotNone(results)
57+
58+
59+
if __name__ == '__main__':
60+
unittest.main()

0 commit comments

Comments
 (0)