mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-11-12 19:43:42 +00:00
Compare commits
9 Commits
f12786a0c6
...
78314146b8
| Author | SHA1 | Date | |
|---|---|---|---|
| 78314146b8 | |||
| 25b66b5b60 | |||
| c89f6ad98c | |||
| c734f0815a | |||
| dc3cee9449 | |||
| 0b2acfac9b | |||
| c5d849d6a6 | |||
| 63ccb5fc11 | |||
| 04e554d096 |
@ -17,6 +17,7 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from ahriman.core import context
|
||||
from ahriman.core.archive.archive_tree import ArchiveTree
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.sign.gpg import GPG
|
||||
@ -44,7 +45,9 @@ class ArchiveTrigger(Trigger):
|
||||
Trigger.__init__(self, repository_id, configuration)
|
||||
|
||||
self.paths = configuration.repository_paths
|
||||
self.tree = ArchiveTree(self.paths, GPG(configuration).repository_sign_args)
|
||||
|
||||
ctx = context.get()
|
||||
self.tree = ArchiveTree(self.paths, ctx.get(GPG).repository_sign_args)
|
||||
|
||||
def on_result(self, result: Result, packages: list[Package]) -> None:
|
||||
"""
|
||||
|
||||
@ -36,7 +36,6 @@ class Trigger(LazyLogging):
|
||||
CONFIGURATION_SCHEMA(ConfigurationSchema): (class attribute) configuration schema template
|
||||
CONFIGURATION_SCHEMA_FALLBACK(str | None): (class attribute) optional fallback option for defining
|
||||
configuration schema type used
|
||||
REQUIRES_REPOSITORY(bool): (class attribute) either trigger requires loaded repository or not
|
||||
configuration(Configuration): configuration instance
|
||||
repository_id(RepositoryId): repository unique identifier
|
||||
|
||||
@ -60,7 +59,6 @@ class Trigger(LazyLogging):
|
||||
|
||||
CONFIGURATION_SCHEMA: ClassVar[ConfigurationSchema] = {}
|
||||
CONFIGURATION_SCHEMA_FALLBACK: ClassVar[str | None] = None
|
||||
REQUIRES_REPOSITORY: ClassVar[bool] = True
|
||||
|
||||
def __init__(self, repository_id: RepositoryId, configuration: Configuration) -> None:
|
||||
"""
|
||||
@ -81,16 +79,6 @@ class Trigger(LazyLogging):
|
||||
"""
|
||||
return self.repository_id.architecture
|
||||
|
||||
@property
|
||||
def is_allowed_to_run(self) -> bool:
|
||||
"""
|
||||
whether trigger allowed to run or not
|
||||
|
||||
Returns:
|
||||
bool: ``True`` in case if trigger allowed to run and ``False`` otherwise
|
||||
"""
|
||||
return not (self.REQUIRES_REPOSITORY and self.repository_id.is_empty)
|
||||
|
||||
@classmethod
|
||||
def configuration_schema(cls, configuration: Configuration | None) -> ConfigurationSchema:
|
||||
"""
|
||||
|
||||
@ -77,9 +77,8 @@ class TriggerLoader(LazyLogging):
|
||||
"""
|
||||
instance = cls()
|
||||
instance.triggers = [
|
||||
trigger
|
||||
for trigger_name in instance.selected_triggers(configuration)
|
||||
if (trigger := instance.load_trigger(trigger_name, repository_id, configuration)).is_allowed_to_run
|
||||
instance.load_trigger(trigger, repository_id, configuration)
|
||||
for trigger in instance.selected_triggers(configuration)
|
||||
]
|
||||
|
||||
return instance
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.core.archive import ArchiveTrigger
|
||||
from ahriman.core.archive.archive_tree import ArchiveTree
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.sign.gpg import GPG
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -20,15 +23,18 @@ def archive_tree(configuration: Configuration) -> ArchiveTree:
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def archive_trigger(configuration: Configuration) -> ArchiveTrigger:
|
||||
def archive_trigger(configuration: Configuration, gpg: GPG, mocker: MockerFixture) -> ArchiveTrigger:
|
||||
"""
|
||||
archive trigger fixture
|
||||
|
||||
Args:
|
||||
configuration(Configuration): configuration fixture
|
||||
gpg(GPG): GPG fixture
|
||||
mocker(MockerFixture): mocker object
|
||||
|
||||
Returns:
|
||||
ArchiveTrigger: archive trigger test instance
|
||||
"""
|
||||
mocker.patch("ahriman.core._Context.get", return_value=GPG)
|
||||
_, repository_id = configuration.check_loaded()
|
||||
return ArchiveTrigger(repository_id, configuration)
|
||||
|
||||
@ -3,7 +3,6 @@ from unittest.mock import MagicMock
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.report import ReportTrigger
|
||||
from ahriman.core.triggers import Trigger
|
||||
from ahriman.models.repository_id import RepositoryId
|
||||
from ahriman.models.result import Result
|
||||
|
||||
|
||||
@ -14,19 +13,6 @@ def test_architecture(trigger: Trigger) -> None:
|
||||
assert trigger.architecture == trigger.repository_id.architecture
|
||||
|
||||
|
||||
def test_is_allowed_to_run(trigger: Trigger) -> None:
|
||||
"""
|
||||
must return flag correctly
|
||||
"""
|
||||
assert trigger.is_allowed_to_run
|
||||
|
||||
trigger.repository_id = RepositoryId("", "")
|
||||
assert not trigger.is_allowed_to_run
|
||||
|
||||
trigger.REQUIRES_REPOSITORY = False
|
||||
assert trigger.is_allowed_to_run
|
||||
|
||||
|
||||
def test_configuration_schema(configuration: Configuration) -> None:
|
||||
"""
|
||||
must return used configuration schema
|
||||
|
||||
Reference in New Issue
Block a user