diff --git a/swh/graphql/tests/functional/test_branch_connection.py b/swh/graphql/tests/functional/test_branch_connection.py --- a/swh/graphql/tests/functional/test_branch_connection.py +++ b/swh/graphql/tests/functional/test_branch_connection.py @@ -8,13 +8,22 @@ from .utils import get_query_response -def test_get(client): +def get_branches(client, swhid, first, params=""): query_str = """ { - snapshot(swhid: "swh:1:snp:0e7f84ede9a254f2cd55649ad5240783f557e65f") { - branches(first:10) { + snapshot(swhid: "%s") { + branches(first: %s, %s) { + pageInfo { + endCursor + } + edges { + cursor + } nodes { type + name { + text + } target { __typename ...on Revision { @@ -37,8 +46,17 @@ } } } - """ - data, errors = get_query_response(client, query_str) + """ % ( + swhid, + first, + params, + ) + return get_query_response(client, query_str) + + +def test_get(client): + swhid = "swh:1:snp:0e7f84ede9a254f2cd55649ad5240783f557e65f" + data, errors = get_branches(client, swhid, 10) # Alias type is not handled at the moment, hence the error assert len(errors) == 1 assert errors[0]["message"] == "Invalid node type: branch-alias" @@ -56,40 +74,8 @@ ], ) def test_get_type_filter(client, filter_type, count, target_type, swhid_pattern): - query_str = ( - """ - { - snapshot(swhid: "swh:1:snp:0e7f84ede9a254f2cd55649ad5240783f557e65f") { - branches(first:10, types: [%s]) { - nodes { - type - target { - __typename - ...on Revision { - swhid - } - ...on Release { - swhid - } - ...on Content { - swhid - } - ...on Directory { - swhid - } - ...on Snapshot { - swhid - } - } - } - } - } - } - """ - % filter_type - ) - data, _ = get_query_response(client, query_str) - + swhid = "swh:1:snp:0e7f84ede9a254f2cd55649ad5240783f557e65f" + data, _ = get_branches(client, swhid, 10, params=f"types: [{filter_type}]") assert len(data["snapshot"]["branches"]["nodes"]) == count for node in data["snapshot"]["branches"]["nodes"]: assert node["target"]["__typename"] == target_type @@ -104,104 +90,34 @@ ], ) def test_get_type_filter_multiple(client, filter_types, count): - query_str = ( - """ - { - snapshot(swhid: "swh:1:snp:0e7f84ede9a254f2cd55649ad5240783f557e65f") { - branches(first:10, types: [%s]) { - nodes { - type - } - } - } - }""" - % filter_types - ) - data, _ = get_query_response(client, query_str) + swhid = "swh:1:snp:0e7f84ede9a254f2cd55649ad5240783f557e65f" + data, _ = get_branches(client, swhid, 10, params=f"types: [{filter_types}]") assert len(data["snapshot"]["branches"]["nodes"]) == count @pytest.mark.parametrize("name", ["rel", "rev", "non-exist"]) def test_get_name_include_filter(client, name): - query_str = ( - """ - { - snapshot(swhid: "swh:1:snp:0e7f84ede9a254f2cd55649ad5240783f557e65f") { - branches(first:10, nameInclude: "%s") { - nodes { - name { - text - } - } - } - } - }""" - % name - ) - data, _ = get_query_response(client, query_str) + swhid = "swh:1:snp:0e7f84ede9a254f2cd55649ad5240783f557e65f" + data, _ = get_branches(client, swhid, 10, params=f'nameInclude: "{name}"') for node in data["snapshot"]["branches"]["nodes"]: assert name in node["name"]["text"] @pytest.mark.parametrize("count", [1, 2]) def test_get_first_arg(client, count): - query_str = ( - """ - { - snapshot(swhid: "swh:1:snp:0e7f84ede9a254f2cd55649ad5240783f557e65f") { - branches(first: %s) { - nodes { - type - } - } - } - }""" - % count - ) - data, _ = get_query_response(client, query_str) + swhid = "swh:1:snp:0e7f84ede9a254f2cd55649ad5240783f557e65f" + data, _ = get_branches(client, swhid, first=count) assert len(data["snapshot"]["branches"]["nodes"]) == count def test_get_after_arg(client): - query_str = """ - { - snapshot(swhid: "swh:1:snp:0e7f84ede9a254f2cd55649ad5240783f557e65f") { - branches(first: 1) { - pageInfo { - endCursor - } - nodes { - name { - text - } - } - } - } - }""" - first_data, _ = get_query_response(client, query_str) + swhid = "swh:1:snp:0e7f84ede9a254f2cd55649ad5240783f557e65f" + first_data, _ = get_branches(client, swhid, first=1) end_cursor = first_data["snapshot"]["branches"]["pageInfo"]["endCursor"] node_name = first_data["snapshot"]["branches"]["nodes"][0]["name"]["text"] - - query_str = ( - """ - { - snapshot(swhid: "swh:1:snp:0e7f84ede9a254f2cd55649ad5240783f557e65f") { - branches(first: 3, after: "%s") { - nodes { - type - name { - text - } - } - edges { - cursor - } - } - } - }""" - % end_cursor + second_data, _ = get_branches( + client, swhid, first=3, params=f'after: "{end_cursor}"' ) - second_data, _ = get_query_response(client, query_str) branches = second_data["snapshot"]["branches"] assert len(branches["nodes"]) == 3 assert branches["edges"][0]["cursor"] == end_cursor