From 8ee0a460ae0ba0a2f3f605dfaf936bd15d31e14d Mon Sep 17 00:00:00 2001 From: s-hertel <19572925+s-hertel@users.noreply.github.com> Date: Thu, 21 Jul 2022 14:07:14 -0400 Subject: [PATCH] generate responses in loop for test --- test/units/galaxy/test_api.py | 111 +++++++++++----------------------- 1 file changed, 36 insertions(+), 75 deletions(-) diff --git a/test/units/galaxy/test_api.py b/test/units/galaxy/test_api.py index f6a1591044ccbc..7d5faaa5a9141a 100644 --- a/test/units/galaxy/test_api.py +++ b/test/units/galaxy/test_api.py @@ -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