def test_drop_report_values_on_cdf_forecast_drop(cursor, valueset_report):
    report_params = json.loads(valueset_report['report_parameters'])
    object_pairs = report_params['object_pairs']
    cdf_group = uuid_to_bin(UUID(object_pairs[-1][1]))
    cursor.execute('SELECT COUNT(*) FROM report_values WHERE object_id = %s',
                   cdf_group)
    assert cursor.fetchone()[0] > 0
    cursor.execute('DELETE FROM cdf_forecasts_groups where id = %s', cdf_group)
    cursor.execute('SELECT COUNT(*) FROM report_values WHERE object_id = %s',
                   cdf_group)
    assert cursor.fetchone()[0] == 0
def test_drop_report_values_on_observation_drop(cursor, valueset_report):
    report_params = json.loads(valueset_report['report_parameters'])
    object_pairs = report_params['object_pairs']
    observation = uuid_to_bin(UUID(object_pairs[0][0]))
    cursor.execute('SELECT COUNT(*) FROM report_values WHERE object_id = %s',
                   observation)
    assert cursor.fetchone()[0] > 0
    cursor.execute('DELETE FROM observations where id = %s', observation)
    cursor.execute('SELECT COUNT(*) FROM report_values WHERE object_id = %s',
                   observation)
    assert cursor.fetchone()[0] == 0
def test_is_read_values_any_allowed_cdf_single(cursor, make_user_roles,
                                               new_cdf_forecast, other_obj):
    """That that a user can (and can not) perform the specified action"""
    info = make_user_roles('read_values', other_obj, True)
    authid = info['user']['auth0_id']
    obj = new_cdf_forecast(org=info['org'])
    for id_ in obj['constant_values'].keys():
        binid = uuid_to_bin(UUID(id_))
        cursor.execute('SELECT is_read_values_any_allowed(%s, %s)',
                       (authid, binid))
        if other_obj == 'cdf_forecasts':
            assert cursor.fetchone()[0] == 1
        else:
            assert cursor.fetchone()[0] == 0
def test_is_read_values_any_allowed_cdf_single_specific(
        cursor, make_user_roles, new_cdf_forecast, issame):
    """That that a user can (and can not) perform the specified action"""
    perm = make_user_roles('read_values', 'cdf_forecasts', False)
    authid = perm['user']['auth0_id']
    firstobj = new_cdf_forecast(org=perm['org'])
    cursor.execute(
        'INSERT INTO permission_object_mapping (permission_id, object_id)'
        ' VALUES (%s, %s)', (perm['permission']['id'], firstobj['id']))
    if issame:
        # permission has been added for firstobj cdf fx, but not
        obj = firstobj
    else:
        obj = new_cdf_forecast(org=perm['org'])

    for id_ in obj['constant_values'].keys():
        binid = uuid_to_bin(UUID(id_))
        cursor.execute('SELECT is_read_values_any_allowed(%s, %s)',
                       (authid, binid))
        assert cursor.fetchone()[0] == issame
def test_delete_cdf_forecast_single_in_report_vals(cursor, cdf_obj,
                                                   allow_delete_cdf_group,
                                                   allow_update_cdf_group,
                                                   new_report):
    auth0id, cdfgroupid, cdf = cdf_obj
    cdf_singles = list(cdf['constant_values'].keys())
    cursor.execute(
        'SELECT COUNT(id) FROM arbiter_data.cdf_forecasts_singles WHERE '
        'cdf_forecast_group_id = UUID_TO_BIN(%s, 1)', cdfgroupid)
    num = cursor.fetchone()[0]
    assert num > 0
    assert num == len(cdf_singles)

    rep = new_report(forecasts=[],
                     cdf_forecasts=[],
                     cdf_forecast_single=[{
                         'id': uuid_to_bin(UUID(c))
                     } for c in cdf_singles])
    cursor.execute(
        'SELECT count(object_id) from arbiter_data.report_values '
        'WHERE report_id = %s', rep['id'])
    num_rep_items = cursor.fetchone()[0]
    assert num_rep_items == len(cdf_singles) + 1  # obs

    for cid in cdf_singles:
        cursor.callproc('delete_cdf_forecasts_single', (auth0id, cid))
    cursor.execute(
        'SELECT COUNT(id) FROM arbiter_data.cdf_forecasts_singles WHERE '
        'cdf_forecast_group_id = UUID_TO_BIN(%s, 1)', cdfgroupid)
    assert cursor.fetchone()[0] == 0

    cursor.execute(
        'SELECT count(object_id) from arbiter_data.report_values '
        'WHERE report_id = %s', rep['id'])
    num_rep_items = cursor.fetchone()[0]
    assert num_rep_items == 1  # only obs left
Ejemplo n.º 6
0
def test_uuid_to_bin(cursor, uuid):
    cursor.execute('SELECT UUID_TO_BIN(%s, 1)', str(uuid))
    assert uuid_to_bin(uuid) == cursor.fetchone()[0]
    cursor.execute('SELECT BIN_TO_UUID(%s, 1)', uuid_to_bin(uuid))
    assert str(uuid) == cursor.fetchone()[0]
Ejemplo n.º 7
0
from uuid import uuid1
import pytest
from conftest import uuid_to_bin, bin_to_uuid


@pytest.mark.parametrize('uuid', [uuid1() for i in range(5)])
def test_uuid_to_bin(cursor, uuid):
    cursor.execute('SELECT UUID_TO_BIN(%s, 1)', str(uuid))
    assert uuid_to_bin(uuid) == cursor.fetchone()[0]
    cursor.execute('SELECT BIN_TO_UUID(%s, 1)', uuid_to_bin(uuid))
    assert str(uuid) == cursor.fetchone()[0]


@pytest.mark.parametrize('binid', [uuid_to_bin(uuid1()) for i in range(5)])
def test_bin_to_uuid(cursor, binid):
    cursor.execute('SELECT BIN_TO_UUID(%s, 1)', binid)
    assert str(bin_to_uuid(binid)) == cursor.fetchone()[0]
    cursor.execute('SELECT UUID_TO_BIN(%s, 1)', str(bin_to_uuid(binid)))
    assert binid == cursor.fetchone()[0]