Skip to content

Commit 88d8af1

Browse files
committed
test: record topic parsing for webhook
Signed-off-by: Daniel Bluhm <[email protected]>
1 parent 5f7330a commit 88d8af1

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

aries_cloudagent/admin/server.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
LOGGER = logging.getLogger(__name__)
4141

4242
EVENT_PATTERN_WEBHOOK = re.compile("^acapy::webhook::(.*)$")
43-
EVENT_PATTERN_RECORD = re.compile("^acapy::record::(.*)$")
43+
EVENT_PATTERN_RECORD = re.compile("^acapy::record::([^:]*)(?:::.*)?$")
4444

4545
EVENT_WEBHOOK_MAPPING = {
4646
"acapy::basicmessage::received": "basicmessages",
@@ -450,8 +450,8 @@ def sort_dict(raw: dict) -> dict:
450450

451451
event_bus = self.context.inject(EventBus, required=False)
452452
if event_bus:
453-
event_bus.subscribe(EVENT_PATTERN_WEBHOOK, self.__on_webhook_event)
454-
event_bus.subscribe(EVENT_PATTERN_RECORD, self.__on_record_event)
453+
event_bus.subscribe(EVENT_PATTERN_WEBHOOK, self._on_webhook_event)
454+
event_bus.subscribe(EVENT_PATTERN_RECORD, self._on_record_event)
455455

456456
for event_topic, webhook_topic in EVENT_WEBHOOK_MAPPING.items():
457457
event_bus.subscribe(
@@ -788,13 +788,13 @@ async def websocket_handler(self, request):
788788

789789
return ws
790790

791-
async def __on_webhook_event(self, profile: Profile, event: Event):
791+
async def _on_webhook_event(self, profile: Profile, event: Event):
792792
match = EVENT_PATTERN_WEBHOOK.search(event.topic)
793793
webhook_topic = match.group(1) if match else None
794794
if webhook_topic:
795795
await self.send_webhook(profile, webhook_topic, event.payload)
796796

797-
async def __on_record_event(self, profile: Profile, event: Event):
797+
async def _on_record_event(self, profile: Profile, event: Event):
798798
match = EVENT_PATTERN_RECORD.search(event.topic)
799799
webhook_topic = match.group(1) if match else None
800800
if webhook_topic:

aries_cloudagent/admin/tests/test_admin_server.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
from aries_cloudagent.core.event_bus import Event
12
import json
23

34
from aiohttp import ClientSession, DummyCookieJar, TCPConnector, web
45
from aiohttp.test_utils import unused_port
6+
import pytest
57

68
from asynctest import TestCase as AsyncTestCase
79
from asynctest import mock as async_mock
@@ -434,3 +436,25 @@ async def test_server_health_state(self):
434436
) as response:
435437
assert response.status == 503
436438
await server.stop()
439+
440+
441+
@pytest.fixture
442+
async def server():
443+
test_class = TestAdminServer()
444+
await test_class.setUp()
445+
yield test_class.get_admin_server()
446+
await test_class.tearDown()
447+
448+
449+
@pytest.mark.asyncio
450+
@pytest.mark.parametrize(
451+
"event_topic, webhook_topic",
452+
[("acapy::record::topic", "topic"), ("acapy::record::topic::state", "topic")],
453+
)
454+
async def test_on_record_event(server, event_topic, webhook_topic):
455+
profile = InMemoryProfile.test_profile()
456+
with async_mock.patch.object(
457+
server, "send_webhook", async_mock.CoroutineMock()
458+
) as mock_send_webhook:
459+
await server._on_record_event(profile, Event(event_topic, None))
460+
mock_send_webhook.assert_called_once_with(profile, webhook_topic, None)

0 commit comments

Comments
 (0)