-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ Enhanced test coverage for webhooks service (#748)
* 🚚 move tests to services module * 🎨 * ✅ Test coverage for webhooks route * 🎨 modify try-except block for readability and ensure cancelled errors are caught correctly * 🎨 * ✅ Test coverage for disconnect check * ✅ Test coverage for health check * 🎨 remove unnecessary get_container method * ✅ Broader test coverage for webhooks redis service * 🎨 * 👷 remove unused constant * 🎨
- Loading branch information
Showing
13 changed files
with
341 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
from unittest.mock import Mock | ||
|
||
import pytest | ||
|
||
from shared.models.webhook_events import CloudApiWebhookEventGeneric | ||
from webhooks.web.routers.webhooks import ( | ||
get_webhooks_by_wallet, | ||
get_webhooks_by_wallet_and_topic, | ||
) | ||
|
||
wallet_id = "wallet123" | ||
topic = "test_topic" | ||
cloud_api_event = CloudApiWebhookEventGeneric( | ||
wallet_id=wallet_id, | ||
topic=topic, | ||
origin="test_origin", | ||
group_id="test_group", | ||
payload={"key": "value"}, | ||
) | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_get_webhooks_by_wallet(): | ||
redis_service_mock = Mock() | ||
|
||
redis_service_mock.get_cloudapi_events_by_wallet.return_value = [cloud_api_event] | ||
|
||
result = await get_webhooks_by_wallet( | ||
wallet_id=wallet_id, redis_service=redis_service_mock | ||
) | ||
|
||
assert len(result) == 1 | ||
assert result[0].wallet_id == wallet_id | ||
redis_service_mock.get_cloudapi_events_by_wallet.assert_called_once_with( | ||
wallet_id, num=100 | ||
) | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_get_webhooks_by_wallet_empty(): | ||
redis_service_mock = Mock() | ||
|
||
redis_service_mock.get_cloudapi_events_by_wallet.return_value = [] | ||
|
||
result = await get_webhooks_by_wallet( | ||
wallet_id=wallet_id, redis_service=redis_service_mock | ||
) | ||
|
||
assert result == [] | ||
redis_service_mock.get_cloudapi_events_by_wallet.assert_called_once_with( | ||
wallet_id, num=100 | ||
) | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_get_webhooks_by_wallet_and_topic(): | ||
redis_service_mock = Mock() | ||
|
||
redis_service_mock.get_cloudapi_events_by_wallet_and_topic.return_value = [ | ||
cloud_api_event | ||
] | ||
|
||
result = await get_webhooks_by_wallet_and_topic( | ||
wallet_id=wallet_id, topic=topic, redis_service=redis_service_mock | ||
) | ||
|
||
assert len(result) == 1 | ||
assert result[0].wallet_id == wallet_id | ||
redis_service_mock.get_cloudapi_events_by_wallet_and_topic.assert_called_once_with( | ||
wallet_id=wallet_id, topic=topic, num=100 | ||
) | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_get_webhooks_by_wallet_and_topic_empty(): | ||
redis_service_mock = Mock() | ||
|
||
redis_service_mock.get_cloudapi_events_by_wallet_and_topic.return_value = [] | ||
|
||
result = await get_webhooks_by_wallet_and_topic( | ||
wallet_id=wallet_id, topic=topic, redis_service=redis_service_mock | ||
) | ||
|
||
assert result == [] | ||
redis_service_mock.get_cloudapi_events_by_wallet_and_topic.assert_called_once_with( | ||
wallet_id=wallet_id, topic=topic, num=100 | ||
) |
Empty file.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.