Skip to content

Commit e33c1f2

Browse files
committed
added test for notification
1 parent e144b5c commit e33c1f2

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

packages/service-library/tests/redis/test_project_lock.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ def owner(request: pytest.FixtureRequest) -> Owner:
4646
return Owner(**request.param)
4747

4848

49+
from unittest import mock
50+
51+
52+
@pytest.fixture
53+
def mocked_notification_cb() -> mock.AsyncMock:
54+
return mock.AsyncMock()
55+
56+
4957
@pytest.mark.parametrize(
5058
"project_status",
5159
[
@@ -61,15 +69,17 @@ async def test_with_project_locked(
6169
project_uuid: ProjectID,
6270
owner: Owner,
6371
project_status: ProjectStatus,
72+
mocked_notification_cb: mock.AsyncMock,
6473
):
6574
@with_project_locked(
6675
redis_client_sdk,
6776
project_uuid=project_uuid,
6877
status=project_status,
6978
owner=owner,
70-
notification_cb=None,
79+
notification_cb=mocked_notification_cb,
7180
)
7281
async def _locked_fct() -> None:
82+
mocked_notification_cb.assert_called_once()
7383
assert await is_project_locked(redis_client_sdk, project_uuid) is True
7484
locked_state = await get_project_locked_state(redis_client_sdk, project_uuid)
7585
assert locked_state is not None
@@ -89,11 +99,14 @@ async def _locked_fct() -> None:
8999
status=project_status,
90100
)
91101

102+
mocked_notification_cb.assert_not_called()
92103
assert await get_project_locked_state(redis_client_sdk, project_uuid) is None
93104
assert await is_project_locked(redis_client_sdk, project_uuid) is False
94105
await _locked_fct()
95106
assert await is_project_locked(redis_client_sdk, project_uuid) is False
96107
assert await get_project_locked_state(redis_client_sdk, project_uuid) is None
108+
mocked_notification_cb.assert_called()
109+
assert mocked_notification_cb.call_count == 2
97110

98111

99112
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)