def test_get_key_value(api_client): MiniRedis.instance().set('x1', 'Wolverine') response = api_client.get('/api/store/x1') data = response.json assert response.status_code == 200 assert data['value'] == 'Wolverine'
def test_incr_wrong_value(api_client): MiniRedis.instance().set('x1', 'Gambit') response = api_client.put('/api/store/x1/incr') data = response.json assert response.status_code == 400 assert data['error'] == 'value is not an integer or out of range'
def test_zcard_wrong_store(api_client): MiniRedis.instance().set('first_class', 'active') response = api_client.get('/api/store/first_class/zcard') data = response.json assert response.status_code == 400 assert data[ 'error'] == 'Operation against a key holding the wrong kind of value'
def test_wrong_store(api_client): MiniRedis.instance().zadd('avengers', 1, 'Captain America') response = api_client.get('/api/store/avengers') data = response.json assert response.status_code == 400 assert data[ 'error'] == 'Operation against a key holding the wrong kind of value'
def test_delete_key_with_value(api_client): MiniRedis.instance().set('x1', 'Wolverine') response = api_client.delete('/api/store/x1') data = response.json assert response.status_code == 200 assert data['message'] == 'OK' assert MiniRedis.instance().get('x1') is None
def test_incr_with_value(api_client): MiniRedis.instance().set('mutants', 1) response = api_client.put('/api/store/mutants/incr') data = response.json assert response.status_code == 200 assert data['message'] == 'OK' assert MiniRedis.instance().get('mutants') == 2
def mini_redis_with_ordered_mutants(): mini_redis = MiniRedis() mini_redis.zadd('mutants', 1, 'Wolverine') mini_redis.zadd('mutants', 1, 'Guepardo') mini_redis.zadd('mutants', 2, 'Gambit') mini_redis.zadd('mutants', 3, 'Quicksilver') return mini_redis
def test_zcard_existing_value(api_client): MiniRedis.instance().zadd('aliens', 1, 'outlander_one') MiniRedis.instance().zadd('aliens', 2, 'outlander_two') response = api_client.get('/api/store/aliens/zcard') data = response.json assert response.status_code == 200 assert data['value'] == 2
def mini_redis_with_mutants(): mini_redis = MiniRedis() mini_redis.set('x1', 'Wolverine') mini_redis.set('x2', 'Gambit') mini_redis.set('x3', 'Quicksilver') return mini_redis
def put_incr(key): try: response = MiniRedis.instance().incr(key) except CommandError as e: return create_error_response(e) return create_success_response(response)
def get_key(key): try: response = MiniRedis.instance().get(key) except CommandError as e: return create_error_response(e) return jsonify({'value': response})
def test_set_value(api_client): response = api_client.put('/api/store/x1', json={'value': 'Gambit'}) data = response.json assert response.status_code == 200 assert data['message'] == 'OK' assert MiniRedis.instance().get('x1') == 'Gambit'
def get_zcard(key, method=['GET']): try: response = MiniRedis.instance().zcard(key) except CommandError as e: return create_error_response(e) return jsonify({'value': response})
def get_zrange(key): start = request.args.get('start') stop = request.args.get('stop') try: response = MiniRedis.instance().zrange(key, start, stop) except CommandError as e: return create_error_response(e) return jsonify({'range': response})
def set_key(key): try: data = request.json except ValueError: return create_error_response('not a valid request data') value = data.get('value') response = MiniRedis.instance().set(key, value) return create_success_response(response)
def test_zadd_valid(api_client): response = api_client.put('/api/store/defenders/zadd', json={ 'score': 1, 'member': 'Daredevil' }) data = response.json assert response.status_code == 200 assert data['value'] == 1 assert MiniRedis.instance().zrank('defenders', 'Daredevil') == 0
def put_zadd(key): try: data = request.json except ValueError: return create_error_response('not a valid request data') score = data.get('score') member = data.get('member') try: response = MiniRedis.instance().zadd(key, score, member) except CommandError as e: return create_error_response(e) return jsonify({"value": response})
def test_zrange_existing_value(api_client): MiniRedis.instance().zadd('syths', 1, 'palpatine') MiniRedis.instance().zadd('syths', 1, 'kylo') MiniRedis.instance().zadd('syths', 2, 'anakin') response = api_client.get('/api/store/syths/zrange?start=0&stop=-1') data = response.json assert response.status_code == 200 assert data['range'] == ['palpatine', 'kylo', 'anakin']
def test_zrank_existing_value(api_client): MiniRedis.instance().zadd('jedis', 1, 'obi') MiniRedis.instance().zadd('jedis', 1, 'leia') MiniRedis.instance().zadd('jedis', 2, 'anakin') response = api_client.get('/api/store/jedis/zrank/anakin') data = response.json assert response.status_code == 200 assert data['value'] == 2
def mini_redis(): return MiniRedis()
def delete_key(key): response = MiniRedis.instance().delete(key) return create_success_response(response)
def get_zrank(key, member): response = MiniRedis.instance().zrank(key, member) return jsonify({'value': response})