예제 #1
0
 def test_resultReceived_invalidPath(self):
     """
     If a result is received that was computed using arguments that don't
     correspond to a valid path in the garden, don't send the input on.
     """
     store = InMemoryStore()
     store.put(Data('joe', 'money', '1', 'xxxx', 'lots'))
     
     garden = Garden()
     garden.addPath('happiness', '1', [
         ('cake', '1'),
     ])
     
     receiver = FakeReceiver([IResult])
     
     f = InvalidResultFilter(garden, store)
     ISource(f).subscribe(receiver)
     
     r = f.resultReceived(Result('joe', 'happiness', '1', 'bbbb', 'yes', [
         ('money', '1', 'xxxx', sha1('lots').hexdigest()),
     ]))
     self.assertEqual(receiver.receive.call_count, 0, "Should not "
                      "send the result on, because money doesn't produce "
                      "happiness in this garden.  Only cake does that")
     self.assertTrue(r.called)
예제 #2
0
 def test_resultReceived_hashcheck(self):
     """
     When a result is received, it is only accepted if the inputs on which
     it is based are still valid.
     """
     store = InMemoryStore()
     store.put(Data('joe', 'cake', '1', 'xxxx', 'chocolate'))
     
     garden = Garden()
     garden.addPath('happiness', '1', [
         ('cake', '1'),
     ])
     
     receiver = FakeReceiver([IResult])
     
     f = InvalidResultFilter(garden, store)
     ISource(f).subscribe(receiver)
     
     # receive a result not based on the correct input value
     r = f.resultReceived(Result('joe', 'happiness', '1', 'bbbb', 'yes', [
         ('cake', '1', 'xxxx', sha1('vanilla').hexdigest()),
     ]))
     self.assertEqual(receiver.receive.call_count, 0, "Should not "
                      "have passed the result on")
     self.assertTrue(r.called)
     
     # receive a valid result (based on the current input value)
     result = Result('joe', 'happiness', '1', 'bbbb', 'yes', [
         ('cake', '1', 'xxxx', sha1('chocolate').hexdigest()),
     ])
     r = f.resultReceived(result)
     receiver.receive.assert_called_once_with(result)
     self.assertTrue(self.successResultOf(r))
예제 #3
0
 def test_dataReceived_unchanged(self):
     """
     Don't pass data along if it's unchanged.
     """
     store = InMemoryStore()
     store.put(Data('ham', 'cake', '1', 'xxxx', 'value'))
     
     fake = FakeReceiver([IData])
     
     s = DataStorer(store)
     ISource(s).subscribe(fake)
     
     s.dataReceived(Data('ham', 'cake', '1', 'xxxx', 'value'))
     self.assertEqual(fake.receive.call_count, 0, "Should not pass "
                      "along unchanged data")
예제 #4
0
 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)
예제 #5
0
 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)
예제 #6
0
 def test_dataReceived(self):
     """
     Should store the data, then pass it on, returning whatever the receiver
     returns.
     """
     store = InMemoryStore()
     store_d = defer.Deferred()
     store.put = create_autospec(store.put, return_value=store_d)
     
     fake = FakeReceiver([IData])
     
     s = DataStorer(store)
     ISource(s).subscribe(fake)
     
     data = Data('sam', 'cake', '1', 'xxxx', 'value')
     result = s.dataReceived(data)
     self.assertEqual(fake.receive.call_count, 0, "Should not have "
                      "passed the data on because it hasn't been stored yet")
     store.put.assert_called_once_with(data)
     self.assertFalse(result.called)
     store_d.callback({'changed': True})
     fake.receive.assert_called_once_with(data)
     self.assertTrue(self.successResultOf(result), "Should return "
                      "whatever the other receiver returns")