mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-05-04 20:23:49 +00:00
Compare commits
3 Commits
ab6f12b4af
...
f27f260531
Author | SHA1 | Date | |
---|---|---|---|
f27f260531 | |||
bfe37dbac0 | |||
ce7a8fde3c |
@ -130,12 +130,11 @@ class Patch(Handler):
|
||||
variables(list[str] | None): extract patches only for specified PKGBUILD variables
|
||||
exit_code(bool): exit with error on empty search result
|
||||
"""
|
||||
patches = []
|
||||
if variables is not None:
|
||||
for variable in variables:
|
||||
patches.extend(application.reporter.package_patches_get(package_base, variable))
|
||||
else:
|
||||
patches = application.reporter.package_patches_get(package_base, variables)
|
||||
patches = [
|
||||
patch
|
||||
for patch in application.reporter.package_patches_get(package_base, None)
|
||||
if variables is None or patch.key in variables
|
||||
]
|
||||
Patch.check_if_empty(exit_code, not patches)
|
||||
|
||||
PatchPrinter(package_base, patches)(verbose=True, separator=" = ")
|
||||
@ -154,4 +153,4 @@ class Patch(Handler):
|
||||
for variable in variables: # iterate over single variable
|
||||
application.reporter.package_patches_remove(package_base, variable)
|
||||
else:
|
||||
application.reporter.package_patches_remove(package_base, variables) # just pass as is
|
||||
application.reporter.package_patches_remove(package_base, None) # just pass as is
|
||||
|
@ -25,8 +25,8 @@ class PatchSchema(Schema):
|
||||
request and response patch schema
|
||||
"""
|
||||
|
||||
key = fields.String(required=True, metadata={
|
||||
"description": "environment variable name",
|
||||
key = fields.String(metadata={
|
||||
"description": "environment variable name. Required in case if it is not full diff",
|
||||
})
|
||||
value = fields.String(metadata={
|
||||
"description": "environment variable value",
|
||||
|
@ -96,7 +96,7 @@ class PatchesView(StatusViewGuard, BaseView):
|
||||
|
||||
try:
|
||||
data = await self.request.json()
|
||||
key = data["key"]
|
||||
key = data.get("key")
|
||||
value = data["value"]
|
||||
except Exception as ex:
|
||||
raise HTTPBadRequest(reason=str(ex))
|
||||
|
@ -161,12 +161,12 @@ def test_patch_set_list(application: Application, mocker: MockerFixture) -> None
|
||||
must list available patches for the command
|
||||
"""
|
||||
get_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_patches_get",
|
||||
return_value=[PkgbuildPatch(None, "patch")])
|
||||
return_value=[PkgbuildPatch(None, "patch"), PkgbuildPatch("version", "value")])
|
||||
print_mock = mocker.patch("ahriman.core.formatters.Printer.print")
|
||||
check_mock = mocker.patch("ahriman.application.handlers.Handler.check_if_empty")
|
||||
|
||||
Patch.patch_set_list(application, "ahriman", ["version"], False)
|
||||
get_mock.assert_called_once_with("ahriman", "version")
|
||||
get_mock.assert_called_once_with("ahriman", None)
|
||||
print_mock.assert_called_once_with(verbose=True, log_fn=pytest.helpers.anyvar(int), separator=" = ")
|
||||
check_mock.assert_called_once_with(False, False)
|
||||
|
||||
|
@ -27,7 +27,7 @@ def test_path(args: argparse.Namespace, configuration: Configuration) -> None:
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
args.lock = Path("/")
|
||||
Lock(args, repository_id, configuration).path # special case
|
||||
assert Lock(args, repository_id, configuration).path # special case
|
||||
|
||||
|
||||
def test_check_user(lock: Lock, mocker: MockerFixture) -> None:
|
||||
@ -205,7 +205,7 @@ def test_exit_with_exception(lock: Lock, mocker: MockerFixture) -> None:
|
||||
mocker.patch("ahriman.application.lock.Lock.create")
|
||||
update_status_mock = mocker.patch("ahriman.core.status.Client.status_update")
|
||||
|
||||
with pytest.raises(Exception):
|
||||
with pytest.raises(ValueError):
|
||||
with lock:
|
||||
raise Exception()
|
||||
raise ValueError()
|
||||
update_status_mock.assert_has_calls([MockCall(BuildStatusEnum.Building), MockCall(BuildStatusEnum.Failed)])
|
||||
|
@ -128,7 +128,7 @@ def test_database_copy_database_exist(pacman: Pacman, mocker: MockerFixture) ->
|
||||
copy_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_database_init(pacman: Pacman, configuration: Configuration) -> None:
|
||||
def test_database_init(pacman: Pacman) -> None:
|
||||
"""
|
||||
must init database with settings
|
||||
"""
|
||||
@ -184,14 +184,15 @@ def test_files(pacman: Pacman, package_ahriman: Package, mocker: MockerFixture,
|
||||
pacman.handle = handle_mock
|
||||
tarball = resource_path_root / "core" / "arcanisrepo.files.tar.gz"
|
||||
|
||||
mocker.patch("pathlib.Path.is_file", return_value=True)
|
||||
open_mock = mocker.patch("ahriman.core.alpm.pacman.tarfile.open", return_value=tarfile.open(tarball, "r:gz"))
|
||||
with tarfile.open(tarball, "r:gz") as fd:
|
||||
mocker.patch("pathlib.Path.is_file", return_value=True)
|
||||
open_mock = mocker.patch("ahriman.core.alpm.pacman.tarfile.open", return_value=fd)
|
||||
|
||||
files = pacman.files()
|
||||
assert len(files) == 2
|
||||
assert package_ahriman.base in files
|
||||
assert "usr/bin/ahriman" in files[package_ahriman.base]
|
||||
open_mock.assert_called_once_with(pytest.helpers.anyvar(int), "r:gz")
|
||||
files = pacman.files()
|
||||
assert len(files) == 2
|
||||
assert package_ahriman.base in files
|
||||
assert "usr/bin/ahriman" in files[package_ahriman.base]
|
||||
open_mock.assert_called_once_with(pytest.helpers.anyvar(int), "r:gz")
|
||||
|
||||
|
||||
def test_files_package(pacman: Pacman, package_ahriman: Package, mocker: MockerFixture,
|
||||
@ -205,12 +206,13 @@ def test_files_package(pacman: Pacman, package_ahriman: Package, mocker: MockerF
|
||||
|
||||
tarball = resource_path_root / "core" / "arcanisrepo.files.tar.gz"
|
||||
|
||||
mocker.patch("pathlib.Path.is_file", return_value=True)
|
||||
mocker.patch("ahriman.core.alpm.pacman.tarfile.open", return_value=tarfile.open(tarball, "r:gz"))
|
||||
with tarfile.open(tarball, "r:gz") as fd:
|
||||
mocker.patch("pathlib.Path.is_file", return_value=True)
|
||||
mocker.patch("ahriman.core.alpm.pacman.tarfile.open", return_value=fd)
|
||||
|
||||
files = pacman.files(package_ahriman.base)
|
||||
assert len(files) == 1
|
||||
assert package_ahriman.base in files
|
||||
files = pacman.files(package_ahriman.base)
|
||||
assert len(files) == 1
|
||||
assert package_ahriman.base in files
|
||||
|
||||
|
||||
def test_files_skip(pacman: Pacman, mocker: MockerFixture) -> None:
|
||||
|
@ -165,7 +165,6 @@ def test_package_update_remove_get(database: SQLite, package_ahriman: Package) -
|
||||
"""
|
||||
must insert, remove and retrieve package
|
||||
"""
|
||||
status = BuildStatus()
|
||||
database.package_update(package_ahriman)
|
||||
database.package_remove(package_ahriman.base)
|
||||
assert not database.packages_get()
|
||||
|
@ -68,9 +68,9 @@ def test_in_package_context_failed(database: SQLite, package_ahriman: Package, m
|
||||
mocker.patch("ahriman.core.log.LazyLogging._package_logger_set")
|
||||
reset_mock = mocker.patch("ahriman.core.log.LazyLogging._package_logger_reset")
|
||||
|
||||
with pytest.raises(Exception):
|
||||
with pytest.raises(ValueError):
|
||||
with database.in_package_context(package_ahriman.base, ""):
|
||||
raise Exception()
|
||||
raise ValueError()
|
||||
|
||||
reset_mock.assert_called_once_with()
|
||||
|
||||
@ -81,11 +81,3 @@ def test_logger(database: SQLite) -> None:
|
||||
"""
|
||||
assert database.logger
|
||||
assert database.logger.name == "ahriman.core.database.sqlite.SQLite"
|
||||
|
||||
|
||||
def test_logger_attribute_error(database: SQLite) -> None:
|
||||
"""
|
||||
must raise AttributeError in case if no attribute found
|
||||
"""
|
||||
with pytest.raises(AttributeError):
|
||||
database.loggerrrr
|
||||
|
@ -4,7 +4,7 @@ import pytest
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.core.status.local_client import LocalClient
|
||||
from ahriman.models.build_status import BuildStatusEnum, BuildStatus
|
||||
from ahriman.models.build_status import BuildStatus, BuildStatusEnum
|
||||
from ahriman.models.changes import Changes
|
||||
from ahriman.models.dependencies import Dependencies
|
||||
from ahriman.models.log_record_id import LogRecordId
|
||||
|
@ -2,7 +2,6 @@ import datetime
|
||||
import logging
|
||||
import os
|
||||
import pytest
|
||||
import shlex
|
||||
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
|
@ -60,4 +60,4 @@ def test_lt_invalid() -> None:
|
||||
must raise ValueError if other is not valid repository id
|
||||
"""
|
||||
with pytest.raises(ValueError):
|
||||
RepositoryId("x86_64", "a") < 42
|
||||
assert RepositoryId("x86_64", "a") < 42
|
||||
|
@ -64,6 +64,24 @@ async def test_post(client: TestClient, package_ahriman: Package) -> None:
|
||||
assert patches == [payload]
|
||||
|
||||
|
||||
async def test_post_full_diff(client: TestClient, package_ahriman: Package) -> None:
|
||||
"""
|
||||
must create patch from full diff
|
||||
"""
|
||||
await client.post(f"/api/v1/packages/{package_ahriman.base}",
|
||||
json={"status": BuildStatusEnum.Success.value, "package": package_ahriman.view()})
|
||||
request_schema = pytest.helpers.schema_request(PatchesView.post)
|
||||
|
||||
payload = {"value": "v"}
|
||||
assert not request_schema.validate(payload)
|
||||
response = await client.post(f"/api/v1/packages/{package_ahriman.base}/patches", json=payload)
|
||||
assert response.status == 204
|
||||
|
||||
response = await client.get(f"/api/v1/packages/{package_ahriman.base}/patches")
|
||||
patches = await response.json()
|
||||
assert patches == [payload]
|
||||
|
||||
|
||||
async def test_post_exception(client: TestClient, package_ahriman: Package) -> None:
|
||||
"""
|
||||
must raise exception on invalid payload
|
||||
|
@ -30,7 +30,7 @@ async def test_get(client: TestClient, repository_id: RepositoryId) -> None:
|
||||
"""
|
||||
response_schema = pytest.helpers.schema_response(InfoView.get)
|
||||
|
||||
response = await client.get(f"/api/v1/info")
|
||||
response = await client.get("/api/v1/info")
|
||||
assert response.ok
|
||||
json = await response.json()
|
||||
assert not response_schema.validate(json)
|
||||
|
@ -29,7 +29,7 @@ async def test_get(client: TestClient, repository_id: RepositoryId) -> None:
|
||||
"""
|
||||
response_schema = pytest.helpers.schema_response(RepositoriesView.get)
|
||||
|
||||
response = await client.get(f"/api/v1/repositories")
|
||||
response = await client.get("/api/v1/repositories")
|
||||
assert response.ok
|
||||
json = await response.json()
|
||||
assert not response_schema.validate(json, many=True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user