Changeset View
Changeset View
Standalone View
Standalone View
swh/graphql/tests/functional/test_release_node.py
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | query getRelease($swhid: SWHID!) { | ||||
} | } | ||||
date { | date { | ||||
date | date | ||||
offset { | offset { | ||||
text | text | ||||
base64 | base64 | ||||
} | } | ||||
} | } | ||||
targetType | target { | ||||
type | |||||
} | |||||
} | } | ||||
} | } | ||||
""" | """ | ||||
data, _ = utils.get_query_response(client, query_str, swhid=str(release.swhid())) | data, _ = utils.get_query_response(client, query_str, swhid=str(release.swhid())) | ||||
assert data["release"] == { | assert data["release"] == { | ||||
"swhid": str(release.swhid()), | "swhid": str(release.swhid()), | ||||
"name": { | "name": { | ||||
Show All 14 Lines | assert data["release"] == { | ||||
"date": release.date.to_datetime().isoformat(), | "date": release.date.to_datetime().isoformat(), | ||||
"offset": { | "offset": { | ||||
"text": release.date.offset_bytes.decode(), | "text": release.date.offset_bytes.decode(), | ||||
"base64": base64.b64encode(release.date.offset_bytes).decode("ascii"), | "base64": base64.b64encode(release.date.offset_bytes).decode("ascii"), | ||||
}, | }, | ||||
} | } | ||||
if release.date | if release.date | ||||
else None, | else None, | ||||
"targetType": release.target_type.value, | "target": { | ||||
"type": release.target_type.value, | |||||
}, | |||||
} | } | ||||
def test_get_release_with_invalid_swhid(client): | def test_get_release_with_invalid_swhid(client): | ||||
query_str = """ | query_str = """ | ||||
query getRelease($swhid: SWHID!) { | query getRelease($swhid: SWHID!) { | ||||
release(swhid: $swhid) { | release(swhid: $swhid) { | ||||
swhid | swhid | ||||
} | } | ||||
} | } | ||||
""" | """ | ||||
errors = utils.get_error_response(client, query_str, swhid="swh:1:rel:invalid") | errors = utils.get_error_response(client, query_str, swhid="swh:1:rel:invalid") | ||||
# API will throw an error in case of an invalid SWHID | # API will throw an error in case of an invalid SWHID | ||||
assert len(errors) == 1 | assert len(errors) == 1 | ||||
assert "Expected type 'SWHID'. Input error: Invalid SWHID" in errors[0]["message"] | assert "Expected type 'SWHID'. Input error: Invalid SWHID" in errors[0]["message"] | ||||
@pytest.mark.parametrize("release_with_target", get_releases_with_target()) | @pytest.mark.parametrize("release_with_target", get_releases_with_target()) | ||||
def test_get_release_targets(client, release_with_target): | def test_get_release_targets(client, release_with_target): | ||||
query_str = """ | query_str = """ | ||||
query getRelease($swhid: SWHID!) { | query getRelease($swhid: SWHID!) { | ||||
release(swhid: $swhid) { | release(swhid: $swhid) { | ||||
targetType | |||||
target { | target { | ||||
type | |||||
node { | |||||
...on Revision { | ...on Revision { | ||||
swhid | swhid | ||||
} | } | ||||
...on Release { | ...on Release { | ||||
swhid | swhid | ||||
} | } | ||||
...on Directory { | ...on Directory { | ||||
swhid | swhid | ||||
} | } | ||||
...on Content { | ...on Content { | ||||
swhid | swhid | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | |||||
""" | """ | ||||
data, _ = utils.get_query_response( | data, _ = utils.get_query_response( | ||||
client, query_str, swhid=str(release_with_target.swhid()) | client, query_str, swhid=str(release_with_target.swhid()) | ||||
) | ) | ||||
if release_with_target.target_type == ObjectType.REVISION: | if release_with_target.target_type == ObjectType.REVISION: | ||||
target_swhid = get_revisions()[0].swhid() | target = get_revisions()[0] | ||||
elif release_with_target.target_type == ObjectType.RELEASE: | elif release_with_target.target_type == ObjectType.RELEASE: | ||||
target_swhid = get_releases()[0].swhid() | target = get_releases()[0] | ||||
elif release_with_target.target_type == ObjectType.DIRECTORY: | elif release_with_target.target_type == ObjectType.DIRECTORY: | ||||
target_swhid = get_directories()[0].swhid() | target = get_directories()[0] | ||||
elif release_with_target.target_type == ObjectType.CONTENT: | elif release_with_target.target_type == ObjectType.CONTENT: | ||||
target_swhid = get_contents()[0].swhid() | target = get_contents()[0] | ||||
assert data["release"] == { | assert data["release"] == { | ||||
"targetType": release_with_target.target_type.value, | "target": { | ||||
"target": {"swhid": str(target_swhid)}, | "type": release_with_target.target_type.value, | ||||
# "identifier": target.id.hex(), | |||||
"node": {"swhid": str(target.swhid())}, | |||||
}, | |||||
} | } | ||||
def test_get_release_target_unknown(client): | def test_get_release_target_unknown(client): | ||||
# Clinet can request all the possible options if the target type | # Clinet can request all the possible options if the target type | ||||
# is unknown. The data under the right type will be returned | # is unknown. The data under the right type will be returned | ||||
# The target is of type Revision in this case | # The target is of type Revision in this case | ||||
# ie: both swhid and message will be available in the response | # ie: both swhid and message will be available in the response | ||||
swhid = get_releases_with_target()[0].swhid() | swhid = get_releases_with_target()[0].swhid() | ||||
query_str = """ | query_str = """ | ||||
query getRelease($swhid: SWHID!) { | query getRelease($swhid: SWHID!) { | ||||
release(swhid: $swhid) { | release(swhid: $swhid) { | ||||
targetType | |||||
target { | target { | ||||
type | |||||
identifier | |||||
node { | |||||
...on Revision { | ...on Revision { | ||||
swhid | swhid | ||||
message { | message { | ||||
text | text | ||||
} | } | ||||
} | } | ||||
...on Release { | ...on Release { | ||||
swhid | swhid | ||||
} | } | ||||
...on Directory { | ...on Directory { | ||||
swhid | swhid | ||||
} | } | ||||
...on Content { | ...on Content { | ||||
swhid | swhid | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | |||||
""" | """ | ||||
data, _ = utils.get_query_response(client, query_str, swhid=str(swhid)) | data, _ = utils.get_query_response(client, query_str, swhid=str(swhid)) | ||||
assert data["release"] == { | assert data["release"] == { | ||||
"target": { | "target": { | ||||
"type": "revision", | |||||
"identifier": get_revisions()[0].id.hex(), | |||||
"node": { | |||||
"message": {"text": "hello"}, | "message": {"text": "hello"}, | ||||
"swhid": str(get_revisions()[0].swhid()), | "swhid": str(get_revisions()[0].swhid()), | ||||
}, | }, | ||||
"targetType": "revision", | }, | ||||
} | } | ||||
def test_get_release_with_unknown_swhid(client): | def test_get_release_with_unknown_swhid(client): | ||||
unknown_sha1 = "1" * 40 | unknown_sha1 = "1" * 40 | ||||
query_str = """ | query_str = """ | ||||
query getRelease($swhid: SWHID!) { | query getRelease($swhid: SWHID!) { | ||||
release(swhid: $swhid) { | release(swhid: $swhid) { | ||||
Show All 10 Lines |