Example #1
0
def test_log_and_monitoring(backend, mocker, http_client, path, auth_path, headers,
                            auth_server, file_path, prefix):
    mon_traffic = stat_by_name('block_traffic_by_request_sum')
    mon_quota = stat_by_name('block_quota_by_request_sum')

    traffic_before = mon_traffic() or 0
    quota_before = mon_quota({'type': 'increase'}) or 0
    quota_dec_before = mon_quota({'type': 'decrease'}) or 0

    quota_log = mocker.patch(
        'blockserver.backend.database.PostgresUserDatabase.update_size')
    trafifc_log = mocker.patch(
        'blockserver.backend.database.PostgresUserDatabase.update_traffic')
    body = b'Dummy'
    size = len(body)
    _, prefix_name, file_name = file_path.split('/')
    auth_server.add_response(services.Request('POST', auth_path),
                             services.Response(200, body=b'{"user_id": 0, "active": true,'
                                                         b'"block_quota": 123, "monthly_traffic_quota": 789}'))
    yield http_client.fetch(path, method='POST', body=body, headers=headers)
    quota = mon_quota({'type': 'increase'})
    assert quota - quota_before == size
    yield http_client.fetch(path, method='POST', body=body, headers=headers)
    quota = mon_quota({'type': 'increase'})
    assert quota - quota_before == size
    yield http_client.fetch(path, method='GET', headers=headers)
    yield http_client.fetch(path, method='DELETE', headers=headers)

    assert mon_traffic() - traffic_before == size

    assert (mon_quota({'type': 'decrease'}) - quota_dec_before) == size

    expected_quota = [call(prefix, size), call(prefix, -size)]
    assert quota_log.call_args_list == expected_quota

    expected_traffic = [call(prefix, size)]
    assert trafifc_log.call_args_list == expected_traffic
Example #2
0
def test_auth_send_request_error_propagation(app, http_client, auth_server,
                                             auth_path):
    auth_server.add_response(services.Request('POST', auth_path),
                             services.Response(500))
    with pytest.raises(auth.AuthError):
        yield auth.AccountingServerAuth.send_request('foobar')
Example #3
0
def test_auth_send_request_not_found(app, http_client, auth_server, auth_path):
    auth_server.add_response(services.Request('POST', auth_path),
                             services.Response(404))
    with pytest.raises(auth.UserNotFound):
        yield auth.AccountingServerAuth.send_request('foobar')