Exemplo n.º 1
0
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'
Exemplo n.º 2
0
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'
Exemplo n.º 3
0
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'
Exemplo n.º 4
0
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'
Exemplo n.º 5
0
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
Exemplo n.º 6
0
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
Exemplo n.º 7
0
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
Exemplo n.º 8
0
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
Exemplo n.º 9
0
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
Exemplo n.º 10
0
def put_incr(key):
    try:
        response = MiniRedis.instance().incr(key)
    except CommandError as e:
        return create_error_response(e)

    return create_success_response(response)
Exemplo n.º 11
0
def get_key(key):
    try:
        response = MiniRedis.instance().get(key)
    except CommandError as e:
        return create_error_response(e)

    return jsonify({'value': response})
Exemplo n.º 12
0
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'
Exemplo n.º 13
0
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})
Exemplo n.º 14
0
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})
Exemplo n.º 15
0
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)
Exemplo n.º 16
0
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
Exemplo n.º 17
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})
Exemplo n.º 18
0
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']
Exemplo n.º 19
0
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
Exemplo n.º 20
0
def mini_redis():
    return MiniRedis()
Exemplo n.º 21
0
def delete_key(key):
    response = MiniRedis.instance().delete(key)

    return create_success_response(response)
Exemplo n.º 22
0
def get_zrank(key, member):

    response = MiniRedis.instance().zrank(key, member)

    return jsonify({'value': response})