Changeset View
Changeset View
Standalone View
Standalone View
swh/graphql/tests/functional/test_content.py
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | response = { | ||||
"url": f"{archive_url}content/sha1:{content.sha1.hex()}/raw/", | "url": f"{archive_url}content/sha1:{content.sha1.hex()}/raw/", | ||||
}, | }, | ||||
"mimeType": None, | "mimeType": None, | ||||
"language": None, | "language": None, | ||||
"license": None, | "license": None, | ||||
} | } | ||||
assert data["content"] == response | assert data["content"] == response | ||||
def test_get_content_with_invalid_swhid(client): | |||||
query_str = """ | |||||
query getContent($swhid: SWHID!) { | |||||
content(swhid: $swhid) { | |||||
swhid | |||||
} | |||||
} | |||||
""" | |||||
errors = utils.get_error_response(client, query_str, swhid="invalid") | |||||
# API will throw an error in case of an invalid SWHID | |||||
assert len(errors) == 1 | |||||
assert "Input error: Invalid SWHID" in errors[0]["message"] | |||||
@pytest.mark.parametrize("content", get_contents()) | @pytest.mark.parametrize("content", get_contents()) | ||||
lunar: Was this one really meant to be part of this diff? | |||||
Done Inline ActionsThis is not newly added or updated. Just grouped all the hash related tests, and this got placed in the top. jayeshv: This is not newly added or updated. Just grouped all the hash related tests, and this got… | |||||
def test_get_content_with_hash(client, content): | def test_get_content_with_hash(client, content): | ||||
query_str = """ | query_str = """ | ||||
query getContent($hashes: [ContentHash]!) { | query getContent($sha1: String, $sha1_git: String, $sha256: String, $blake2s256: String) { | ||||
contentByHashes(hashes: $hashes) { | contentByHashes(sha1: $sha1, sha1_git: $sha1_git, sha256: $sha256, | ||||
blake2s256: $blake2s256) { | |||||
swhid | swhid | ||||
} | } | ||||
} | } | ||||
""" | """ | ||||
data, _ = utils.get_query_response( | data, _ = utils.get_query_response( | ||||
client, | client, | ||||
query_str, | query_str, | ||||
hashes=[ | sha1=content.sha1.hex(), | ||||
f"blake2s256:{content.blake2s256.hex()}", | sha1_git=content.sha1_git.hex(), | ||||
f"sha1:{content.sha1.hex()}", | sha256=content.sha256.hex(), | ||||
f"sha1_git:{content.sha1_git.hex()}", | blake2s256=content.blake2s256.hex(), | ||||
f"sha256:{content.sha256.hex()}", | |||||
], | |||||
) | ) | ||||
assert data["contentByHashes"] == {"swhid": str(content.swhid())} | assert data["contentByHashes"] == {"swhid": str(content.swhid())} | ||||
def test_get_content_with_invalid_swhid(client): | @pytest.mark.parametrize("content", get_contents()) | ||||
def test_get_content_with_single_hash(client, content): | |||||
query_str = """ | query_str = """ | ||||
query getContent($swhid: SWHID!) { | query getContent($sha1: String, $sha1_git: String, $sha256: String, $blake2s256: String) { | ||||
content(swhid: $swhid) { | contentByHashes(sha1: $sha1, sha1_git: $sha1_git, sha256: $sha256, | ||||
blake2s256: $blake2s256) { | |||||
swhid | swhid | ||||
} | } | ||||
} | } | ||||
""" | """ | ||||
errors = utils.get_error_response(client, query_str, swhid="invalid") | data, _ = utils.get_query_response( | ||||
# API will throw an error in case of an invalid SWHID | client, | ||||
assert len(errors) == 1 | query_str, | ||||
assert "Input error: Invalid SWHID" in errors[0]["message"] | sha1=content.sha1.hex(), | ||||
) | |||||
assert data["contentByHashes"] == {"swhid": str(content.swhid())} | |||||
@pytest.mark.parametrize("content", get_contents()) | |||||
def test_get_content_with_one_non_matching_hash(client, content): | |||||
query_str = """ | |||||
query getContent($sha1: String, $sha1_git: String, $sha256: String, $blake2s256: String) { | |||||
contentByHashes(sha1: $sha1, sha1_git: $sha1_git, sha256: $sha256, | |||||
blake2s256: $blake2s256) { | |||||
swhid | |||||
} | |||||
} | |||||
""" | |||||
utils.assert_missing_object( | |||||
client, | |||||
query_str, | |||||
obj_type="contentByHashes", | |||||
sha1=content.sha1.hex(), | |||||
Done Inline ActionsThis is a bit confusing. I read this test as checking the behavior when only one hash over multiple match objects in the archive. I don’t believe it’s “wrong” as the request is just looking for an unknown object. Do you see what I mean? Maybe it should be the test should be labelled differently. Especially given passing the content of a blake2 hash as a sha_git feels indeed wrong. Maybe use an explicit aaaaaa… of the right length instead? lunar: This is a bit confusing. I read this test as checking the behavior when only one hash over… | |||||
Done Inline Actionsrenamed the test and now using a different test hash jayeshv: renamed the test and now using a different test hash | |||||
sha1_git="a" * 20, # hash is valid, but not matching the object | |||||
) | |||||
def test_get_content_with_invalid_hashes(client): | def test_get_content_with_invalid_hashes(client): | ||||
content = get_contents()[0] | content = get_contents()[0] | ||||
query_str = """ | query_str = """ | ||||
query getContent($hashes: [ContentHash]!) { | query getContent($sha1: String, $sha1_git: String, $sha256: String, $blake2s256: String) { | ||||
contentByHashes(hashes: $hashes) { | contentByHashes(sha1: $sha1, sha1_git: $sha1_git, sha256: $sha256, | ||||
blake2s256: $blake2s256) { | |||||
swhid | swhid | ||||
} | } | ||||
} | } | ||||
""" | """ | ||||
errors = utils.get_error_response( | errors = utils.get_error_response( | ||||
client, | client, | ||||
query_str, | query_str, | ||||
hashes=[ | sha1="invalid", # Only one hash is invalid | ||||
"invalid", # Only one hash is invalid | sha1_git=content.sha1_git.hex(), | ||||
f"sha1:{content.sha1.hex()}", | sha256=content.sha256.hex(), | ||||
f"sha1_git:{content.sha1_git.hex()}", | |||||
f"sha256:{content.sha256.hex()}", | |||||
], | |||||
) | ) | ||||
# API will throw an error in case of an invalid content hash | # API will throw an error in case of an invalid content hash | ||||
assert len(errors) == 1 | assert len(errors) == 1 | ||||
assert "Input error: Invalid content hash" in errors[0]["message"] | assert "Input error: Invalid content hash" in errors[0]["message"] | ||||
def test_get_content_with_invalid_hash_algorithm(client): | def test_get_content_with_no_hashes(client): | ||||
content = get_contents()[0] | |||||
query_str = """ | query_str = """ | ||||
query getContent($hashes: [ContentHash]!) { | query getContent($sha1: String, $sha1_git: String, $sha256: String, $blake2s256: String) { | ||||
contentByHashes(hashes: $hashes) { | contentByHashes(sha1: $sha1, sha1_git: $sha1_git, sha256: $sha256, | ||||
blake2s256: $blake2s256) { | |||||
swhid | swhid | ||||
} | } | ||||
} | } | ||||
""" | """ | ||||
data, errors = utils.get_query_response( | errors = utils.get_error_response( | ||||
client, query_str, hashes=[f"test:{content.sha1.hex()}"] | client, | ||||
query_str, | |||||
) | ) | ||||
assert data is None | |||||
assert len(errors) == 1 | assert len(errors) == 1 | ||||
assert "Input error: Invalid hash algorithm" in errors[0]["message"] | assert ( | ||||
"Input error: At least one of the four hashes must be provided" | |||||
in errors[0]["message"] | |||||
) | |||||
def test_get_content_as_target(client): | def test_get_content_as_target(client): | ||||
# SWHID of a test dir with a file entry | # SWHID of a test dir with a file entry | ||||
directory_swhid = "swh:1:dir:87b339104f7dc2a8163dec988445e3987995545f" | directory_swhid = "swh:1:dir:87b339104f7dc2a8163dec988445e3987995545f" | ||||
query_str = """ | query_str = """ | ||||
query getDirectory($swhid: SWHID!) { | query getDirectory($swhid: SWHID!) { | ||||
directory(swhid: $swhid) { | directory(swhid: $swhid) { | ||||
Show All 38 Lines |
Was this one really meant to be part of this diff?