def __init__(self, configFile=None): self._Store = HDStore() self._Device = HDDevice() if configFile is not None: self.readConfig(configFile) elif os.path.isfile(self.configFile): self.readConfig(self.configFile)
def test_FetchDevices(self): store = HDStore({'config': {'filesdir': '/tmp/hd40test'}}) store.write('Device_' + str(self._deviceA['_id']), self._deviceA) store.write('Device_' + str(self._deviceB['_id']), self._deviceB) devices = store.fetchDevices() count = 0 for key in devices: count += 1 self.assertEqual(2, count)
def test_storeFetch(self): key = 'storekey-' + self._token store = HDStore() store.store(key, self._data) data = store.fetch(key) self.assertEqual(self._data, data) # Verify data is not cached data = store._Cache.read(key) self.assertEqual(data, None) # Verify data is on disk exists = os.path.isfile(os.path.join(store._directory, key + '.json')) self.assertTrue(exists)
def test_readWrite(self): key = 'readkey-' + self._token store = HDStore() store.write(key, self._data) data = store.read(key) self.assertEqual(data, self._data) # Verify data is cached data = store._Cache.read(key) self.assertEqual(data, self._data) # Verify data is on disk exists = os.path.isfile(os.path.join(store._directory, key + '.json')) self.assertTrue(exists)
def test_moveIn(self): store = HDStore({'config': {'filesdir': '/tmp/hd40test'}}) store.purge() deviceA = store.read('Device_' + str(self._deviceA['_id'])) self.assertEqual(None, deviceA) # Save dict as Json - try moving it into the store, then fetching it back out. fileName = 'Device_' + str(self._deviceA['_id']) + '.json' jsonFile = open(fileName, "w") jsonFile.write(json.dumps(self._deviceA)) jsonFile.close() store.moveIn(fileName, fileName) deviceA = store.fetch('Device_' + str(self._deviceA['_id'])) self.assertEqual(self._deviceA, deviceA) # Cleanup store.purge() pass
def __init__(self, config=None): self._Store = HDStore() if config is not None: self.setConfig(config)