def test_dataReceived(self): """ Should store the data, then call doPossibleWork for all destinations for which the received data is an input. """ garden = Garden() garden.addPath('cake', '1', [ ('eggs', '1'), ('flour', '1'), ]) garden.addPath('german pancake', '1', [ ('eggs', '1'), ('flour', '1'), ]) w = WorkMaker(garden, None) w.doPossibleWork = create_autospec(w.doPossibleWork, side_effect=(lambda *x: defer.succeed(['hey']))) r = w.dataReceived(Data('Frog', 'flour', '1', 'bbbb', 'flour value')) w.doPossibleWork.assert_has_calls([ call('Frog', 'cake', '1'), call('Frog', 'german pancake', '1'), ]) self.assertTrue(r.called) return r
def test_dataReceived_errorFetchingData(self): """ If there's an error getting data for computing, the whole call should fail """ store = InMemoryStore() store.get = create_autospec(store.get, side_effect=lambda *a: defer.fail(Exception('foo'))) garden = Garden() garden.addPath('cake', '1', [ ('eggs', '1'), ]) w = WorkMaker(garden, store) r = w.dataReceived(Data('Jim', 'eggs', '1', 'xxxx', 'value')) self.assertFailure(r, Exception) return r.addErrback(lambda x:None)
def test_dataReceived_errorReceiving(self): """ If the work_receiver errsback on receiving any of the pieces of work, the whole dataReceived call should also errback. """ store = InMemoryStore() store.put(Data('Jim', 'eggs', '1', 'xxxx', 'value')) garden = Garden() garden.addPath('cake', '1', [ ('eggs', '1'), ]) garden.addPath('cake', '2', [ ('eggs', '1'), ]) receiver = FakeReceiver([IWork], lambda x: defer.fail(Exception('foo'))) w = WorkMaker(garden, store) ISource(w).subscribe(receiver) r = w.dataReceived(Data('Jim', 'eggs', '1', 'xxxx', 'value')) self.assertFailure(r, Exception)
def test_IReceiver(self): verifyObject(IReceiver, WorkMaker(None, None)) maker = WorkMaker(None, None) mapping = maker.receiverMapping() self.assertEqual(mapping[IData], maker.dataReceived)