Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/tests/test_utils.py
# Copyright (C) 2017-2018 The Software Heritage developers | # Copyright (C) 2017-2018 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from swh.objstorage.exc import ObjNotFoundError | from swh.objstorage.exc import ObjNotFoundError | ||||
from swh.model import hashutil | from swh.model import hashutil | ||||
from swh.model.hashutil import hash_to_bytes | |||||
ORIGINS = [ | ORIGINS = [ | ||||
{ | { | ||||
'id': 52189575, | 'id': 52189575, | ||||
'lister': None, | 'lister': None, | ||||
'project': None, | 'project': None, | ||||
'type': 'git', | 'type': 'git', | ||||
'url': 'https://github.com/SoftwareHeritage/swh-storage'}, | 'url': 'https://github.com/SoftwareHeritage/swh-storage'}, | ||||
▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | SNAPSHOTS = { | ||||
'target': b'\xe4?r\xe1,\x88\xab\xec\xe7\x9a\x87\xb8' | 'target': b'\xe4?r\xe1,\x88\xab\xec\xe7\x9a\x87\xb8' | ||||
b'\xc9\xad#.\x1bw=\x18', | b'\xc9\xad#.\x1bw=\x18', | ||||
'target_type': 'revision'}}, | 'target_type': 'revision'}}, | ||||
'id': b'\xa1\xa2\x8c\n\xb3\x87\xa8\xf9\xe0a\x8c\xb7' | 'id': b'\xa1\xa2\x8c\n\xb3\x87\xa8\xf9\xe0a\x8c\xb7' | ||||
b'\x05\xea\xb8\x1f\xc4H\xf4s'}, | b'\x05\xea\xb8\x1f\xc4H\xf4s'}, | ||||
54974445: { | 54974445: { | ||||
'branches': { | 'branches': { | ||||
b'HEAD': { | b'HEAD': { | ||||
'target': b'8dbb6aeb036e7fd80664eb8bfd1507881af1ba9f', | 'target': hash_to_bytes( | ||||
'8dbb6aeb036e7fd80664eb8bfd1507881af1ba9f'), | |||||
'target_type': 'revision'}}} | 'target_type': 'revision'}}} | ||||
} | } | ||||
SHA1_TO_LICENSES = { | SHA1_TO_LICENSES = { | ||||
'01c9379dfc33803963d07c1ccc748d3fe4c96bb5': ['GPL'], | '01c9379dfc33803963d07c1ccc748d3fe4c96bb5': ['GPL'], | ||||
'02fb2c89e14f7fab46701478c83779c7beb7b069': ['Apache2.0'], | '02fb2c89e14f7fab46701478c83779c7beb7b069': ['Apache2.0'], | ||||
'103bc087db1d26afc3a0283f38663d081e9b01e6': ['MIT'], | '103bc087db1d26afc3a0283f38663d081e9b01e6': ['MIT'], | ||||
▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | def content_metadata_add(self, metadata, conflict_update=None): | ||||
self.added_data.append( | self.added_data.append( | ||||
('content_metadata', conflict_update, metadata)) | ('content_metadata', conflict_update, metadata)) | ||||
def revision_metadata_add(self, metadata, conflict_update=None): | def revision_metadata_add(self, metadata, conflict_update=None): | ||||
assert conflict_update | assert conflict_update | ||||
self.added_data.append( | self.added_data.append( | ||||
('revision_metadata', conflict_update, metadata)) | ('revision_metadata', conflict_update, metadata)) | ||||
for item in metadata: | for item in metadata: | ||||
assert isinstance(item['id'], bytes) | |||||
self.revision_metadata.setdefault(item['id'], []).append(item) | self.revision_metadata.setdefault(item['id'], []).append(item) | ||||
def revision_metadata_get(self, ids): | def revision_metadata_get(self, ids): | ||||
for id_ in ids: | for id_ in ids: | ||||
assert isinstance(id_, bytes) | |||||
yield from self.revision_metadata.get(id_) | yield from self.revision_metadata.get(id_) | ||||
def origin_intrinsic_metadata_add(self, metadata, conflict_update=None): | def origin_intrinsic_metadata_add(self, metadata, conflict_update=None): | ||||
self.added_data.append( | self.added_data.append( | ||||
('origin_intrinsic_metadata', conflict_update, metadata)) | ('origin_intrinsic_metadata', conflict_update, metadata)) | ||||
def content_metadata_get(self, sha1s): | def content_metadata_get(self, sha1s): | ||||
return [{ | return [{ | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | class MockStorage(): | ||||
def snapshot_get_latest(self, origin_id): | def snapshot_get_latest(self, origin_id): | ||||
if origin_id in SNAPSHOTS: | if origin_id in SNAPSHOTS: | ||||
return SNAPSHOTS[origin_id] | return SNAPSHOTS[origin_id] | ||||
else: | else: | ||||
assert False, origin_id | assert False, origin_id | ||||
def revision_get(self, revisions): | def revision_get(self, revisions): | ||||
return [{ | return [{ | ||||
'id': b'8dbb6aeb036e7fd80664eb8bfd1507881af1ba9f', | 'id': hash_to_bytes('8dbb6aeb036e7fd80664eb8bfd1507881af1ba9f'), | ||||
'committer': { | 'committer': { | ||||
'id': 26, | 'id': 26, | ||||
'name': b'Andrew Nesbitt', | 'name': b'Andrew Nesbitt', | ||||
'fullname': b'Andrew Nesbitt <andrewnez@gmail.com>', | 'fullname': b'Andrew Nesbitt <andrewnez@gmail.com>', | ||||
'email': b'andrewnez@gmail.com' | 'email': b'andrewnez@gmail.com' | ||||
}, | }, | ||||
'synthetic': False, | 'synthetic': False, | ||||
'date': { | 'date': { | ||||
▲ Show 20 Lines • Show All 330 Lines • Show Last 20 Lines |