Skip to content

Commit

Permalink
feat(subscriber): added the delete_credentials method to the Subscrib…
Browse files Browse the repository at this point in the history
…erApi
  • Loading branch information
MuhammadNFadhil authored and ryshu committed Oct 14, 2023
1 parent 0e885ea commit d6ffc98
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
16 changes: 15 additions & 1 deletion novu/api/subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
SubscriberDto,
SubscriberPreferenceDto,
)
from novu.enums import Channel
from novu.enums import Channel, ProviderIdEnum


class SubscriberApi(Api):
Expand Down Expand Up @@ -131,6 +131,20 @@ def credentials(
self.handle_request("PUT", f"{self._subscriber_url}/{subscriber_id}/credentials", payload).get("data", {})
)

def delete_credentials(
self,
subscriber_id: str,
provider_id: ProviderIdEnum,
) -> None:
"""Delete subscriber credentials such as slack and expo tokens.
Args:
subscriber_id: The subscriber identifier
provider_id: The provider identifier (e.g: slack)
"""

self.handle_request("DELETE", f"{self._subscriber_url}/{subscriber_id}/credentials/{provider_id}")

def online_status(self, subscriber_id: str, status: bool) -> SubscriberDto:
"""Used to update the subscriber is_online flag
Expand Down
15 changes: 15 additions & 0 deletions tests/api/test_subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,3 +529,18 @@ def test_unseen_notifications(self, mock_request: mock.MagicMock) -> None:
params=None,
timeout=5,
)

@mock.patch("requests.request")
def test_delete_credentials(self, mock_request: mock.MagicMock) -> None:
mock_request.return_value = MockResponse(204)

self.api.delete_credentials("subscriber-id", ChatProviderIdEnum.SLACK)

mock_request.assert_called_once_with(
method="DELETE",
url="sample.novu.com/v1/subscribers/subscriber-id/credentials/slack",
headers={"Authorization": "ApiKey api-key"},
json=None,
params=None,
timeout=5,
)

0 comments on commit d6ffc98

Please sign in to comment.