class InMemoryDatabaseTest(unittest2.TestCase): def setUp(self): self.db = InMemoryDatabase() def set(self, k, v): flo = self.db.write_stream(k, 'text/plain') flo.write(v) flo.close() def get(self, k): return self.db.read_stream(k) def test_can_write_data(self): self.set('key', 'test data') def test_can_read_data(self): self.set('key', 'test data') rs = self.get('key') self.assertEqual('test data', rs.read()) def test_can_overwrite_key(self): self.set('key', 'test data') rs = self.get('key') self.assertEqual('test data', rs.read()) self.set('key', 'test data2') rs = self.get('key') self.assertEqual('test data2', rs.read())
class PersistenceSettings(object): id_provider = UuidProvider() key_builder = StringDelimitedKeyBuilder() database = InMemoryDatabase(key_builder=key_builder) @classmethod def clone(cls, id_provider=None, key_builder=None, database=None): ip = id_provider kb = key_builder db = database class Settings(PersistenceSettings): id_provider = ip or cls.id_provider key_builder = kb or cls.key_builder database = db or cls.database return Settings
def setUp(self): self.db = InMemoryDatabase()
class Settings(PersistenceSettings): id_provider = UuidProvider() key_builder = StringDelimitedKeyBuilder() database = InMemoryDatabase(key_builder=key_builder)
class Settings(PersistenceSettings): id_provider = UuidProvider() key_builder = StringDelimitedKeyBuilder() database = InMemoryDatabase(key_builder=key_builder) event_log = EventLog(path=self._dir, channel=InMemoryChannel())