Exemplo n.º 1
0
def assert_no_requests_in_progress_state(client: utils.Client, requests_amount,
                                         submitted_requests):
    """Check get_all request returns expected in_progress values."""
    query_params = {
        "per_page": requests_amount,
        "page": 1,
        "state": "in_progress"
    }
    response = client.fetch_all_requests(query_params, all_pages=False)
    assert response.status == 200

    assert all(item["state"] == "in_progress"
               for item in response.data["items"]
               ), "At least one of requests was not in in_progress state"

    response_ids = set(item["id"] for item in response.data["items"])
    # Check there are no completed requests in the response.
    assert not any(
        request_id in response_ids for request_id in submitted_requests
    ), (
        f"At least one of requests {response_ids} was in completed state. ",
        "All requests are expected to be in other state than completed.",
    )
    assert 0 <= len(response.data["items"]) <= requests_amount, (
        f"Number of obtained responses ({len(response.data['items'])}) "
        f"is not in the range from 0 to {requests_amount}")
Exemplo n.º 2
0
def assert_completed_requests(client: utils.Client, submitted_ids):
    """Check get_all request returns submitted requests in complete state."""
    query_params = {
        "per_page": len(submitted_ids),
        "page": 1,
        "state": "complete"
    }
    submitted_ids = submitted_ids.copy()
    while len(submitted_ids):
        response = client.fetch_all_requests(query_params, all_pages=False)
        assert response.status == 200
        assert response.data["items"], "Cachito did not return any requests"

        for response_item in response.data["items"]:
            assert response_item["state"] == "complete"
            if response_item["id"] in submitted_ids:
                submitted_ids.remove(response_item["id"])

        query_params["page"] += 1

    assert len(submitted_ids) == 0