def test_unregister(self): listener_1 = MagicMock() registration_event_listenable_map[int].add_listener(listener_1) listener_2 = MagicMock() registration_event_listenable_map[int].add_listener(listener_2) unregister(123) update_1 = RegistrationEvent(123, RegistrationEvent.Type.UNREGISTERED) listener_1.assert_called_once_with(update_1) listener_1.reset_mock() listener_2.assert_called_once_with(update_1) listener_2.reset_mock()
def test_register_can_be_unsubscribed(self): listener_1 = MagicMock() registration_event_listenable_map[int].add_listener(listener_1) listener_2 = MagicMock() registration_event_listenable_map[int].add_listener(listener_2) register(123) update_1 = RegistrationEvent(123, RegistrationEvent.Type.REGISTERED) registration_event_listenable_map[int].remove_listener(listener_2) register(456) unregister(456) listener_2.assert_called_once_with(update_1)