Skip to content

Commit

Permalink
Add support to replace multiple tags
Browse files Browse the repository at this point in the history
  • Loading branch information
alejouribesanchez committed Dec 12, 2023
1 parent 4d569c3 commit da8a7c3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
16 changes: 15 additions & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,25 @@ def test_tags():


@responses.activate
def test_multiple_tags():
def test_replace_multiple_tags():
mock_doc_id = 169985445
mock_resp = {"id": 6673474, "tags": ["tag_1", "tag_2", "tag_3"]}
client = Client(client_id="v", client_secret="w", username="o", api_key="c")
responses.put(
f"{client.versioned_url}/partner/documents/{mock_doc_id}/",
json=mock_resp,
status=200,
)
d = client.replace_tags(mock_doc_id, ["tag_1", "tag_2", "tag_3"])
assert d == mock_resp


@responses.activate
def test_add_multiple_tags():
mock_doc_id = 169985445
mock_resp = {"id": 6673474, "tags": ["tag_1", "tag_2", "tag_3"]}
client = Client(client_id="v", client_secret="w", username="o", api_key="c")
responses.post(
f"{client.versioned_url}/partner/documents/{mock_doc_id}/tags/",
json=mock_resp,
status=200,
Expand Down
13 changes: 12 additions & 1 deletion veryfi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,17 @@ def add_tag(self, document_id, tag_name):
request_arguments = {"name": tag_name}
return self._request("PUT", endpoint_name, request_arguments)

def replace_tags(self, document_id, tags):
"""
Replace multiple tags on an existing document.
:param document_id: ID of the document you'd like to update
:param tags: array of strings
:return: Added tags data
"""
endpoint_name = f"/documents/{document_id}/"
request_arguments = {"tags": tags}
return self._request("PUT", endpoint_name, request_arguments)

def add_tags(self, document_id, tags):
"""
Add multiple tags on an existing document.
Expand All @@ -408,4 +419,4 @@ def add_tags(self, document_id, tags):
"""
endpoint_name = f"/documents/{document_id}/tags/"
request_arguments = {"tags": tags}
return self._request("PUT", endpoint_name, request_arguments)
return self._request("POST", endpoint_name, request_arguments)

0 comments on commit da8a7c3

Please sign in to comment.