def test_send_calls_attached_callback(self): self.c.return_value = self.deferred l = Local() l.attach_listener('foo', self.c) l.send('foo', 'asd', self.deferred) self.c.assert_called_once_with('asd') self.deferred.then.assert_called_once_with(IsCallable(), IsCallable())
def test_attach_listener_overrides_handlers(self): c_not_called = mock.MagicMock() self.c.return_value = self.deferred l = Local() l.attach_listener('foo', c_not_called) l.attach_listener('foo', self.c) l.send('foo', 'asd', self.deferred) self.c.assert_called_once_with('asd') self.assertEqual(c_not_called.call_count, 0)
def test_send_expects_deferred(self): def se(done, fail): done('asd') self.c.return_value = self.deferred self.deferred.then.side_effect=se d = mock.Mock() l = Local() l.attach_listener('foo', self.c) l.send('foo', 'asd', d) d.resolve.assert_called_once_with(IsA(str)) self.c.assert_called_once_with('asd') self.deferred.then.assert_called_once_with(IsCallable(), IsCallable())