コード例 #1
0
class TestStore(object):
    def setup(self):
        self.db = np.array([[1] * min(RECORD_SIZE, x) +
                            [0] * max(0, RECORD_SIZE - x)
                            for x in range(RECORD_COUNT)])
        self.store = Store(database=self.db)

    def test_retrieve(self):
        public_key, secret_key = generate_pair()
        index = 2
        enc_index = public_key.encrypt(
            binary(index, size=self.store.index_blength))
        enc_data = self.store.retrieve(enc_index, public_key)
        data = [secret_key.decrypt(bit) for bit in enc_data]
        assert_true(all(data == self.db[index]))

    def test_set(self):
        index = 2
        new_value = [0, 0, 0, 0, 1, 1, 1, 1]
        self.store.set(index, new_value)

        public_key, secret_key = generate_pair()
        enc_index = public_key.encrypt(
            binary(index, size=self.store.index_blength))
        enc_data = self.store.retrieve(enc_index, public_key)
        data = [secret_key.decrypt(bit) for bit in enc_data]
        assert_equals(data, new_value)
コード例 #2
0
ファイル: test_store.py プロジェクト: Eipifi/blindstore
class TestStore(object):

    def setup(self):
        self.db = np.array([[1] * min(RECORD_SIZE, x) + [0] * max(0, RECORD_SIZE - x) for x in range(RECORD_COUNT)])
        self.store = Store(database=self.db)

    def test_retrieve(self):
        pk, sk = generate_pair()
        index = 2
        query = encrypt_index(pk, index, self.store.index_bits)

        response = self.store.retrieve(query, pk)
        data = sk.decrypt(response)
        assert_true(all(data == self.db[index]))

    def test_set(self):
        index = 2
        new_value = [0, 0, 0, 0, 1, 1, 1, 1]
        self.store.set(index, new_value)

        pk, sk = generate_pair()
        enc_index = encrypt_index(pk, index, self.store.index_bits)
        enc_data = self.store.retrieve(enc_index, pk)
        data = [sk.decrypt(bit) for bit in enc_data]
        assert_equals(data, new_value)
コード例 #3
0
 def test_set_attempts_when_errors(self):
     store = Store(host="localhost", port="6379", db='_not_exist_test_db_')
     with patch('redis.Redis.set') as mock:
         mock.side_effect = redis.RedisError('Test error')
         try:
             val = store.set('test_key', 'test_val')
         except redis.RedisError:
             pass
         self.assertGreater(mock.call_count, 1)
コード例 #4
0
ファイル: test_store.py プロジェクト: YigitDemirag/blindstore
class TestStore(object):
    def setup(self):
        self.db = np.array([[1] * min(RECORD_SIZE, x) + [0] * max(0, RECORD_SIZE - x) for x in range(RECORD_COUNT)])
        self.store = Store(database=self.db)

    def test_retrieve(self):
        public_key, secret_key = generate_pair()
        index = 2
        enc_index = public_key.encrypt(binary(index, size=self.store.index_blength))
        enc_data = self.store.retrieve(enc_index, public_key)
        data = [secret_key.decrypt(bit) for bit in enc_data]
        assert_true(all(data == self.db[index]))

    def test_set(self):
        index = 2
        new_value = [0, 0, 0, 0, 1, 1, 1, 1]
        self.store.set(index, new_value)

        public_key, secret_key = generate_pair()
        enc_index = public_key.encrypt(binary(index, size=self.store.index_blength))
        enc_data = self.store.retrieve(enc_index, public_key)
        data = [secret_key.decrypt(bit) for bit in enc_data]
        assert_equals(data, new_value)
コード例 #5
0
 def test_LRU_cache(self):
     size = 10  # cache size
     used_index = [2, 4, 5]  # these keys are used frequently
     lost_index = [3, 6, 7]
     store = Store(host="localhost",
                   port="6379",
                   db='_not_exist_test_db_',
                   cache_size=size)
     with patch('redis.Redis.get') as mock_get:
         mock_get.return_value = None
         with patch('redis.Redis.set') as mock_set:
             for i in range(size * 50):
                 store.cache_set(i, i * i)
                 j = i % len(used_index)
                 if j < i:
                     self.assertEqual(j * j, store.cache_get(j))
         for j in lost_index:
             self.assertIsNone(store.cache_get(j))
コード例 #6
0
ファイル: test_store.py プロジェクト: YigitDemirag/blindstore
 def setup(self):
     self.db = np.array([[1] * min(RECORD_SIZE, x) + [0] * max(0, RECORD_SIZE - x) for x in range(RECORD_COUNT)])
     self.store = Store(database=self.db)
コード例 #7
0
                            print('> > > k: ' + k + ' - v: ' +
                                  data['payload'][k])
                    response_dict = {
                        'parent': "content",
                        'id': data['id'],
                        'html': input_temp_preference(self.store.getall())
                    }
                    await websocket.send(json.dumps(response_dict))
                """
                elif data['func'] == 'LISTE':
                    print('> Laden der Liste > ' + message)
                    response_dict = {
                        'parent': "liste",
                        'id': data['id'],
                        'html': greeting(["Alpha", "Beta", "Gamma"])
                    }
                    await websocket.send(json.dumps(response_dict))
                """

    def get_dom(self):
        return


if __name__ == '__main__':
    store = Store()
    store.set('temperature', 20)
    store.set('humidity', 45.5)

    ws = Server(store)
    asyncio.get_event_loop().run_until_complete(ws.start())
    asyncio.get_event_loop().run_forever()
コード例 #8
0
 def test_cache_get_what_set(self, key, val):
     store = Store(host="localhost", port="6379", db='_not_exist_test_db_')
     store.cache_set(key, val)
     self.assertEqual(val, store.cache_get(key),
                      "with key = %s and val = %s" % (key, val))
コード例 #9
0
 def test_set_raises_when_disconnected(self):
     store = Store(host="localhost", port="6379", db='_not_exist_test_db_')
     with patch('redis.Redis.set') as mock:
         mock.side_effect = redis.RedisError('Test error')
         self.assertRaises(redis.RedisError, store.set, 'test_key',
                           'test_val')
コード例 #10
0
 def test_cache_get_noraises_when_nodata(self):
     store = Store(host="localhost", port="6379", db='_not_exist_test_db_')
     try:
         val = store.cache_get('unknown_key')
     except Exception:
         self.fail('Store.cache_get() raised exception, but never must')
コード例 #11
0
 def setup(self):
     self.db = np.array([[1] * min(RECORD_SIZE, x) +
                         [0] * max(0, RECORD_SIZE - x)
                         for x in range(RECORD_COUNT)])
     self.store = Store(database=self.db)
コード例 #12
0
def _default_callback(message):
    if message.data['success']:
        result = message.data['result']
        if isinstance(result, dict):
            return Store(result)
        return result
コード例 #13
0
def parse_args(argv):
	for arg in argv[1:]:
		key, value = arg.split('=')
		defaults[key] = eval_val(value)
	return Store(defaults)