merge settings groups instead of using whole group

This commit is contained in:
2021-03-30 04:53:15 +03:00
parent bd2b61494f
commit 2260e52d5c
14 changed files with 222 additions and 101 deletions

View File

@ -1,5 +1,4 @@
import pytest
import shutil
from pathlib import Path
from pytest_mock import MockerFixture

View File

@ -7,3 +7,9 @@ from ahriman.core.sign.gpg import GPG
@pytest.fixture
def gpg(configuration: Configuration) -> GPG:
return GPG("x86_64", configuration)
@pytest.fixture
def gpg_with_key(gpg: GPG) -> GPG:
gpg.default_key = "key"
return gpg

View File

@ -5,93 +5,177 @@ from ahriman.core.sign.gpg import GPG
from ahriman.models.sign_settings import SignSettings
def test_repository_sign_args(gpg: GPG) -> None:
def test_repository_sign_args_1(gpg_with_key: GPG) -> None:
"""
must generate correct sign args
"""
gpg.target = {SignSettings.SignRepository}
assert gpg.repository_sign_args
gpg_with_key.targets = {SignSettings.SignRepository}
assert gpg_with_key.repository_sign_args
def test_sign_package_1(gpg: GPG, mocker: MockerFixture) -> None:
def test_repository_sign_args_2(gpg_with_key: GPG) -> None:
"""
must generate correct sign args
"""
gpg_with_key.targets = {SignSettings.SignPackages, SignSettings.SignRepository}
assert gpg_with_key.repository_sign_args
def test_repository_sign_args_skip_1(gpg_with_key: GPG) -> None:
"""
must return empty args if it is not set
"""
gpg_with_key.targets = {}
assert not gpg_with_key.repository_sign_args
def test_repository_sign_args_skip_2(gpg_with_key: GPG) -> None:
"""
must return empty args if it is not set
"""
gpg_with_key.targets = {SignSettings.SignPackages}
assert not gpg_with_key.repository_sign_args
def test_repository_sign_args_skip_3(gpg: GPG) -> None:
"""
must return empty args if it is not set
"""
gpg.targets = {SignSettings.SignRepository}
assert not gpg.repository_sign_args
def test_repository_sign_args_skip_4(gpg: GPG) -> None:
"""
must return empty args if it is not set
"""
gpg.targets = {SignSettings.SignPackages, SignSettings.SignRepository}
assert not gpg.repository_sign_args
def test_sign_package_1(gpg_with_key: GPG, mocker: MockerFixture) -> None:
"""
must sign package
"""
result = [Path("a"), Path("a.sig")]
process_mock = mocker.patch("ahriman.core.sign.gpg.GPG.process", return_value=result)
gpg.target = {SignSettings.SignPackages}
assert gpg.sign_package(Path("a"), "a") == result
gpg_with_key.targets = {SignSettings.SignPackages}
assert gpg_with_key.sign_package(Path("a"), "a") == result
process_mock.assert_called_once()
def test_sign_package_2(gpg: GPG, mocker: MockerFixture) -> None:
def test_sign_package_2(gpg_with_key: GPG, mocker: MockerFixture) -> None:
"""
must sign package
"""
result = [Path("a"), Path("a.sig")]
process_mock = mocker.patch("ahriman.core.sign.gpg.GPG.process", return_value=result)
gpg.target = {SignSettings.SignPackages, SignSettings.SignRepository}
assert gpg.sign_package(Path("a"), "a") == result
gpg_with_key.targets = {SignSettings.SignPackages, SignSettings.SignRepository}
assert gpg_with_key.sign_package(Path("a"), "a") == result
process_mock.assert_called_once()
def test_sign_package_skip_1(gpg: GPG, mocker: MockerFixture) -> None:
def test_sign_package_skip_1(gpg_with_key: GPG, mocker: MockerFixture) -> None:
"""
must not sign package if it is not set
"""
process_mock = mocker.patch("ahriman.core.sign.gpg.GPG.process")
gpg.target = {}
gpg_with_key.targets = {}
gpg_with_key.sign_package(Path("a"), "a")
process_mock.assert_not_called()
def test_sign_package_skip_2(gpg: GPG, mocker: MockerFixture) -> None:
def test_sign_package_skip_2(gpg_with_key: GPG, mocker: MockerFixture) -> None:
"""
must not sign package if it is not set
"""
process_mock = mocker.patch("ahriman.core.sign.gpg.GPG.process")
gpg.target = {SignSettings.SignRepository}
gpg_with_key.targets = {SignSettings.SignRepository}
gpg_with_key.sign_package(Path("a"), "a")
process_mock.assert_not_called()
def test_sign_repository_1(gpg: GPG, mocker: MockerFixture) -> None:
def test_sign_package_skip_3(gpg: GPG, mocker: MockerFixture) -> None:
"""
must not sign package if it is not set
"""
process_mock = mocker.patch("ahriman.core.sign.gpg.GPG.process")
gpg.targets = {SignSettings.SignPackages}
gpg.sign_package(Path("a"), "a")
process_mock.assert_not_called()
def test_sign_package_skip_4(gpg: GPG, mocker: MockerFixture) -> None:
"""
must not sign package if it is not set
"""
process_mock = mocker.patch("ahriman.core.sign.gpg.GPG.process")
gpg.targets = {SignSettings.SignPackages, SignSettings.SignRepository}
gpg.sign_package(Path("a"), "a")
process_mock.assert_not_called()
def test_sign_repository_1(gpg_with_key: GPG, mocker: MockerFixture) -> None:
"""
must sign repository
"""
result = [Path("a"), Path("a.sig")]
process_mock = mocker.patch("ahriman.core.sign.gpg.GPG.process", return_value=result)
gpg.target = {SignSettings.SignRepository}
assert gpg.sign_repository(Path("a")) == result
gpg_with_key.targets = {SignSettings.SignRepository}
assert gpg_with_key.sign_repository(Path("a")) == result
process_mock.assert_called_once()
def test_sign_repository_2(gpg: GPG, mocker: MockerFixture) -> None:
def test_sign_repository_2(gpg_with_key: GPG, mocker: MockerFixture) -> None:
"""
must sign repository
"""
result = [Path("a"), Path("a.sig")]
process_mock = mocker.patch("ahriman.core.sign.gpg.GPG.process", return_value=result)
gpg.target = {SignSettings.SignPackages, SignSettings.SignRepository}
assert gpg.sign_repository(Path("a")) == result
gpg_with_key.targets = {SignSettings.SignPackages, SignSettings.SignRepository}
assert gpg_with_key.sign_repository(Path("a")) == result
process_mock.assert_called_once()
def test_sign_repository_skip_1(gpg: GPG, mocker: MockerFixture) -> None:
def test_sign_repository_skip_1(gpg_with_key: GPG, mocker: MockerFixture) -> None:
"""
must not sign repository if it is not set
"""
process_mock = mocker.patch("ahriman.core.sign.gpg.GPG.process")
gpg.target = {}
gpg_with_key.targets = {}
gpg_with_key.sign_repository(Path("a"))
process_mock.assert_not_called()
def test_sign_repository_skip_2(gpg: GPG, mocker: MockerFixture) -> None:
def test_sign_repository_skip_2(gpg_with_key: GPG, mocker: MockerFixture) -> None:
"""
must not sign repository if it is not set
"""
process_mock = mocker.patch("ahriman.core.sign.gpg.GPG.process")
gpg.target = {SignSettings.SignPackages}
gpg_with_key.targets = {SignSettings.SignPackages}
gpg_with_key.sign_repository(Path("a"))
process_mock.assert_not_called()
def test_sign_repository_skip_3(gpg: GPG, mocker: MockerFixture) -> None:
"""
must not sign repository if it is not set
"""
process_mock = mocker.patch("ahriman.core.sign.gpg.GPG.process")
gpg.targets = {SignSettings.SignRepository}
gpg.sign_repository(Path("a"))
process_mock.assert_not_called()
def test_sign_repository_skip_4(gpg: GPG, mocker: MockerFixture) -> None:
"""
must not sign repository if it is not set
"""
process_mock = mocker.patch("ahriman.core.sign.gpg.GPG.process")
gpg.targets = {SignSettings.SignPackages, SignSettings.SignRepository}
gpg.sign_repository(Path("a"))
process_mock.assert_not_called()

View File

@ -21,6 +21,13 @@ def test_from_path(mocker: MockerFixture) -> None:
load_logging_mock.assert_called_once()
def test_section_name(configuration: Configuration) -> None:
"""
must return architecture specific group
"""
assert configuration.section_name("build", "x86_64") == "build_x86_64"
def test_absolute_path_for_absolute(configuration: Configuration) -> None:
"""
must not change path for absolute path in settings
@ -54,12 +61,13 @@ def test_dump_architecture_specific(configuration: Configuration) -> None:
dump must contain architecture specific settings
"""
configuration.add_section("build_x86_64")
configuration.set("build_x86_64", "archbuild_flags", "")
configuration.set("build_x86_64", "archbuild_flags", "hello flag")
dump = configuration.dump("x86_64")
assert dump
assert "build" not in dump
assert "build_x86_64" in dump
assert "build" in dump
assert "build_x86_64" not in dump
assert dump["build"]["archbuild_flags"] == "hello flag"
def test_getlist(configuration: Configuration) -> None:
@ -87,23 +95,6 @@ def test_getlist_single(configuration: Configuration) -> None:
assert configuration.getlist("build", "test_list") == ["a"]
def test_get_section_name(configuration: Configuration) -> None:
"""
must return architecture specific group
"""
configuration.add_section("build_x86_64")
configuration.set("build_x86_64", "archbuild_flags", "")
assert configuration.get_section_name("build", "x86_64") == "build_x86_64"
def test_get_section_name_missing(configuration: Configuration) -> None:
"""
must return default group if architecture depending group does not exist
"""
assert configuration.get_section_name("prefix", "suffix") == "prefix"
assert configuration.get_section_name("build", "x86_64") == "build"
def test_load_includes_missing(configuration: Configuration) -> None:
"""
must not fail if not include directory found