Skip to content

Commit da8a7c3

Browse files
Add support to replace multiple tags
1 parent 4d569c3 commit da8a7c3

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

tests/test_client.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,25 @@ def test_tags():
384384

385385

386386
@responses.activate
387-
def test_multiple_tags():
387+
def test_replace_multiple_tags():
388388
mock_doc_id = 169985445
389389
mock_resp = {"id": 6673474, "tags": ["tag_1", "tag_2", "tag_3"]}
390390
client = Client(client_id="v", client_secret="w", username="o", api_key="c")
391391
responses.put(
392+
f"{client.versioned_url}/partner/documents/{mock_doc_id}/",
393+
json=mock_resp,
394+
status=200,
395+
)
396+
d = client.replace_tags(mock_doc_id, ["tag_1", "tag_2", "tag_3"])
397+
assert d == mock_resp
398+
399+
400+
@responses.activate
401+
def test_add_multiple_tags():
402+
mock_doc_id = 169985445
403+
mock_resp = {"id": 6673474, "tags": ["tag_1", "tag_2", "tag_3"]}
404+
client = Client(client_id="v", client_secret="w", username="o", api_key="c")
405+
responses.post(
392406
f"{client.versioned_url}/partner/documents/{mock_doc_id}/tags/",
393407
json=mock_resp,
394408
status=200,

veryfi/client.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,17 @@ def add_tag(self, document_id, tag_name):
399399
request_arguments = {"name": tag_name}
400400
return self._request("PUT", endpoint_name, request_arguments)
401401

402+
def replace_tags(self, document_id, tags):
403+
"""
404+
Replace multiple tags on an existing document.
405+
:param document_id: ID of the document you'd like to update
406+
:param tags: array of strings
407+
:return: Added tags data
408+
"""
409+
endpoint_name = f"/documents/{document_id}/"
410+
request_arguments = {"tags": tags}
411+
return self._request("PUT", endpoint_name, request_arguments)
412+
402413
def add_tags(self, document_id, tags):
403414
"""
404415
Add multiple tags on an existing document.
@@ -408,4 +419,4 @@ def add_tags(self, document_id, tags):
408419
"""
409420
endpoint_name = f"/documents/{document_id}/tags/"
410421
request_arguments = {"tags": tags}
411-
return self._request("PUT", endpoint_name, request_arguments)
422+
return self._request("POST", endpoint_name, request_arguments)

0 commit comments

Comments
 (0)