Exemple #1
0
def test_subscriptions():
    svc = BaseService()
    client = mock.Mock()
    svc.subscribe('foo_event', client.on_foo)

    svc.notify_subscribers('foo_event', 1, 2, 3, value='hello')
    deliver_pending_notifications()
    client.on_foo.assert_called_once_with(1, 2, 3, value='hello')

    client.reset_mock()
    svc.notify_subscribers('bar_event')
    deliver_pending_notifications()
    assert not client.on_foo.called
Exemple #2
0
def test_unsubscribe():
    svc = BaseService()
    client = mock.Mock()
    svc.subscribe('foo_event', client.on_foo)

    svc.notify_subscribers('foo_event')
    deliver_pending_notifications()
    client.on_foo.assert_called_once_with()

    client.reset_mock()
    svc.unsubscribe(client.on_foo)
    svc.notify_subscribers('foo_event')
    deliver_pending_notifications()
    assert not client.on_foo.called