Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/git/tests/test_from_disk.py
# Copyright (C) 2018-2020 The Software Heritage developers | # Copyright (C) 2018-2021 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 | ||||
import copy | import copy | ||||
import datetime | import datetime | ||||
import os.path | import os.path | ||||
from unittest import TestCase | from unittest import TestCase | ||||
▲ Show 20 Lines • Show All 151 Lines • ▼ Show 20 Lines | def test_load_unchanged(self): | ||||
assert_last_visit_matches( | assert_last_visit_matches( | ||||
self.loader.storage, | self.loader.storage, | ||||
self.repo_url, | self.repo_url, | ||||
status="full", | status="full", | ||||
type="git", | type="git", | ||||
snapshot=SNAPSHOT1.id, | snapshot=SNAPSHOT1.id, | ||||
) | ) | ||||
def test_load_visit_without_snapshot_so_status_failed(self): | |||||
# unfortunately, monkey-patch the hard way, self.loader is already instantiated | |||||
# (patching won't work self.loader is already instantiated) | |||||
# Make get_contents fail for some reason | |||||
self.loader.get_contents = None | |||||
res = self.loader.load() | |||||
assert res == {"status": "failed"} | |||||
assert_last_visit_matches( | |||||
self.loader.storage, | |||||
self.repo_url, | |||||
status="failed", | |||||
type="git", | |||||
snapshot=None, | |||||
) | |||||
def test_load_visit_with_snapshot_so_status_partial(self): | |||||
# unfortunately, monkey-patch the hard way, self.loader is already instantiated | |||||
# (patching won't work self.loader is already instantiated) | |||||
# fake store_metadata raising for some reason, so we could have a snapshot id | |||||
# at this point in time | |||||
self.loader.store_metadata = None | |||||
# fake having a snapshot so the visit status is partial | |||||
self.loader.loaded_snapshot_id = hash_to_bytes( | |||||
"a23699280a82a043f8c0994cf1631b568f716f95" | |||||
) | |||||
res = self.loader.load() | |||||
assert res == {"status": "failed"} | |||||
assert_last_visit_matches( | |||||
self.loader.storage, | |||||
self.repo_url, | |||||
status="partial", | |||||
type="git", | |||||
snapshot=None, | |||||
) | |||||
class FullGitLoaderTests(CommonGitLoaderTests): | class FullGitLoaderTests(CommonGitLoaderTests): | ||||
"""Tests for GitLoader (from disk or not). Includes the common ones, and | """Tests for GitLoader (from disk or not). Includes the common ones, and | ||||
add others that only work with a local dir. | add others that only work with a local dir. | ||||
""" | """ | ||||
def test_load_changed(self): | def test_load_changed(self): | ||||
▲ Show 20 Lines • Show All 228 Lines • Show Last 20 Lines |