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")
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")
def test_IReceiver(self): verifyObject(IReceiver, DataStorer(None)) s = DataStorer(None) mapping = s.receiverMapping() self.assertEqual(mapping[IData], s.dataReceived)