Detector: fingerprint store methods

Signed-off-by: Václav Valíček <valicek1994@gmail.com>
This commit is contained in:
2022-08-04 11:09:26 +02:00
parent d74c67d4f6
commit 02f092bfc3
2 changed files with 66 additions and 5 deletions

View File

@@ -2,7 +2,7 @@ import logging
from repo_cloner.lib import Detector, DetectedCommit
import pytest
from unittest.mock import patch, MagicMock
from unittest.mock import patch, MagicMock, PropertyMock
from git import Actor
from cloner_test_fixtures import cloner_dir_struct
from collections import namedtuple
@@ -211,6 +211,45 @@ def test_initialize_caches(tmp_path):
assert dict(json.loads(cache_dir.joinpath("tags").read_text())) == tags
def test_check_fingerprint(tmp_path):
mocks = {
'repo_fingerprint': PropertyMock(return_value = "FingerPrint"),
}
repo = tmp_path.joinpath("repo.git")
cache_dir = tmp_path.joinpath("cache")
cache_dir.mkdir()
fp_file = cache_dir.joinpath("detectorSum")
with patch.multiple("repo_cloner.lib.RepoTool", **mocks):
det = Detector(repo, cache_dir, "Mocked")
# file does not exist
assert det.check_fingerprint()
fp_file.touch()
assert det.check_fingerprint()
fp_file.write_text("FingerPrint")
assert not det.check_fingerprint()
def test_persist_fingerprint(tmp_path):
mocks = {
'repo_fingerprint': PropertyMock(return_value = "FingerPrint"),
}
repo = tmp_path.joinpath("repo.git")
cache_dir = tmp_path.joinpath("cache")
cache_dir.mkdir()
fp_file = cache_dir.joinpath("detectorSum")
with patch.multiple("repo_cloner.lib.RepoTool", **mocks):
det = Detector(repo, cache_dir, "Mocked")
det.persist_fingerprint()
assert fp_file.read_text().strip() == "FingerPrint"
def test_run(tmp_path, caplog):
stamp = 1659533160
executed = []
@@ -298,9 +337,10 @@ def test_run(tmp_path, caplog):
for commit in commits_new]
mocks = {
'list_commits': MagicMock(return_value = commits_named_new),
'list_branches': MagicMock(return_value = branches_new),
'list_tags': MagicMock(return_value = tags_new),
'list_commits': MagicMock(return_value = commits_named_new),
'list_branches': MagicMock(return_value = branches_new),
'list_tags': MagicMock(return_value = tags_new),
'repo_fingerprint': PropertyMock(return_value = "some-fingerprint"),
}
repo = tmp_path.joinpath("repo.git")