Esempio n. 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)
Esempio n. 2
0
    def test_IReceiver(self):
        verifyObject(IReceiver, InvalidResultFilter(None, None))

        f = InvalidResultFilter(None, None)
        mapping = f.receiverMapping()
        self.assertEqual(mapping[IResult], f.resultReceived)
        self.assertEqual(mapping[IResultError], f.resultReceived)
Esempio n. 3
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))