22import logging
33from typing import AsyncIterable , Iterable
44
5- import pytest
6-
75from asynctest import mock as async_mock
6+ import pytest
87
9- from .....core .profile import Profile , ProfileSession
10- from .....core .in_memory import InMemoryProfile
8+ from .. import manager as test_module
119from .....core .event_bus import EventBus , MockEventBus
12- from .....connections . models . conn_record import ConnRecord
13- from .....messaging . request_context import RequestContext
10+ from .....core . in_memory import InMemoryProfile
11+ from .....core . profile import Profile , ProfileSession
1412from .....storage .error import StorageNotFoundError
15- from .....transport .inbound .receipt import MessageReceipt
16-
1713from ....routing .v1_0 .models .route_record import RouteRecord
18-
19- from .. import manager as test_module
2014from ..manager import (
2115 MediationAlreadyExists ,
2216 MediationManager ,
2519)
2620from ..messages .inner .keylist_update_rule import KeylistUpdateRule
2721from ..messages .inner .keylist_updated import KeylistUpdated
22+ from ..messages .keylist_update_response import KeylistUpdateResponse
2823from ..messages .mediate_deny import MediationDeny
2924from ..messages .mediate_grant import MediationGrant
3025from ..messages .mediate_request import MediationRequest
3126from ..models .mediation_record import MediationRecord
3227
3328TEST_CONN_ID = "conn-id"
29+ TEST_THREAD_ID = "thread-id"
3430TEST_ENDPOINT = "https://example.com"
3531TEST_VERKEY = "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx"
3632TEST_ROUTE_VERKEY = "9WCgWKUaAJj3VWxxtzvvMQN3AoFxoBtBDo9ntwJnVVCC"
@@ -373,7 +369,6 @@ async def test_store_update_results(
373369 self ,
374370 session : ProfileSession ,
375371 manager : MediationManager ,
376- mock_event_bus : MockEventBus ,
377372 ):
378373 """test_store_update_results."""
379374 await RouteRecord (
@@ -394,12 +389,6 @@ async def test_store_update_results(
394389 ),
395390 ]
396391 await manager .store_update_results (TEST_CONN_ID , results )
397- assert mock_event_bus .events
398- assert mock_event_bus .events [0 ][1 ].topic == manager .KEYLIST_UPDATED_EVENT
399- assert mock_event_bus .events [0 ][1 ].payload == {
400- "connection_id" : TEST_CONN_ID ,
401- "updated" : [result .serialize () for result in results ],
402- }
403392 routes = await RouteRecord .query (session )
404393
405394 assert len (routes ) == 1
@@ -484,6 +473,34 @@ async def test_store_update_results_errors(self, caplog, manager):
484473 assert "server_error" in caplog .text
485474 print (caplog .text )
486475
476+ async def test_notify_keylist_updated (
477+ self , manager : MediationManager , mock_event_bus : MockEventBus
478+ ):
479+ """test notify_keylist_updated."""
480+ response = KeylistUpdateResponse (
481+ updated = [
482+ KeylistUpdated (
483+ recipient_key = TEST_ROUTE_VERKEY ,
484+ action = KeylistUpdateRule .RULE_ADD ,
485+ result = KeylistUpdated .RESULT_SUCCESS ,
486+ ),
487+ KeylistUpdated (
488+ recipient_key = TEST_VERKEY ,
489+ action = KeylistUpdateRule .RULE_REMOVE ,
490+ result = KeylistUpdated .RESULT_SUCCESS ,
491+ ),
492+ ],
493+ )
494+ response .assign_thread_id (TEST_THREAD_ID )
495+ await manager .notify_keylist_updated (TEST_CONN_ID , response )
496+ assert mock_event_bus .events
497+ assert mock_event_bus .events [0 ][1 ].topic == manager .KEYLIST_UPDATED_EVENT
498+ assert mock_event_bus .events [0 ][1 ].payload == {
499+ "connection_id" : TEST_CONN_ID ,
500+ "thread_id" : TEST_THREAD_ID ,
501+ "updated" : [result .serialize () for result in response .updated ],
502+ }
503+
487504 async def test_get_my_keylist (self , session , manager ):
488505 """test_get_my_keylist."""
489506 await RouteRecord (
0 commit comments