Skip to content

Commit

Permalink
add integration test for requests/latest endpoint
Browse files Browse the repository at this point in the history
Generate duplicate requests for a repo/ref and query the requests/latest
API endpoint to determine the "latest". The latest request should always
be the last of the duplicate requests for each repo+ref combination

Signed-off-by: Taylor Madore <tmadore@redhat.com>
  • Loading branch information
taylormadore committed Dec 13, 2023
1 parent 793e21e commit d912982
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/integration/test_get_latest_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# SPDX-License-Identifier: GPL-3.0-or-later

from typing import Any

from cachito.common.utils import get_repo_name

from . import utils


def test_get_latest_request(api_client: utils.Client, test_env: dict[str, Any]) -> None:
"""
Generates requests and ensures that the requests/latest endpoint returns the most recent one.
For each package in "various_packages", a request and a duplicate request are generated.
After all requests have been completed for all packages, the requests/latest endpoint is
queried for each repo_name/ref combination. The request_id of the final duplicate request
for each package should match what is returned by the latest endpoint.
"""
latest_created_request_ids = {}
repeat_count = 2

# Generate the requests
for pkg_manager, package in test_env["various_packages"].items():
repo_name = get_repo_name(package["repo"])
for _ in range(repeat_count):
initial_response = api_client.create_new_request(
payload={
"repo": package["repo"],
"ref": package["ref"],
"pkg_managers": [pkg_manager],
},
)
completed_response = api_client.wait_for_complete_request(initial_response)
utils.assert_properly_completed_response(completed_response)
latest_created_request_ids[(repo_name, package["ref"])] = completed_response.data["id"]

# Check that the latest is the latest
for package in test_env["various_packages"].values():
repo_name = get_repo_name(package["repo"])
latest_request = api_client.fetch_latest_request(
repo_name=repo_name, ref=package["ref"]
).json()

assert {
"id",
"repo",
"ref",
"updated",
}.issubset(latest_request), "Required fields missing from returned Request"
assert "configuration_files" not in latest_request, "A verbose Request was returned"
assert (
latest_created_request_ids[(repo_name, package["ref"])] == latest_request["id"]
), f"id={latest_request['id']} is not the latest request for {(repo_name, package['ref'])}"
12 changes: 12 additions & 0 deletions tests/integration/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ def fetch_all_requests(self, query_params=None, all_pages=True):

return Response({"items": all_items}, None, resp.status_code)

def fetch_latest_request(self, **params) -> requests.Response:
"""
Fetch the latest request for a repo/ref from the Cachito API.
:param dict query_params: Request parameters and values (repo_name, ref)
:return: Object that contains response from the Cachito API
:rtype: Response
"""
resp = self.requests_session.get(f"{self._cachito_api_url}/requests/latest", params=params)
resp.raise_for_status()
return resp

def fetch_content_manifest(self, request_id):
"""
Fetch a contest manifest by request_id from the Cachito API.
Expand Down

0 comments on commit d912982

Please sign in to comment.