def test_setattr_syncs_to_cache(self): workflow_id = uuid4() context = {'workflow_execution_id': workflow_id} app = AppBase('Something', self.device2.id, context) app._cache = self.cache app.foo = 42 app.bar = 23 self.assertSetEqual( set(self.cache.scan()), {app._format_cache_key('foo'), app._format_cache_key('bar')} ) for field, expected in (('foo', 42), ('bar', 23)): self.assertEqual(dill.loads(self.cache.get(app._format_cache_key(field))), expected)
def test_setattr_syncs_to_cache(self): workflow_id = uuid4() context = {'workflow_execution_id': workflow_id} app = AppBase('Something', self.device2.id, context) app._cache = self.cache app.foo = 42 app.bar = 23 self.assertSetEqual( set(self.cache.scan()), {app._format_cache_key('foo'), app._format_cache_key('bar')}) for field, expected in (('foo', 42), ('bar', 23)): self.assertEqual( dill.loads(self.cache.get(app._format_cache_key(field))), expected)
def test_getattr_gets_from_cache(self): workflow_id = uuid4() context = {'workflow_execution_id': workflow_id} app = AppBase('Something', self.device2.id, context) app._cache = self.cache app.foo = 42 app.bar = 23 self.cache.set(app._format_cache_key('foo'), dill.dumps('a')) self.cache.set(app._format_cache_key('bar'), dill.dumps('b')) self.assertEqual(app.foo, 'a') self.assertEqual(app.bar, 'b') with self.assertRaises(AttributeError): y = app.baz