Skip to content

Commit 9f1c651

Browse files
committed
Tests for aries_webhook_server
* includes some additions to the actual class to * raise exceptions instead of logging them only * Generally need to think up a good way of testing the methods with pubsub throughout
1 parent e8c9a5c commit 9f1c651

File tree

5 files changed

+77
-20
lines changed

5 files changed

+77
-20
lines changed

libs/aries-basic-controller/aries_basic_controller/aries_webhook_server.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@ async def listen_webhooks(self):
5151
self.webhook_host,
5252
self.webhook_port)
5353
await self.webhook_site.start()
54+
logger.info(
55+
f"Listening Webhooks on {self.webhook_host}:{self.webhook_port}")
5456
except Exception as exc:
5557
logger.warning(f"Listening webhooks failed! {exc!r} occurred.")
58+
raise
5659

5760
async def _receive_webhook(self, request: ClientRequest):
5861
"""Helper to receive webhooks by requesting it
@@ -79,6 +82,7 @@ async def _receive_webhook(self, request: ClientRequest):
7982
return web.Response(status=200)
8083
except Exception as exc:
8184
logger.warning(f"Receiving webhooks failed! {exc!r} occurred.")
85+
raise
8286

8387
async def _handle_webhook(self, wallet_id, topic, payload):
8488
"""Helper handling a webhook
@@ -103,6 +107,7 @@ async def _handle_webhook(self, wallet_id, topic, payload):
103107
logger.warning(
104108
(f"Handling webhooks failed! {exc!r} occurred"
105109
f" when trying to handle this topic: {topic}"))
110+
raise
106111

107112
async def terminate(self):
108113
"""Terminate the controller client session and webhook listeners"""
@@ -115,3 +120,4 @@ async def terminate(self):
115120
except Exception as exc:
116121
logger.warning(
117122
f"Terminating webhooks listener failed! {exc!r} occurred.")
123+
raise

libs/aries-basic-controller/aries_basic_controller/scrap.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

libs/aries-basic-controller/aries_basic_controller/tests/test_aries_controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
LOGGER = logging.getLogger(__name__)
1515

1616

17-
class TestAriesAgentControllerBase():
17+
class TestAriesAgentController():
1818

1919
admin_url = "0.0.0.0"
2020
webhook_host = ""

libs/aries-basic-controller/aries_basic_controller/tests/test_aries_tenant_controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
LOGGER = logging.getLogger(__name__)
1616

1717

18-
class TestAriesAgentControllerBase():
18+
class TestAriesTenantController():
1919

2020
admin_url = "0.0.0.0"
2121
webhook_host = ""
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import logging
2+
import re
3+
import pytest
4+
import pytest_asyncio
5+
from aiohttp import (
6+
web,
7+
ClientSession,
8+
)
9+
10+
from ..aries_webhook_server import AriesWebhookServer
11+
12+
LOGGER = logging.getLogger(__name__)
13+
14+
15+
class TestAriesWebhookServer():
16+
17+
webhook_host = ""
18+
webhook_port = 8000
19+
webhook_base = ""
20+
21+
@pytest.mark.asyncio
22+
async def test_init_args_missing_webhook_host(self):
23+
with pytest.raises(
24+
TypeError,
25+
match=re.escape(
26+
"__init__() missing 1 required positional argument: 'webhook_host'"
27+
)):
28+
AriesWebhookServer(
29+
webhook_port=self.webhook_port,
30+
webhook_base=self.webhook_base)
31+
32+
@pytest.mark.asyncio
33+
async def test_init_args_missing_webhook_port(self):
34+
with pytest.raises(
35+
TypeError,
36+
match=re.escape(
37+
"__init__() missing 1 required positional argument: 'webhook_port'"
38+
)):
39+
AriesWebhookServer(
40+
webhook_host=self.webhook_host,
41+
webhook_base=self.webhook_base)
42+
43+
@pytest.mark.asyncio
44+
async def test_listen_webhooks(self, caplog):
45+
caplog.set_level(logging.INFO)
46+
aws = AriesWebhookServer(
47+
webhook_host=self.webhook_host,
48+
webhook_port=self.webhook_port)
49+
await aws.listen_webhooks()
50+
assert f"Listening Webhooks on {aws.webhook_host}:{aws.webhook_port}" in caplog.text
51+
await aws.terminate()
52+
53+
# TODO create mocks for pubsub webhook handling
54+
# Not quite sure how to do this best
55+
56+
@pytest.mark.asyncio
57+
async def test_terminate(self, caplog):
58+
caplog.set_level(logging.INFO)
59+
aws = AriesWebhookServer(
60+
webhook_host=self.webhook_host,
61+
webhook_port=self.webhook_port)
62+
assert await aws.terminate() is None
63+
64+
aws = AriesWebhookServer(
65+
webhook_host=self.webhook_host,
66+
webhook_port=self.webhook_port)
67+
await aws.listen_webhooks()
68+
await aws.terminate()
69+
assert "Webhook server terminated." in caplog.text

0 commit comments

Comments
 (0)