Skip to content

Commit

Permalink
generate responses in loop for test
Browse files Browse the repository at this point in the history
  • Loading branch information
s-hertel committed Jul 21, 2022
1 parent 9465358 commit 8ee0a46
Showing 1 changed file with 36 additions and 75 deletions.
111 changes: 36 additions & 75 deletions test/units/galaxy/test_api.py
Expand Up @@ -79,85 +79,46 @@ def get_v3_collection_versions(namespace='namespace', name='collection'):
pagination_path = f"/api/galaxy/content/community/v3/plugin/{namespace}/content/community/collections/index/{namespace}/{name}/versions"
page_versions = (('1.0.0', '1.0.1',), ('1.0.2', '1.0.3',), ('1.0.4', '1.0.5'),)
responses = [
{
# TODO: initial response
},
{
"meta": {"count": 6},
"links": {
"first": f"{pagination_path}/?limit=100",
"previous": None,
"next": f"{pagination_path}/?limit=100&offset=100",
"last": f"{pagination_path}/?limit=100&offset=200",
},
"data": [
{
"version": f"{page_versions[0][0]}",
"href": f"{pagination_path}/{page_versions[0][0]}/",
"created_at": "2022-05-13T15:55:58.913107Z",
"updated_at": "2022-05-13T15:55:58.913121Z",
"requires_ansible": ">=2.9.10"
},
{
"version": f"{page_versions[0][1]}",
"href": f"{pagination_path}/{page_versions[0][1]}/",
"created_at": "2022-05-13T15:55:58.913107Z",
"updated_at": "2022-05-13T15:55:58.913121Z",
"requires_ansible": ">=2.9.10"
},
]
},
{
"meta": {"count": 6},
"links": {
"first": f"{pagination_path}/?limit=100",
"previous": f"{pagination_path}/?limit=100",
"next": f"{pagination_path}/?limit=100&offset=200",
"last": f"{pagination_path}/?limit=100&offset=200",
},
"data": [
{
"version": f"{page_versions[1][0]}",
"href": f"{pagination_path}/{page_versions[1][0]}/",
"created_at": "2022-05-13T15:55:58.913107Z",
"updated_at": "2022-05-13T15:55:58.913121Z",
"requires_ansible": ">=2.9.10"
},
{
"version": f"{page_versions[1][1]}",
"href": f"{pagination_path}/{page_versions[1][1]}/",
"created_at": "2022-05-13T15:55:58.913107Z",
"updated_at": "2022-05-13T15:55:58.913121Z",
"requires_ansible": ">=2.9.10"
},
]
},
{
"meta": {"count": 6},
"links": {
"first": f"{pagination_path}/?limit=100",
"previous": f"{pagination_path}/?limit=100&offset=100",
"next": None,
"last": f"{pagination_path}/?limit=100&offset=200",
},
"data": [
{
"version": f"{page_versions[2][0]}",
"href": f"{pagination_path}/{page_versions[2][0]}/",
"created_at": "2022-05-13T15:55:58.913107Z",
"updated_at": "2022-05-13T15:55:58.913121Z",
"requires_ansible": ">=2.9.10"
},
{}, # TODO: initial response
]

for page in range(0, len(page_versions)):
data = []

first = f"{pagination_path}/?limit=100"
last = f"{pagination_path}/?limit=100&offset=200"

if page == 0:
p_previous = None
p_next = f"{pagination_path}/?limit=100&offset=100"
elif page == 1:
p_previous = first
p_next = last
else:
p_previous = f"{pagination_path}/?limit=100&offset=100"
p_next = None

links = {"first": first, "last": last, "next": p_next, "previous": p_previous}

for version in page_versions[page]:
data.append(
{
"version": f"{page_versions[2][1]}",
"href": f"{pagination_path}/{page_versions[2][1]}/",
"version": f"{version}",
"href": f"{pagination_path}/{version}/",
"created_at": "2022-05-13T15:55:58.913107Z",
"updated_at": "2022-05-13T15:55:58.913121Z",
"requires_ansible": ">=2.9.10"
},
]
},
]
}
)

responses.append(
{
"meta": {"count": 6},
"links": links,
"data": data,
}
)

return responses


Expand Down

0 comments on commit 8ee0a46

Please sign in to comment.