|
3 | 3 | from marshmallow.exceptions import ValidationError |
4 | 4 |
|
5 | 5 | from ....admin.request_context import AdminRequestContext |
| 6 | +from ....core.event_bus import EventBus, MockEventBus |
| 7 | +from ....core.util import MULTITENANT_WALLET_CREATED_TOPIC |
6 | 8 | from ....messaging.models.base import BaseModelError |
7 | 9 | from ....storage.error import StorageError, StorageNotFoundError |
8 | 10 | from ....tests import mock |
@@ -279,6 +281,59 @@ async def test_wallet_create(self): |
279 | 281 | assert mock_multitenant_mgr.get_wallet_profile.called |
280 | 282 | assert test_module.attempt_auto_author_with_endorser_setup.called |
281 | 283 |
|
| 284 | + async def test_wallet_create_emits_wallet_created_event(self): |
| 285 | + body = { |
| 286 | + "wallet_name": "event-test", |
| 287 | + "wallet_type": "askar", |
| 288 | + "wallet_key": "test", |
| 289 | + "key_management_mode": "managed", |
| 290 | + "wallet_webhook_urls": [], |
| 291 | + "wallet_dispatch_type": "default", |
| 292 | + } |
| 293 | + self.request.json = mock.CoroutineMock(return_value=body) |
| 294 | + |
| 295 | + test_module.attempt_auto_author_with_endorser_setup = mock.CoroutineMock() |
| 296 | + |
| 297 | + mock_event_bus = MockEventBus() |
| 298 | + self.profile.context.injector.bind_instance(EventBus, mock_event_bus) |
| 299 | + |
| 300 | + wallet_mock = mock.MagicMock( |
| 301 | + serialize=mock.MagicMock( |
| 302 | + return_value={ |
| 303 | + "wallet_id": "event-wallet-id", |
| 304 | + "settings": {}, |
| 305 | + "key_management_mode": body["key_management_mode"], |
| 306 | + } |
| 307 | + ) |
| 308 | + ) |
| 309 | + wallet_mock.wallet_id = "event-wallet-id" |
| 310 | + wallet_mock.wallet_name = body["wallet_name"] |
| 311 | + wallet_mock.settings = {"wallet.name": body["wallet_name"]} |
| 312 | + |
| 313 | + mock_multitenant_mgr = mock.AsyncMock(BaseMultitenantManager, autospec=True) |
| 314 | + mock_multitenant_mgr.create_wallet = mock.CoroutineMock(return_value=wallet_mock) |
| 315 | + mock_multitenant_mgr.create_auth_token = mock.CoroutineMock( |
| 316 | + return_value="event-token" |
| 317 | + ) |
| 318 | + mock_multitenant_mgr.get_wallet_profile = mock.CoroutineMock( |
| 319 | + return_value=mock.MagicMock() |
| 320 | + ) |
| 321 | + self.profile.context.injector.bind_instance( |
| 322 | + BaseMultitenantManager, mock_multitenant_mgr |
| 323 | + ) |
| 324 | + |
| 325 | + await test_module.wallet_create(self.request) |
| 326 | + |
| 327 | + await mock_event_bus.task_queue.wait_for_completion() |
| 328 | + |
| 329 | + assert mock_event_bus.events |
| 330 | + _, event = mock_event_bus.events[-1] |
| 331 | + assert event.topic == ( |
| 332 | + f"{MULTITENANT_WALLET_CREATED_TOPIC}::{wallet_mock.wallet_id}" |
| 333 | + ) |
| 334 | + assert event.payload["wallet_id"] == wallet_mock.wallet_id |
| 335 | + assert event.payload["wallet_name"] == wallet_mock.wallet_name |
| 336 | + |
282 | 337 | async def test_wallet_create_x(self): |
283 | 338 | body = {} |
284 | 339 | self.request.json = mock.CoroutineMock(return_value=body) |
|
0 commit comments