add sign tests

This commit is contained in:
2021-03-26 04:36:13 +03:00
parent 83084a318d
commit 077b80d345
8 changed files with 72 additions and 4 deletions

View File

@ -49,7 +49,7 @@ class GPG:
self.logger = logging.getLogger("build_details")
self.config = config
self.section = config.get_section_name("sign", architecture)
self.target = [SignSettings.from_option(opt) for opt in config.getlist(self.section, "target")]
self.target = {SignSettings.from_option(opt) for opt in config.getlist(self.section, "target")}
self.default_key = config.get(self.section, "key") if self.target else ""
@property

View File

@ -1,7 +1,6 @@
from pathlib import Path
from unittest import mock
from pytest_mock import MockerFixture
from unittest import mock
from ahriman.core.repository.executor import Executor
from ahriman.models.package import Package

View File

@ -1,5 +1,4 @@
from pathlib import Path
from pytest_mock import MockerFixture
from ahriman.core.repository.repository import Repository

View File

@ -0,0 +1,9 @@
import pytest
from ahriman.core.configuration import Configuration
from ahriman.core.sign.gpg import GPG
@pytest.fixture
def gpg(configuration: Configuration) -> GPG:
return GPG("x86_64", configuration)

View File

@ -0,0 +1,61 @@
from pathlib import Path
from pytest_mock import MockerFixture
from ahriman.core.sign.gpg import GPG
from ahriman.models.sign_settings import SignSettings
def test_repository_sign_args(gpg: GPG) -> None:
"""
must generate correct sign args
"""
gpg.target = {SignSettings.SignRepository}
assert gpg.repository_sign_args
def test_sign_package(gpg: GPG, mocker: MockerFixture) -> None:
"""
must sign package
"""
result = [Path("a"), Path("a.sig")]
process_mock = mocker.patch("ahriman.core.sign.gpg.process", return_value=result)
for target in ({SignSettings.SignPackages}, {SignSettings.SignPackages, SignSettings.SignRepository}):
gpg.target = target
assert gpg.sign_package(Path("a"), "a") == result
process_mock.assert_called_once()
def test_sign_package_skip(gpg: GPG, mocker: MockerFixture) -> None:
"""
must not sign package if it is not set
"""
process_mock = mocker.patch("ahriman.core.sign.gpg.process")
for target in ({}, {SignSettings.SignRepository}):
gpg.target = target
process_mock.assert_not_called()
def test_sign_repository(gpg: GPG, mocker: MockerFixture) -> None:
"""
must sign repository
"""
result = [Path("a"), Path("a.sig")]
process_mock = mocker.patch("ahriman.core.sign.gpg.process", return_value=result)
for target in ({SignSettings.SignRepository}, {SignSettings.SignPackages, SignSettings.SignRepository}):
gpg.target = target
assert gpg.sign_repository(Path("a")) == result
process_mock.assert_called_once()
def test_sign_repository_skip(gpg: GPG, mocker: MockerFixture) -> None:
"""
must not sign repository if it is not set
"""
process_mock = mocker.patch("ahriman.core.sign.gpg.process")
for target in ({}, {SignSettings.SignPackages}):
gpg.target = target
process_mock.assert_not_called()

View File

View File