Skip to content

Commit

Permalink
Update test_subscriber.py
Browse files Browse the repository at this point in the history
added test cases for updated subscriber dto field related to credentials
  • Loading branch information
prathapbelli authored Sep 5, 2023
1 parent 659e533 commit 1cc85e3
Showing 1 changed file with 77 additions and 1 deletion.
78 changes: 77 additions & 1 deletion tests/api/test_subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
SubscriberPreferencePreferenceDto,
SubscriberPreferenceTemplateDto,
)
from novu.enums import Channel
from novu.enums import Channel, ChatProviderIdEnum
from tests.factories import MockResponse


Expand Down Expand Up @@ -47,6 +47,7 @@ def setUpClass(cls) -> None:
_id="63dafedbc037e013fd82d37a",
_environment_id="63dafed97779f59258e38445",
_organization_id="63dafed97779f59258e3843f",
channels=[],
deleted=False,
created_at="2023-02-02T00:07:55.459Z",
updated_at="2023-02-06T23:03:22.645Z",
Expand Down Expand Up @@ -153,6 +154,81 @@ def test_get_subscriber(self, mock_request: mock.MagicMock) -> None:
timeout=5,
)

@mock.patch("requests.request")
def test_get_subscriber_with_credentials_info(self, mock_request: mock.MagicMock) -> None:
mock_request.return_value = MockResponse(
200,
{
"data": {
"_id": "63dafedbc037e013fd82d37a",
"_organizationId": "63dafed97779f59258e3843f",
"_environmentId": "63dafed97779f59258e38445",
"subscriberId": "63dafed4117f8c850991ec4a",
"channels": [
{
'provider_id': 'slack',
'_integration_id': '64f6d74be166fcd7f2751111',
'credentials': {
'webhook_url': 'TEST',
'channel': 'slack',
'device_tokens': ["TEST"]
},
'integration_identifier': None
}
],
"deleted": False,
"createdAt": "2023-02-02T00:07:55.459Z",
"updatedAt": "2023-02-06T23:03:22.645Z",
"__v": 0,
"isOnline": False,
"email": "[email protected]",
"lastOnlineAt": "2023-02-06T23:03:22.645Z",
}
},
)

res = self.api.get("subscriber-id")
self.assertIsInstance(res, SubscriberDto)
self.assertEqual(
res,
SubscriberDto(
subscriber_id="63dafed4117f8c850991ec4a",
email="[email protected]",
first_name=None,
last_name=None,
phone=None,
avatar=None,
locale=None,
_id="63dafedbc037e013fd82d37a",
_environment_id="63dafed97779f59258e38445",
_organization_id="63dafed97779f59258e3843f",
channels=[ChannelSettingsDto(
provider_id=ChatProviderIdEnum.SLACK,
_integration_id='64f6d74be166fcd7f2751111',
credentials=ChannelSettingsCredentialsDto(
webhook_url='TEST',
channel='slack',
device_tokens=["TEST"]
),
integration_identifier=None
)],
deleted=False,
created_at="2023-02-02T00:07:55.459Z",
updated_at="2023-02-06T23:03:22.645Z",
is_online=False,
last_online_at="2023-02-06T23:03:22.645Z",
)
)

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

@mock.patch("requests.request")
def test_update_subscriber(self, mock_request: mock.MagicMock) -> None:
mock_request.return_value = MockResponse(200, self.response_get)
Expand Down

0 comments on commit 1cc85e3

Please sign in to comment.