diff --git a/swh/web/common/service.py b/swh/web/common/service.py --- a/swh/web/common/service.py +++ b/swh/web/common/service.py @@ -89,6 +89,7 @@ """ algo, hash = query.parse_hash(q) found = storage.content_find({algo: hash}) + found = found[0] if found else None return {'found': converters.from_content(found), 'algo': algo} @@ -104,7 +105,7 @@ """ algo, hash = query.parse_hash(q) found = storage.content_find({algo: hash}) - return {'found': found is not None} + return {'found': bool(found)} def _lookup_content_sha1(q): @@ -122,7 +123,7 @@ hashes = storage.content_find({algo: hash}) if not hashes: return None - return hashes['sha1'] + return hashes[0]['sha1'] return hash @@ -718,6 +719,12 @@ directory_entries))} elif entity['type'] == 'file': # content content = storage.content_find({'sha1_git': entity['target']}) + content = content[0] if content else None + if not content: + raise NotFoundExc( + "Content not found with revision '%s' " + % (entity['target']) + ) if with_data: c = _first_element(storage.content_get([content['sha1']])) content['data'] = c['data'] @@ -751,7 +758,7 @@ if not c: raise NotFoundExc('Content with %s checksum equals to %s not found!' % (algo, hashutil.hash_to_hex(hash))) - return converters.from_content(c) + return converters.from_content(c[0]) def lookup_content_raw(q): diff --git a/swh/web/tests/common/test_service.py b/swh/web/tests/common/test_service.py --- a/swh/web/tests/common/test_service.py +++ b/swh/web/tests/common/test_service.py @@ -340,8 +340,19 @@ self.assertIn('Revision %s not found' % unknown_revision, cm.exception.args[0]) + @given(unknown_content()) + def test_lookup_directory_with_revision_unknown_content( + self, unknown_content): + sha1_git = unknown_content['sha1_git'] + + with self.assertRaises(NotFoundExc) as cm: + service.lookup_directory_with_revision(sha1_git) + self.assertIn('Content not found for %s' % sha1_git, + cm.exception.args[0]) + @given(revision()) - def test_lookup_directory_with_revision_ko_path_to_nowhere(self, revision): + def test_lookup_directory_with_revision_ko_path_to_nowhere( + self, revision): invalid_path = 'path/to/something/unknown' with self.assertRaises(NotFoundExc) as cm: