mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-15 15:05:48 +00:00
alpm tests implementation
This commit is contained in:
10
tests/ahriman/core/alpm/test_pacman.py
Normal file
10
tests/ahriman/core/alpm/test_pacman.py
Normal file
@ -0,0 +1,10 @@
|
||||
from ahriman.core.alpm.pacman import Pacman
|
||||
|
||||
|
||||
def test_all_packages(pacman: Pacman) -> None:
|
||||
"""
|
||||
package list must not be empty
|
||||
"""
|
||||
packages = pacman.all_packages()
|
||||
assert packages
|
||||
assert "pacman" in packages
|
65
tests/ahriman/core/alpm/test_repo.py
Normal file
65
tests/ahriman/core/alpm/test_repo.py
Normal file
@ -0,0 +1,65 @@
|
||||
import os
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest import mock
|
||||
|
||||
from ahriman.core.alpm.repo import Repo
|
||||
|
||||
|
||||
def test_repo_path(repo: Repo) -> None:
|
||||
"""
|
||||
name must be something like archive name
|
||||
"""
|
||||
assert repo.repo_path.endswith("db.tar.gz")
|
||||
|
||||
|
||||
def test_repo_add(repo: Repo, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must call repo-add on package addition
|
||||
"""
|
||||
check_output_mock = mocker.patch("ahriman.core.alpm.repo.Repo._check_output")
|
||||
|
||||
repo.add("path")
|
||||
Repo._check_output.assert_called_once()
|
||||
assert check_output_mock.call_args[0][0] == "repo-add"
|
||||
|
||||
|
||||
def test_repo_remove(repo: Repo, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must call repo-remove on package addition
|
||||
"""
|
||||
mocker.patch("os.listdir", return_value=[])
|
||||
check_output_mock = mocker.patch("ahriman.core.alpm.repo.Repo._check_output")
|
||||
|
||||
repo.remove("package", "package.pkg.tar.xz")
|
||||
Repo._check_output.assert_called_once()
|
||||
assert check_output_mock.call_args[0][0] == "repo-remove"
|
||||
|
||||
|
||||
def test_repo_remove_fail_no_file(repo: Repo, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must fail on missing file
|
||||
"""
|
||||
mocker.patch("os.listdir", return_value=["package.pkg.tar.xz"])
|
||||
mocker.patch("os.remove", side_effect=FileNotFoundError())
|
||||
|
||||
with pytest.raises(FileNotFoundError):
|
||||
repo.remove("package", "package.pkg.tar.xz")
|
||||
|
||||
|
||||
def test_repo_remove_remove_requested(repo: Repo, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must remove only requested files
|
||||
"""
|
||||
packages = ["package.pkg.tar.xz", "package.pkg.tar.xz.sig"]
|
||||
all_packages = packages + ["valid-package.pkg.tar.xz.sig", "package-valid.pkg.tar.xz.sig"]
|
||||
|
||||
mocker.patch("os.listdir", return_value=all_packages)
|
||||
remove_mock = mocker.patch("os.remove")
|
||||
mocker.patch("ahriman.core.alpm.repo.Repo._check_output")
|
||||
|
||||
repo.remove("package", "package.pkg.tar.xz")
|
||||
removed = [call.call_list()[0][0][0] for call in remove_mock.call_args_list]
|
||||
to_be_removed = [os.path.join(repo.paths.repository, package) for package in packages]
|
||||
assert set(removed) == set(to_be_removed)
|
27
tests/ahriman/core/conftest.py
Normal file
27
tests/ahriman/core/conftest.py
Normal file
@ -0,0 +1,27 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from ahriman.core.alpm.pacman import Pacman
|
||||
from ahriman.core.alpm.repo import Repo
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def configuration(resource_path_root: Path) -> Configuration:
|
||||
path = resource_path_root / "core" / "ahriman.ini"
|
||||
return Configuration.from_path(path=str(path), logfile=False)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def pacman(configuration: Configuration) -> Pacman:
|
||||
return Pacman(configuration)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def repo(configuration: Configuration) -> Repo:
|
||||
return Repo(
|
||||
configuration.get("repository", "name"),
|
||||
RepositoryPaths(configuration.get("repository", "root"), "x86_64"),
|
||||
[])
|
46
tests/testresources/core/ahriman.ini
Normal file
46
tests/testresources/core/ahriman.ini
Normal file
@ -0,0 +1,46 @@
|
||||
[settings]
|
||||
logging = logging.ini
|
||||
|
||||
[alpm]
|
||||
aur_url = https://aur.archlinux.org
|
||||
database = /var/lib/pacman
|
||||
repositories = core extra community multilib
|
||||
root = /
|
||||
|
||||
[build]
|
||||
archbuild_flags =
|
||||
build_command = extra-x86_64-build
|
||||
ignore_packages =
|
||||
makechrootpkg_flags =
|
||||
makepkg_flags = --skippgpcheck
|
||||
|
||||
[repository]
|
||||
name = aur-clone
|
||||
root = /var/lib/ahriman
|
||||
|
||||
[sign]
|
||||
target =
|
||||
key =
|
||||
|
||||
[report]
|
||||
target =
|
||||
|
||||
[html]
|
||||
path =
|
||||
homepage =
|
||||
link_path =
|
||||
template_path = /usr/share/ahriman/repo-index.jinja2
|
||||
|
||||
[upload]
|
||||
target =
|
||||
|
||||
[rsync]
|
||||
remote =
|
||||
|
||||
[s3]
|
||||
bucket =
|
||||
|
||||
[web]
|
||||
host =
|
||||
port =
|
||||
templates = /usr/share/ahriman
|
59
tests/testresources/core/logging.ini
Normal file
59
tests/testresources/core/logging.ini
Normal file
@ -0,0 +1,59 @@
|
||||
[loggers]
|
||||
keys = root,builder,build_details,http
|
||||
|
||||
[handlers]
|
||||
keys = console_handler,build_file_handler,file_handler,http_handler
|
||||
|
||||
[formatters]
|
||||
keys = generic_format
|
||||
|
||||
[handler_console_handler]
|
||||
class = StreamHandler
|
||||
level = DEBUG
|
||||
formatter = generic_format
|
||||
args = (sys.stderr,)
|
||||
|
||||
[handler_file_handler]
|
||||
class = logging.handlers.RotatingFileHandler
|
||||
level = DEBUG
|
||||
formatter = generic_format
|
||||
args = ('/var/log/ahriman/ahriman.log', 'a', 20971520, 20)
|
||||
|
||||
[handler_build_file_handler]
|
||||
class = logging.handlers.RotatingFileHandler
|
||||
level = DEBUG
|
||||
formatter = generic_format
|
||||
args = ('/var/log/ahriman/build.log', 'a', 20971520, 20)
|
||||
|
||||
[handler_http_handler]
|
||||
class = logging.handlers.RotatingFileHandler
|
||||
level = DEBUG
|
||||
formatter = generic_format
|
||||
args = ('/var/log/ahriman/http.log', 'a', 20971520, 20)
|
||||
|
||||
[formatter_generic_format]
|
||||
format = [%(levelname)s %(asctime)s] [%(filename)s:%(lineno)d] [%(funcName)s]: %(message)s
|
||||
datefmt =
|
||||
|
||||
[logger_root]
|
||||
level = DEBUG
|
||||
handlers = file_handler
|
||||
qualname = root
|
||||
|
||||
[logger_builder]
|
||||
level = DEBUG
|
||||
handlers = file_handler
|
||||
qualname = builder
|
||||
propagate = 0
|
||||
|
||||
[logger_build_details]
|
||||
level = DEBUG
|
||||
handlers = build_file_handler
|
||||
qualname = build_details
|
||||
propagate = 0
|
||||
|
||||
[logger_http]
|
||||
level = DEBUG
|
||||
handlers = http_handler
|
||||
qualname = http
|
||||
propagate = 0
|
Reference in New Issue
Block a user