mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-08-28 20:39:56 +00:00
fix: correctly process trigger repo specific settings in validator (see #154)
This commit is contained in:
@ -2,6 +2,7 @@ import argparse
|
||||
import json
|
||||
import pytest
|
||||
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.application.handlers.validate import Validate
|
||||
@ -53,12 +54,50 @@ def test_run_skip(args: argparse.Namespace, configuration: Configuration, mocker
|
||||
print_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_run_default(args: argparse.Namespace, configuration: Configuration) -> None:
|
||||
"""
|
||||
must run on default configuration without errors
|
||||
"""
|
||||
args.exit_code = True
|
||||
_, repository_id = configuration.check_loaded()
|
||||
|
||||
default = Configuration.from_path(Configuration.SYSTEM_CONFIGURATION_PATH, repository_id)
|
||||
# copy autogenerated values
|
||||
for section, key in (("build", "build_command"), ("repository", "root")):
|
||||
value = configuration.get(section, key)
|
||||
default.set_option(section, key, value)
|
||||
|
||||
Validate.run(args, repository_id, default, report=False)
|
||||
|
||||
|
||||
def test_run_repo_specific_triggers(args: argparse.Namespace, configuration: Configuration,
|
||||
resource_path_root: Path) -> None:
|
||||
"""
|
||||
must correctly insert repo specific triggers
|
||||
"""
|
||||
args.exit_code = True
|
||||
_, repository_id = configuration.check_loaded()
|
||||
|
||||
# remove unused sections
|
||||
for section in ("customs3", "github:x86_64", "logs-rotation", "mirrorlist"):
|
||||
configuration.remove_section(section)
|
||||
|
||||
configuration.set_option("report", "target", "test")
|
||||
for section in ("test", "test:i686", "test:another-repo:x86_64"):
|
||||
configuration.set_option(section, "type", "html")
|
||||
configuration.set_option(section, "link_path", "http://link_path")
|
||||
configuration.set_option(section, "path", "path")
|
||||
configuration.set_option(section, "template", "template")
|
||||
configuration.set_option(section, "templates", str(resource_path_root))
|
||||
|
||||
Validate.run(args, repository_id, configuration, report=False)
|
||||
|
||||
|
||||
def test_schema(configuration: Configuration) -> None:
|
||||
"""
|
||||
must generate full schema correctly
|
||||
"""
|
||||
_, repository_id = configuration.check_loaded()
|
||||
schema = Validate.schema(repository_id, configuration)
|
||||
schema = Validate.schema(configuration)
|
||||
|
||||
# defaults
|
||||
assert schema.pop("console")
|
||||
@ -91,9 +130,7 @@ def test_schema_invalid_trigger(configuration: Configuration) -> None:
|
||||
"""
|
||||
configuration.set_option("build", "triggers", "some.invalid.trigger.path.Trigger")
|
||||
configuration.remove_option("build", "triggers_known")
|
||||
_, repository_id = configuration.check_loaded()
|
||||
|
||||
assert Validate.schema(repository_id, configuration) == CONFIGURATION_SCHEMA
|
||||
assert Validate.schema(configuration) == CONFIGURATION_SCHEMA
|
||||
|
||||
|
||||
def test_schema_erase_required() -> None:
|
||||
|
@ -19,10 +19,9 @@ def test_configuration_schema(configuration: Configuration) -> None:
|
||||
"""
|
||||
section = "console"
|
||||
configuration.set_option("report", "target", section)
|
||||
_, repository_id = configuration.check_loaded()
|
||||
|
||||
expected = {section: ReportTrigger.CONFIGURATION_SCHEMA[section]}
|
||||
assert ReportTrigger.configuration_schema(repository_id, configuration) == expected
|
||||
assert ReportTrigger.configuration_schema(configuration) == expected
|
||||
|
||||
|
||||
def test_configuration_schema_no_section(configuration: Configuration) -> None:
|
||||
@ -31,9 +30,7 @@ def test_configuration_schema_no_section(configuration: Configuration) -> None:
|
||||
"""
|
||||
section = "abracadabra"
|
||||
configuration.set_option("report", "target", section)
|
||||
_, repository_id = configuration.check_loaded()
|
||||
|
||||
assert ReportTrigger.configuration_schema(repository_id, configuration) == {}
|
||||
assert ReportTrigger.configuration_schema(configuration) == {}
|
||||
|
||||
|
||||
def test_configuration_schema_no_schema(configuration: Configuration) -> None:
|
||||
@ -43,17 +40,15 @@ def test_configuration_schema_no_schema(configuration: Configuration) -> None:
|
||||
section = "abracadabra"
|
||||
configuration.set_option("report", "target", section)
|
||||
configuration.set_option(section, "key", "value")
|
||||
_, repository_id = configuration.check_loaded()
|
||||
|
||||
assert ReportTrigger.configuration_schema(repository_id, configuration) == {}
|
||||
assert ReportTrigger.configuration_schema(configuration) == {}
|
||||
|
||||
|
||||
def test_configuration_schema_empty(configuration: Configuration) -> None:
|
||||
"""
|
||||
must return default schema if no configuration set
|
||||
"""
|
||||
_, repository_id = configuration.check_loaded()
|
||||
assert ReportTrigger.configuration_schema(repository_id, None) == ReportTrigger.CONFIGURATION_SCHEMA
|
||||
assert ReportTrigger.configuration_schema(None) == ReportTrigger.CONFIGURATION_SCHEMA
|
||||
|
||||
|
||||
def test_configuration_schema_variables() -> None:
|
||||
|
Reference in New Issue
Block a user