def test_reset_context(self): workflow_id1 = uuid4() context1 = {'workflow_execution_id': workflow_id1} app1 = AppBase('Something', self.device2.id, context1) app1._cache = self.cache workflow_id2 = uuid4() context2 = {'workflow_execution_id': workflow_id2} app2 = AppBase('Something', self.device2.id, context2) app2._cache = self.cache app1.foo = 42 app1.bar = 'abc' app2.foo = 43 app2.bar = 'def' app1._reset_context(context2) self.assertEqual(app1.foo, 43) self.assertEqual(app1.bar, 'def')
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
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)