mirror of
https://github.com/arcan1s/ahriman.git
synced 2026-04-08 03:13:37 +00:00
* store built packages in archive tree instead of repository * write tests to support new changes * implement atomic_move method, move files only with lock * use generic packages tree for all repos * lookup through archive packages before build * add archive trigger * add archive trigger * regenerate docs * gpg loader fix * support requires repostory flag * drop excess REQUIRES_REPOSITORY * simplify symlionk creation * remove generators * fix sttyle * add separate function for symlinks creation * fix rebase * add note about slicing * smol refactoring of archive_tree class * remove duplicate code * fix typos * few review fixes * monor fixes and typos * clean empty directories * remove side effect from getter * drop recursive remove * ensure_exists now accepts only argument * add package like guard to symlinks fix * speedup archive_lookup processing by iterrupting cycle * remove custom filelock * fix naming * remove remove flag from repo * review fixes * restore wrapper around filelock * extract repository explorer to separate class * docs update * fix ide findings
70 lines
2.7 KiB
Python
70 lines
2.7 KiB
Python
import pytest
|
|
|
|
from pytest_mock import MockerFixture
|
|
|
|
from ahriman.core.configuration import Configuration
|
|
from ahriman.core.database import SQLite
|
|
from ahriman.models.repository_id import RepositoryId
|
|
|
|
|
|
def test_load(configuration: Configuration, mocker: MockerFixture) -> None:
|
|
"""
|
|
must correctly load instance
|
|
"""
|
|
init_mock = mocker.patch("ahriman.core.database.SQLite.init")
|
|
SQLite.load(configuration)
|
|
init_mock.assert_called_once_with()
|
|
|
|
|
|
def test_init(database: SQLite, mocker: MockerFixture) -> None:
|
|
"""
|
|
must run migrations on init
|
|
"""
|
|
migrate_schema_mock = mocker.patch("ahriman.core.database.migrations.Migrations.migrate")
|
|
database.init()
|
|
migrate_schema_mock.assert_called_once_with(pytest.helpers.anyvar(int), database._configuration)
|
|
|
|
|
|
def test_init_skip_migration(database: SQLite, mocker: MockerFixture) -> None:
|
|
"""
|
|
must skip migrations if option is set
|
|
"""
|
|
database._configuration.set_option("settings", "apply_migrations", "no")
|
|
migrate_schema_mock = mocker.patch("ahriman.core.database.migrations.Migrations.migrate")
|
|
|
|
database.init()
|
|
migrate_schema_mock.assert_not_called()
|
|
|
|
|
|
def test_init_skip_empty_repository(database: SQLite, mocker: MockerFixture) -> None:
|
|
"""
|
|
must skip migrations if repository identifier is not set
|
|
"""
|
|
database._repository_id = RepositoryId("", "")
|
|
migrate_schema_mock = mocker.patch("ahriman.core.database.migrations.Migrations.migrate")
|
|
|
|
database.init()
|
|
migrate_schema_mock.assert_not_called()
|
|
|
|
|
|
def test_package_clear(database: SQLite, repository_id: RepositoryId, mocker: MockerFixture) -> None:
|
|
"""
|
|
must clear package data
|
|
"""
|
|
build_queue_mock = mocker.patch("ahriman.core.database.SQLite.build_queue_clear")
|
|
patches_mock = mocker.patch("ahriman.core.database.SQLite.patches_remove")
|
|
logs_mock = mocker.patch("ahriman.core.database.SQLite.logs_remove")
|
|
changes_mock = mocker.patch("ahriman.core.database.SQLite.changes_remove")
|
|
dependencies_mock = mocker.patch("ahriman.core.database.SQLite.dependencies_remove")
|
|
package_mock = mocker.patch("ahriman.core.database.SQLite.package_remove")
|
|
tree_clear_mock = mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_clear")
|
|
|
|
database.package_clear("package", repository_id)
|
|
build_queue_mock.assert_called_once_with("package", repository_id)
|
|
patches_mock.assert_called_once_with("package", None)
|
|
logs_mock.assert_called_once_with("package", None, repository_id)
|
|
changes_mock.assert_called_once_with("package", repository_id)
|
|
dependencies_mock.assert_called_once_with("package", repository_id)
|
|
package_mock.assert_called_once_with("package", repository_id)
|
|
tree_clear_mock.assert_called_once_with("package")
|