Changeset View
Changeset View
Standalone View
Standalone View
swh/graphql/tests/functional/test_branch_connection.py
Show All 13 Lines | def get_branches(client, **kwargs) -> tuple: | ||||
$nameInclude: String, $excludePrefix: String) { | $nameInclude: String, $excludePrefix: String) { | ||||
snapshot(swhid: $swhid) { | snapshot(swhid: $swhid) { | ||||
branches(first: $first, after: $after, types: $types, nameInclude: $nameInclude, | branches(first: $first, after: $after, types: $types, nameInclude: $nameInclude, | ||||
nameExcludePrefix: $excludePrefix ) { | nameExcludePrefix: $excludePrefix ) { | ||||
pageInfo { | pageInfo { | ||||
endCursor | endCursor | ||||
} | } | ||||
nodes { | nodes { | ||||
targetType | |||||
name { | name { | ||||
text | text | ||||
} | } | ||||
target { | target { | ||||
type | |||||
node { | |||||
__typename | __typename | ||||
...on Branch { | ...on Branch { | ||||
name { | name { | ||||
text | text | ||||
} | } | ||||
} | } | ||||
...on Revision { | ...on Revision { | ||||
swhid | swhid | ||||
} | } | ||||
...on Release { | ...on Release { | ||||
swhid | swhid | ||||
} | } | ||||
...on Content { | ...on Content { | ||||
swhid | swhid | ||||
} | } | ||||
...on Directory { | ...on Directory { | ||||
swhid | swhid | ||||
} | } | ||||
...on Snapshot { | ...on Snapshot { | ||||
swhid | swhid | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | |||||
""" | """ | ||||
return utils.get_query_response(client, query_str, **kwargs) | return utils.get_query_response(client, query_str, **kwargs) | ||||
def test_get_data(client): | def test_get_data(client): | ||||
swhid = "swh:1:snp:0e7f84ede9a254f2cd55649ad5240783f557e65f" | swhid = "swh:1:snp:0e7f84ede9a254f2cd55649ad5240783f557e65f" | ||||
data, errors = get_branches(client, swhid=swhid, first=10, types=["revision"]) | data, errors = get_branches(client, swhid=swhid, first=10, types=["revision"]) | ||||
assert len(data["snapshot"]["branches"]["nodes"]) == 1 | assert len(data["snapshot"]["branches"]["nodes"]) == 1 | ||||
# filter 'type' will return a single revision object and is used to assert data | # filter 'type' will return a single revision object and is used to assert data | ||||
node = data["snapshot"]["branches"]["nodes"][0] | node = data["snapshot"]["branches"]["nodes"][0] | ||||
assert node == { | assert node == { | ||||
"name": {"text": "target/revision"}, | "name": {"text": "target/revision"}, | ||||
"target": { | "target": { | ||||
"type": "revision", | |||||
"node": { | |||||
"__typename": "Revision", | "__typename": "Revision", | ||||
"swhid": "swh:1:rev:66c7c1cd9673275037140f2abff7b7b11fc9439c", | "swhid": "swh:1:rev:66c7c1cd9673275037140f2abff7b7b11fc9439c", | ||||
}, | }, | ||||
"targetType": "revision", | }, | ||||
} | } | ||||
def test_get_branches_with_alias(client): | def test_get_branches_with_alias(client): | ||||
swhid = "swh:1:snp:0e7f84ede9a254f2cd55649ad5240783f557e65f" | swhid = "swh:1:snp:0e7f84ede9a254f2cd55649ad5240783f557e65f" | ||||
data, _ = get_branches(client, swhid=swhid, first=10, types=["alias"]) | data, _ = get_branches(client, swhid=swhid, first=10, types=["alias"]) | ||||
node = data["snapshot"]["branches"]["nodes"][0] | node = data["snapshot"]["branches"]["nodes"][0] | ||||
assert node == { | assert node == { | ||||
"name": {"text": "target/alias"}, | "name": {"text": "target/alias"}, | ||||
"target": {"__typename": "Branch", "name": {"text": "target/revision"}}, | "target": { | ||||
"targetType": "alias", | "type": "alias", | ||||
"node": {"__typename": "Branch", "name": {"text": "target/revision"}}, | |||||
}, | |||||
} | } | ||||
@pytest.mark.parametrize( | @pytest.mark.parametrize( | ||||
"filter_type, count, target_type, swhid_pattern", | "filter_type, count, target_type, swhid_pattern", | ||||
[ | [ | ||||
("revision", 1, "Revision", "swh:1:rev"), | ("revision", 1, "Revision", "swh:1:rev"), | ||||
("release", 1, "Release", "swh:1:rel"), | ("release", 1, "Release", "swh:1:rel"), | ||||
("directory", 1, "Directory", "swh:1:dir"), | ("directory", 1, "Directory", "swh:1:dir"), | ||||
("content", 0, "Content", "swh:1:cnt"), | ("content", 0, "Content", "swh:1:cnt"), | ||||
("snapshot", 1, "Snapshot", "swh:1:snp"), | ("snapshot", 1, "Snapshot", "swh:1:snp"), | ||||
], | ], | ||||
) | ) | ||||
def test_get_type_filter(client, filter_type, count, target_type, swhid_pattern): | def test_get_type_filter(client, filter_type, count, target_type, swhid_pattern): | ||||
swhid = "swh:1:snp:0e7f84ede9a254f2cd55649ad5240783f557e65f" | swhid = "swh:1:snp:0e7f84ede9a254f2cd55649ad5240783f557e65f" | ||||
data, _ = get_branches(client, swhid=swhid, first=10, types=[filter_type]) | data, _ = get_branches(client, swhid=swhid, first=10, types=[filter_type]) | ||||
assert len(data["snapshot"]["branches"]["nodes"]) == count | assert len(data["snapshot"]["branches"]["nodes"]) == count | ||||
for node in data["snapshot"]["branches"]["nodes"]: | for node in data["snapshot"]["branches"]["nodes"]: | ||||
assert node["target"]["__typename"] == target_type | assert node["target"]["node"]["__typename"] == target_type | ||||
assert node["target"]["swhid"].startswith(swhid_pattern) | assert node["target"]["node"]["swhid"].startswith(swhid_pattern) | ||||
@pytest.mark.parametrize( | @pytest.mark.parametrize( | ||||
"filter_types, count", | "filter_types, count", | ||||
[ | [ | ||||
(["revision", "release"], 2), | (["revision", "release"], 2), | ||||
(["revision", "snapshot", "release"], 3), | (["revision", "snapshot", "release"], 3), | ||||
], | ], | ||||
Show All 40 Lines |