Exemplo n.º 1
0
def account_not_exists(context, tenant, account):
    uri = "https://127.0.0.1/account/{}/{}".format(tenant, account)

    request = Request(method='GET', url=uri)
    request.add_header('Accept', 'application/json')

    response = request.do()
    assert response.status in [404, 504], str(response.status)
Exemplo n.º 2
0
def create_token(context, tenant, token):
    key = '{}/{}'.format(tenant, token)
    assert key in context.tokens, 'token does not exist'

    uri = "https://127.0.0.1/token/{}/{}".format(tenant, context.tokens[key])

    request = Request(method='DELETE', url=uri)

    response = request.do()
    if response.status == 504:
        response = request.do()

    assert response.status == 200, str(response.status)
Exemplo n.º 3
0
def check_account_integrity(context, tenant, account):
    snapshots = glob.glob('/data/t_{}/account/{}/snapshot/*'.format(
        tenant, account))
    snapshots.sort(key=lambda f: -int(f.split('/')[-1]))

    assert len(snapshots), 'no snapshots found for {}/{}'.format(
        tenant, account)

    latest = snapshots[-1]

    assert os.path.isfile(latest), 'file not found {}'.format(latest)

    actual = dict()
    with open(latest, 'r') as fd:
        lines = fd.readlines()
        lines = [line.strip() for line in lines]

        actual.update({
            'isBalanceCheck': lines[0][-1] != "F",
            'format': lines[0][4:-2],
            'currency': lines[0][:3],
            'balance': lines[1],
            'blocking': lines[2],
        })

    uri = "https://127.0.0.1/account/{}/{}".format(tenant, account)

    request = Request(method='GET', url=uri)
    request.add_header('Accept', 'application/json')

    response = request.do()

    assert response.status == 200, str(response.status)

    body = json.loads(response.read().decode('utf-8'))

    assert body['format'] == actual[
        'format'], 'format mismatch expected {} actual {}'.format(
            body['format'], actual['format'])
    assert body['balance'] == actual[
        'balance'], 'balance mismatch expected {} actual {}'.format(
            body['balance'], actual['balance'])
    assert body['currency'] == actual[
        'currency'], 'currency mismatch expected {} actual {}'.format(
            body['currency'], actual['currency'])
    assert body['blocking'] == actual[
        'blocking'], 'blocking mismatch expected {} actual {}'.format(
            body['blocking'], actual['blocking'])
    assert body['isBalanceCheck'] == actual[
        'isBalanceCheck'], 'isBalanceCheck mismatch expected {} actual {}'.format(
            body['isBalanceCheck'], actual['isBalanceCheck'])
Exemplo n.º 4
0
def create_token(context, tenant, token):
    payload = {
        'value': token,
    }

    uri = "https://127.0.0.1/token/{}".format(tenant)

    request = Request(method='POST', url=uri)
    request.add_header('Accept', 'application/json')
    request.add_header('Content-Type', 'application/json')
    request.data = json.dumps(payload)

    response = request.do()
    if response.status == 504:
        response = request.do()

    assert response.status == 200, str(response.status)
    key = '{}/{}'.format(tenant, token)
    context.tokens[key] = response.read().decode('utf-8')
Exemplo n.º 5
0
def create_account(context, activity, currency, tenant, account):
    payload = {
        'name': account,
        'format': 'test',
        'currency': currency,
        'isBalanceCheck': activity != 'pasive',
    }

    uri = "https://127.0.0.1/account/{}".format(tenant)

    request = Request(method='POST', url=uri)
    request.add_header('Accept', 'application/json')
    request.add_header('Content-Type', 'application/json')
    request.data = json.dumps(payload)

    response = request.do()
    if response.status == 504:
        response = request.do()

    assert response.status == 200, str(response.status)
Exemplo n.º 6
0
def perform_http_request(context, uri):
    options = dict()
    if context.table:
        for row in context.table:
            options[row['key']] = row['value']

    request = Request(method=options['method'], url=uri)
    request.add_header('Accept', 'application/json')
    if context.text:
        request.add_header('Content-Type', 'application/json')
        request.data = context.text

    response = request.do()
    context.http_response = {
        'status': str(response.status),
        'body': response.read().decode('utf-8'),
        'content-type': response.content_type
    }
Exemplo n.º 7
0
def unit_running(context, unit):
    @eventually(10)
    def wait_for_unit_state_change():
        (code, result,
         error) = Shell.run(["systemctl", "show", "-p", "SubState", unit])
        assert code == 'OK', str(result) + ' ' + str(error)
        assert 'SubState=running' in result, result

    wait_for_unit_state_change()

    if 'cnb-rates-rest' in unit:
        request = Request(method='GET', url="https://127.0.0.1/health")

        @eventually(5)
        def wait_for_healthy():
            response = request.do()
            assert response.status == 200, str(response.status)

        wait_for_healthy()
Exemplo n.º 8
0
def token_exists(context, tenant, token):
    key = '{}/{}'.format(tenant, token)
    assert key in context.tokens, 'token does not exist'

    uri = "https://127.0.0.1/token/{}".format(tenant)

    request = Request(method='GET', url=uri)
    request.add_header('Accept', 'application/json')

    response = request.do()
    if response.status == 504:
        response = request.do()

    assert response.status == 200, str(response.status)

    actual = list()
    for line in response.read().decode('utf-8').split('\n'):
        if line:
            actual.append(json.loads(line)['id'])

    assert context.tokens[
        key] in actual, 'token {} not found in known tokens {}'.format(
            context.tokens[key], actual)