diff --git a/swh/loader/git/tests/test_loader.py b/swh/loader/git/tests/test_loader.py --- a/swh/loader/git/tests/test_loader.py +++ b/swh/loader/git/tests/test_loader.py @@ -10,7 +10,7 @@ from swh.loader.git.loader import GitLoader, GitLoaderFromArchive from swh.loader.core.tests import BaseLoaderTest, LoaderNoStorage -from swh.model.hashutil import hash_to_bytes +from swh.model.hashutil import hash_to_bytes, hash_to_bytehex class MockStorage0: @@ -27,6 +27,9 @@ def revision_missing(self, revisions): return revisions + def object_find_by_sha1_git(self, ids): + return {} + CONTENT1 = { '33ab5639bfd8e7b95eb1d8d0b87781d4ffea4d5d', # README v1 @@ -131,6 +134,42 @@ assert all(isinstance(r, bytes) for r in revisions) return list(set(revisions) - set(map(hash_to_bytes, REVISIONS1))) + def object_find_by_sha1_git(self, ids): + res = {} + for id_ in ids: + found = [] + decoded_id = hash_to_bytehex(id_) + if decoded_id in REVISIONS1: + found.append({ + 'sha1_git': id_, + 'type': 'revision', + 'id': id_, + 'object_id': 42, + }) + elif decoded_id in REVISIONS1.values(): + found.append({ + 'sha1_git': id_, + 'type': 'directory', + 'id': id_, + 'object_id': 42, + }) + elif decoded_id == SUBDIR_HASH: + found.append({ + 'sha1_git': id_, + 'type': 'directory', + 'id': id_, + 'object_id': 42, + }) + elif decoded_id in CONTENT1: + found.append({ + 'sha1_git': id_, + 'type': 'content', + 'id': id_, + 'object_id': 42, + }) + res[id_] = found + return res + class LoaderNoStorageMixin(LoaderNoStorage): def __init__(self): @@ -218,6 +257,7 @@ class GitLoaderTests: + """Common tests for all git loaders.""" def test_load(self): res = self.load() self.assertEqual(res['status'], 'eventful', res) @@ -246,6 +286,8 @@ class DirGitLoaderTest(BaseDirGitLoaderTest, GitLoaderTests): + """Tests for the GitLoader. Includes the common ones, and + add others that only work with a local dir.""" def _git(self, *cmd): try: return subprocess.check_output( @@ -318,4 +360,6 @@ class ZipGitLoaderTest(BaseZipGitLoaderTest, GitLoaderTests): + """Tests for GitLoaderFromArchive. Imports the common ones + from GitLoaderTests.""" pass diff --git a/swh/loader/git/tests/test_updater.py b/swh/loader/git/tests/test_updater.py new file mode 100644 --- /dev/null +++ b/swh/loader/git/tests/test_updater.py @@ -0,0 +1,19 @@ +from swh.loader.git.updater import BulkUpdater +from swh.loader.git.tests.test_loader import ( + DirGitLoaderTest, LoaderNoStorageMixin) + + +class BulkUpdaterNoStorage(LoaderNoStorageMixin, BulkUpdater): + """Subclass of BulkUpdater that uses a mock storage.""" + pass + + +class BulkUpdaterTest(DirGitLoaderTest): + """Same tests as for the GitLoader, but running on BulkUpdater.""" + def setUp(self): + super().setUp() + self.loader = BulkUpdaterNoStorage() + + def load(self): + return self.loader.load( + origin_url=self.repo_url)