Esempio n. 1
0
def test_stats_put_ok_direct_len_3_bad_rst(client):
    _data = b'["1:2:3:4:5:6:7:8", "9:10:11", ""]'
    checksum = calc_checksum(_data)
    resp = client.put('/stats/put/test_123?sync',
                      data=_data,
                      content_type='application/json')
    assert flask.json.loads(resp.data) == {'error': True, 'status': 400}
Esempio n. 2
0
def test_stats_mput_ok(client):
    _data = b'[["1:2:3:4:5:6:7", "8:9:10"],' \
        b'["11:12:13:14:15:16:17", "18:19:20"]]'
    checksum = calc_checksum(_data)
    resp = client.put(
        '/stats/mput/test_123', data=_data, content_type='application/json')
    assert flask.json.loads(resp.data) == {'checksum': checksum, 'error': False}
Esempio n. 3
0
def test_stats_put_fail(client):
    _data = b'["1:2:3:4:5:6:7", "8:9:10"]'
    checksum = calc_checksum(_data)
    resp = client.put('/stats/put/test_123',
                      data=_data,
                      content_type='application/json')
    assert flask.json.loads(resp.data) == {'error': True, 'status': 400}
Esempio n. 4
0
def stats_proc_enq(stat=None, qeez_token=None):
    '''PUT view to enqueue selected stat processing
    '''
    checksum = calc_checksum(request.data)
    job = enqueue_stat_calc(stat, qeez_token, redis_conn=get_queue_redis())
    return _json_response({
        'error': False,
        'checksum': checksum,
        'job_id': job.id,
    })
Esempio n. 5
0
def test_stats_ar_put(client):
    _data = b'["1:2:3:4:5:6:7", "8:9:10"]'
    checksum = calc_checksum(_data)
    stat_id = CFG['STAT_SAVE_FN']
    qeez_token = 'test_123'
    resp = client.put(
        '/stats/ar_put/' + stat_id + '/' + qeez_token, data=_data,
        content_type='application/json')
    assert flask.json.loads(resp.data) == {'checksum': checksum, 'error': False,
        'job_id': STAT_ID_FMT % (stat_id, qeez_token)}
Esempio n. 6
0
def test_stats_put_ok_direct(client):
    _data = b'["1:2:3:4:5:6:7:8", "9:10:11"]'
    checksum = calc_checksum(_data)
    resp = client.put('/stats/put/test_123?sync',
                      data=_data,
                      content_type='application/json')
    assert flask.json.loads(resp.data) == {
        'checksum': checksum,
        'error': False
    }
Esempio n. 7
0
def stats_proc_enq(stat=None, qeez_token=None):
    '''PUT view to enqueue selected stat processing
    '''
    checksum = calc_checksum(request.data)
    job = enqueue_stat_calc(stat, qeez_token, redis_conn=get_queue_redis())
    return _json_response({
        'error': False,
        'checksum': checksum,
        'job_id': job.id,
    })
Esempio n. 8
0
def test_stats_mput_ok(client):
    _data = b'[["1:2:3:4:5:6:7:8", "9:10:11"],' \
        b'["11:12:13:14:15:16:17:18", "19:20:21"]]'
    checksum = calc_checksum(_data)
    resp = client.put('/stats/mput/test_123',
                      data=_data,
                      content_type='application/json')
    assert flask.json.loads(resp.data) == {
        'checksum': checksum,
        'error': False
    }
Esempio n. 9
0
def test_stats_ar_put(client):
    _data = b'["1:2:3:4:5:6:7:8", "9:10:11"]'
    checksum = calc_checksum(_data)
    stat_id = CFG['STAT_CALC_FN']
    qeez_token = 'test_123'
    resp = client.put('/stats/ar_put/' + stat_id + '/' + qeez_token,
                      data=_data,
                      content_type='application/json')
    assert flask.json.loads(resp.data) == {
        'checksum': checksum,
        'error': False,
        'job_id': STAT_ID_FMT % (stat_id, qeez_token)
    }
Esempio n. 10
0
def _process_data(req, qeez_token, multi_data=None, stat=None):
    '''Processes data packets, returns response objects
    '''
    if not req.json:
        return bad_request(None)
    _json = req.get_json()
    if multi_data is True:
        json_data = _json
    else:
        json_data = [_json]
    checksum = calc_checksum(req.data)
    if _save_data(qeez_token, json_data, sync=('sync' in req.args)):
        resp = {'error': False, 'checksum': checksum}
        if stat is not None:
            job = enqueue_stat_calc(stat,
                                    qeez_token,
                                    redis_conn=get_queue_redis())
            resp['job_id'] = job.id
        return _json_response(resp)
    return bad_request(None)
Esempio n. 11
0
def _process_data(req, qeez_token, multi_data=None, stat=None):
    '''Processes data packets, returns response objects
    '''
    if not req.json:
        return bad_request(None)
    _json = req.get_json()
    if multi_data is True:
        json_data = _json
    else:
        json_data = [_json]
    checksum = calc_checksum(req.data)
    if _save_data(qeez_token, json_data):
        resp = {
            'error': False,
            'checksum': checksum}
        if stat is not None:
            job = enqueue_stat_calc(
                stat, qeez_token, redis_conn=get_queue_redis())
            resp['job_id'] = job.id
        return _json_response(resp)
    return bad_request(None)
Esempio n. 12
0
def test_calc_checksum():
    assert utils.calc_checksum(b'') == '00000000'
    assert utils.calc_checksum(b'12') == '4f5344cd'
    assert utils.calc_checksum(b'1234') == '9be3e0a3'
Esempio n. 13
0
def test_stats_put_fail(client):
    _data = b'["1:2:3:4:5:6", "8:9:10"]'
    checksum = calc_checksum(_data)
    resp = client.put(
        '/stats/put/test_123', data=_data, content_type='application/json')
    assert flask.json.loads(resp.data) == {'error': True, 'status': 400}
Esempio n. 14
0
def test_stats_put_ok(client):
    _data = b'["1:2:3:4:5:6:7", "8:9:10"]'
    checksum = calc_checksum(_data)
    resp = client.put(
        '/stats/put/test_123', data=_data, content_type='application/json')
    assert flask.json.loads(resp.data) == {'checksum': checksum, 'error': False}
Esempio n. 15
0
def test_calc_checksum():
    assert utils.calc_checksum(b'') == '00000000'
    assert utils.calc_checksum(b'12') == '4f5344cd'
    assert utils.calc_checksum(b'1234') == '9be3e0a3'