def test_onNextChange_cancel(self): """ You can cancel the deferred returned by onNextChange """ world = World(MagicMock()) obj = world.create('foo') d = world.onNextChange(obj['id'], 'hey') d.cancel() world.setAttr(obj['id'], 'hey', 3) self.assertFailure(d, defer.CancelledError)
def test_onNextChange(self): """ You can get a Deferred which will fire when an attribute changes """ world = World(MagicMock()) obj = world.create('foo') d = world.onNextChange(obj['id'], 'hey') self.assertFalse(d.called) world.setAttr(obj['id'], 'ho', 8) self.assertFalse(d.called) world.setAttr(obj['id'], 'hey', 3) self.assertEqual(self.successResultOf(d), 3) # make sure it isn't called again world.setAttr(obj['id'], 'hey', 2)