Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/common/test_service.py
Show First 20 Lines • Show All 870 Lines • ▼ Show 20 Lines | def test_lookup_invalid_objects(invalid_sha1): | ||||
with pytest.raises(BadInputExc) as e: | with pytest.raises(BadInputExc) as e: | ||||
service.lookup_object(REVISION, invalid_sha1) | service.lookup_object(REVISION, invalid_sha1) | ||||
assert e.match('Invalid checksum') | assert e.match('Invalid checksum') | ||||
with pytest.raises(BadInputExc) as e: | with pytest.raises(BadInputExc) as e: | ||||
service.lookup_object(SNAPSHOT, invalid_sha1) | service.lookup_object(SNAPSHOT, invalid_sha1) | ||||
assert e.match('Invalid checksum') | assert e.match('Invalid checksum') | ||||
def test_lookup_missing_hashes_non_present(): | |||||
missing_cnt = random_sha1() | |||||
missing_dir = random_sha1() | |||||
missing_rev = random_sha1() | |||||
missing_rel = random_sha1() | |||||
missing_snp = random_sha1() | |||||
grouped_pids = { | |||||
CONTENT: [hash_to_bytes(missing_cnt)], | |||||
DIRECTORY: [hash_to_bytes(missing_dir)], | |||||
REVISION: [hash_to_bytes(missing_rev)], | |||||
RELEASE: [hash_to_bytes(missing_rel)], | |||||
SNAPSHOT: [hash_to_bytes(missing_snp)], | |||||
} | |||||
actual_result = service.lookup_missing_hashes(grouped_pids) | |||||
assert actual_result == {missing_cnt, missing_dir, missing_rev, | |||||
vlorentz: You should also add a test for when they are not (all) missing. | |||||
missing_rel, missing_snp} | |||||
@given(content(), directory()) | |||||
def test_lookup_missing_hashes_some_present(archive_data, content, directory): | |||||
missing_rev = random_sha1() | |||||
missing_rel = random_sha1() | |||||
missing_snp = random_sha1() | |||||
grouped_pids = { | |||||
CONTENT: [hash_to_bytes(content['sha1_git'])], | |||||
DIRECTORY: [hash_to_bytes(directory)], | |||||
REVISION: [hash_to_bytes(missing_rev)], | |||||
RELEASE: [hash_to_bytes(missing_rel)], | |||||
SNAPSHOT: [hash_to_bytes(missing_snp)], | |||||
} | |||||
actual_result = service.lookup_missing_hashes(grouped_pids) | |||||
assert actual_result == {missing_rev, missing_rel, missing_snp} |
You should also add a test for when they are not (all) missing.