Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/blueink/bundle_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(
is_test: bool = False,
custom_key: str = None,
team: str = None,
signing_brand: str = None,
):
"""Helper class to aid building a Bundle.

Expand All @@ -41,6 +42,7 @@ def __init__(
is_test:
custom_key:
team:
signing_brand:
"""
self._label = label
self._in_order = in_order
Expand All @@ -52,6 +54,7 @@ def __init__(
self._packets = {}
self._custom_key = custom_key
self._team = team
self._signing_brand = signing_brand
self._envelope_template = None

# for file uploads, index should match those in the document "file_index" field
Expand Down Expand Up @@ -209,6 +212,7 @@ def add_field(
v_pattern: str = None,
v_min: int = None,
v_max: int = None,
v_attachment_types: List[str] = None,
key=None,
**additional_data,
):
Expand All @@ -226,6 +230,7 @@ def add_field(
v_pattern: Optional
v_min: Optional
v_max: Optional
v_attachment_types: Optional list of allowed attachment file extensions (only for kind='att')
editors: Optional
key: Optional
additional_data: Optional and will append any additional kwargs to the json of the field
Expand All @@ -247,6 +252,7 @@ def add_field(
v_pattern=v_pattern,
v_min=v_min,
v_max=v_max,
v_attachment_types=v_attachment_types,
key=key,
**additional_data,
)
Expand All @@ -267,6 +273,7 @@ def add_auto_placement(
offset_y: int = 0,
editors: List[str] = None,
page: int = None,
v_attachment_types: List[str] = None,
**additional_data,
):
"""Add an auto-placement field to a document.
Expand All @@ -284,6 +291,7 @@ def add_auto_placement(
offset_y: Vertical offset from the search text (default: 0)
editors: List of signer keys who can edit this field
page: Optional page number to limit search to
v_attachment_types: Optional list of allowed attachment file extensions (only for kind='att')
additional_data: Optional additional kwargs to append to the auto-placement

Returns:
Expand Down Expand Up @@ -313,6 +321,7 @@ def add_auto_placement(
offset_x=offset_x,
offset_y=offset_y,
page=page,
v_attachment_types=v_attachment_types,
**additional_data,
)

Expand Down Expand Up @@ -496,6 +505,7 @@ def _compile_bundle(self, **additional_data) -> Bundle:
cc_emails=self._cc_emails,
custom_key=self._custom_key,
team=self._team,
signing_brand=self._signing_brand,
**additional_data,
)
return bundle_out
Expand Down Expand Up @@ -561,6 +571,8 @@ def as_data_for_envelope_template(self, **additional_data):
result["custom_key"] = self._custom_key
if self._team:
result["team"] = self._team
if self._signing_brand:
result["signing_brand"] = self._signing_brand

# Add any additional data
result.update(additional_data)
Expand Down
3 changes: 3 additions & 0 deletions src/blueink/model/bundles.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class AutoPlacement(BaseModel):
offset_y: Optional[int] = 0
editors: Optional[List[str]]
page: Optional[int]
v_attachment_types: Optional[List[str]]

class Config:
extra = "allow"
Expand Down Expand Up @@ -94,6 +95,7 @@ class Field(BaseModel):
v_min: Optional[int]
v_max: Optional[int]
editors: Optional[List[str]]
v_attachment_types: Optional[List[str]]

class Config:
extra = "allow"
Expand Down Expand Up @@ -292,6 +294,7 @@ class Bundle(BaseModel):
is_test: Optional[bool]
custom_key: Optional[str]
team: Optional[str]
signing_brand: Optional[str]

class Config:
extra = "allow"
Expand Down
54 changes: 54 additions & 0 deletions src/blueink/tests/test_bundle_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,57 @@ def test_auto_placement_with_page_restriction(self):
auto_placement = compiled_bundle["documents"][0]["auto_placements"][0]

self.assert_equal(auto_placement["page"], 2)

def test_auto_placement_with_attachment_types(self):
"""Test auto-placement with v_attachment_types restriction"""
input_data = copy.deepcopy(self.BUNDLE_INIT_DATA)
url01 = self.DOCUMENT_01_URL
signer01_data = copy.deepcopy(self.SIGNER_01_DATA)

bh = BundleHelper(**input_data)
doc01_key = bh.add_document_by_url(url01)
signer01_key = bh.add_signer(**signer01_data)

bh.add_auto_placement(
document_key=doc01_key,
kind="att",
search="Upload your document",
w=20,
h=5,
v_attachment_types=["pdf", "png"],
editors=[signer01_key],
)

compiled_bundle = bh.as_data()
auto_placement = compiled_bundle["documents"][0]["auto_placements"][0]

self.assert_equal(auto_placement["kind"], "att")
self.assert_equal(auto_placement["v_attachment_types"], ["pdf", "png"])

def test_field_with_attachment_types(self):
"""Test adding a field with v_attachment_types"""
input_data = copy.deepcopy(self.BUNDLE_INIT_DATA)
url01 = self.DOCUMENT_01_URL
signer01_data = copy.deepcopy(self.SIGNER_01_DATA)

bh = BundleHelper(**input_data)
doc01_key = bh.add_document_by_url(url01)
signer01_key = bh.add_signer(**signer01_data)

bh.add_field(
document_key=doc01_key,
x=10,
y=20,
w=30,
h=10,
p=1,
kind="att",
editors=[signer01_key],
v_attachment_types=["pdf", "docx"],
)

compiled_bundle = bh.as_data()
field = compiled_bundle["documents"][0]["fields"][0]

self.assert_equal(field["kind"], "att")
self.assert_equal(field["v_attachment_types"], ["pdf", "docx"])
Loading