mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-23 18:59:56 +00:00
calculate dependencies based on package information (#89)
This commit is contained in:
@ -20,7 +20,7 @@ def leaf_ahriman(package_ahriman: Package) -> Leaf:
|
||||
Returns:
|
||||
Leaf: tree leaf test instance
|
||||
"""
|
||||
return Leaf(package_ahriman, set())
|
||||
return Leaf(package_ahriman)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -34,7 +34,7 @@ def leaf_python_schedule(package_python_schedule: Package) -> Leaf:
|
||||
Returns:
|
||||
Leaf: tree leaf test instance
|
||||
"""
|
||||
return Leaf(package_python_schedule, set())
|
||||
return Leaf(package_python_schedule)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -1,47 +0,0 @@
|
||||
from pytest_mock import MockerFixture
|
||||
from sqlite3 import Connection
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.database.data import migrate_data
|
||||
from ahriman.models.migration_result import MigrationResult
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
|
||||
def test_migrate_data_initial(connection: Connection, configuration: Configuration,
|
||||
repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must perform initial migration
|
||||
"""
|
||||
packages = mocker.patch("ahriman.core.database.data.migrate_package_statuses")
|
||||
patches = mocker.patch("ahriman.core.database.data.migrate_patches")
|
||||
users = mocker.patch("ahriman.core.database.data.migrate_users_data")
|
||||
remotes = mocker.patch("ahriman.core.database.data.migrate_package_remotes")
|
||||
|
||||
migrate_data(MigrationResult(old_version=0, new_version=900), connection, configuration)
|
||||
packages.assert_called_once_with(connection, repository_paths)
|
||||
patches.assert_called_once_with(connection, repository_paths)
|
||||
users.assert_called_once_with(connection, configuration)
|
||||
remotes.assert_called_once_with(connection, repository_paths)
|
||||
|
||||
|
||||
def test_migrate_data_remotes(connection: Connection, configuration: Configuration,
|
||||
repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must perform initial migration
|
||||
"""
|
||||
remotes = mocker.patch("ahriman.core.database.data.migrate_package_remotes")
|
||||
|
||||
migrate_data(MigrationResult(old_version=1, new_version=900), connection, configuration)
|
||||
remotes.assert_called_once_with(connection, repository_paths)
|
||||
|
||||
|
||||
def test_migrate_data_skip(connection: Connection, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must not migrate data if version is up-to-date
|
||||
"""
|
||||
packages = mocker.patch("ahriman.core.database.data.migrate_package_statuses")
|
||||
users = mocker.patch("ahriman.core.database.data.migrate_users_data")
|
||||
|
||||
migrate_data(MigrationResult(old_version=900, new_version=900), connection, configuration)
|
||||
packages.assert_not_called()
|
||||
users.assert_not_called()
|
@ -1,66 +0,0 @@
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
from sqlite3 import Connection
|
||||
|
||||
from ahriman.core.database.data import migrate_package_remotes
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
|
||||
def test_migrate_package_remotes(package_ahriman: Package, connection: Connection, repository_paths: RepositoryPaths,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must put package remotes to database
|
||||
"""
|
||||
mocker.patch(
|
||||
"ahriman.core.database.operations.PackageOperations._packages_get_select_package_bases",
|
||||
return_value={package_ahriman.base: package_ahriman})
|
||||
mocker.patch("pathlib.Path.exists", return_value=False)
|
||||
|
||||
migrate_package_remotes(connection, repository_paths)
|
||||
connection.execute.assert_called_once_with(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_migrate_package_remotes_has_local(package_ahriman: Package, connection: Connection,
|
||||
repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip processing for packages which have local cache
|
||||
"""
|
||||
mocker.patch(
|
||||
"ahriman.core.database.operations.PackageOperations._packages_get_select_package_bases",
|
||||
return_value={package_ahriman.base: package_ahriman})
|
||||
mocker.patch("pathlib.Path.exists", return_value=True)
|
||||
|
||||
migrate_package_remotes(connection, repository_paths)
|
||||
connection.execute.assert_not_called()
|
||||
|
||||
|
||||
def test_migrate_package_remotes_vcs(package_ahriman: Package, connection: Connection,
|
||||
repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must process VCS packages with local cache
|
||||
"""
|
||||
mocker.patch(
|
||||
"ahriman.core.database.operations.PackageOperations._packages_get_select_package_bases",
|
||||
return_value={package_ahriman.base: package_ahriman})
|
||||
mocker.patch("pathlib.Path.exists", return_value=True)
|
||||
mocker.patch.object(Package, "is_vcs", True)
|
||||
|
||||
migrate_package_remotes(connection, repository_paths)
|
||||
connection.execute.assert_called_once_with(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_migrate_package_remotes_no_remotes(package_ahriman: Package, connection: Connection,
|
||||
repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip processing in case if no remotes generated (should never happen)
|
||||
"""
|
||||
mocker.patch(
|
||||
"ahriman.core.database.operations.PackageOperations._packages_get_select_package_bases",
|
||||
return_value={package_ahriman.base: package_ahriman})
|
||||
mocker.patch("pathlib.Path.exists", return_value=False)
|
||||
mocker.patch("ahriman.models.remote_source.RemoteSource.from_source", return_value=None)
|
||||
|
||||
migrate_package_remotes(connection, repository_paths)
|
||||
connection.execute.assert_not_called()
|
@ -1,39 +0,0 @@
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
from sqlite3 import Connection
|
||||
from unittest.mock import call as MockCall
|
||||
|
||||
from ahriman.core.database.data import migrate_package_statuses
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
|
||||
def test_migrate_package_statuses(connection: Connection, package_ahriman: Package, repository_paths: RepositoryPaths,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must migrate packages to database
|
||||
"""
|
||||
response = {"packages": [pytest.helpers.get_package_status_extended(package_ahriman)]}
|
||||
|
||||
mocker.patch("pathlib.Path.is_file", return_value=True)
|
||||
mocker.patch("pathlib.Path.open")
|
||||
mocker.patch("json.load", return_value=response)
|
||||
|
||||
migrate_package_statuses(connection, repository_paths)
|
||||
connection.execute.assert_has_calls([
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int)),
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int)),
|
||||
])
|
||||
connection.executemany.assert_has_calls([
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int)),
|
||||
])
|
||||
|
||||
|
||||
def test_migrate_package_statuses_skip(connection: Connection, repository_paths: RepositoryPaths,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip packages migration if no cache file found
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_file", return_value=False)
|
||||
migrate_package_statuses(connection, repository_paths)
|
@ -1,52 +0,0 @@
|
||||
import pytest
|
||||
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
from sqlite3 import Connection
|
||||
|
||||
from ahriman.core.database.data import migrate_patches
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
|
||||
def test_migrate_patches(connection: Connection, repository_paths: RepositoryPaths,
|
||||
package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must perform migration for patches
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
mocker.patch("pathlib.Path.is_file", return_value=True)
|
||||
iterdir_mock = mocker.patch("pathlib.Path.iterdir", return_value=[Path(package_ahriman.base)])
|
||||
read_mock = mocker.patch("pathlib.Path.read_text", return_value="patch")
|
||||
|
||||
migrate_patches(connection, repository_paths)
|
||||
iterdir_mock.assert_called_once_with()
|
||||
read_mock.assert_called_once_with(encoding="utf8")
|
||||
connection.execute.assert_called_once_with(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_migrate_patches_skip(connection: Connection, repository_paths: RepositoryPaths,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip patches migration in case if no root found
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
iterdir_mock = mocker.patch("pathlib.Path.iterdir")
|
||||
|
||||
migrate_patches(connection, repository_paths)
|
||||
iterdir_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_migrate_patches_no_patch(connection: Connection, repository_paths: RepositoryPaths,
|
||||
package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip package if no match found
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
mocker.patch("pathlib.Path.is_file", return_value=False)
|
||||
iterdir_mock = mocker.patch("pathlib.Path.iterdir", return_value=[Path(package_ahriman.base)])
|
||||
read_mock = mocker.patch("pathlib.Path.read_text")
|
||||
|
||||
migrate_patches(connection, repository_paths)
|
||||
iterdir_mock.assert_called_once_with()
|
||||
read_mock.assert_not_called()
|
@ -1,21 +0,0 @@
|
||||
import pytest
|
||||
|
||||
from sqlite3 import Connection
|
||||
from unittest.mock import call as MockCall
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.database.data import migrate_users_data
|
||||
|
||||
|
||||
def test_migrate_users_data(connection: Connection, configuration: Configuration) -> None:
|
||||
"""
|
||||
must put users to database
|
||||
"""
|
||||
configuration.set_option("auth:read", "user1", "password1")
|
||||
configuration.set_option("auth:write", "user2", "password2")
|
||||
|
||||
migrate_users_data(connection, configuration)
|
||||
connection.execute.assert_has_calls([
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int)),
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int)),
|
||||
])
|
@ -1,4 +1,15 @@
|
||||
from ahriman.core.database.migrations.m000_initial import steps
|
||||
import pytest
|
||||
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
from sqlite3 import Connection
|
||||
from unittest.mock import call as MockCall
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.database.migrations.m000_initial import migrate_data, migrate_package_statuses, migrate_patches, \
|
||||
migrate_users_data, steps
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
|
||||
def test_migration_initial() -> None:
|
||||
@ -6,3 +17,104 @@ def test_migration_initial() -> None:
|
||||
migration must not be empty
|
||||
"""
|
||||
assert steps
|
||||
|
||||
|
||||
def test_migrate_data(connection: Connection, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must perform data migration
|
||||
"""
|
||||
packages = mocker.patch("ahriman.core.database.migrations.m000_initial.migrate_package_statuses")
|
||||
patches = mocker.patch("ahriman.core.database.migrations.m000_initial.migrate_patches")
|
||||
users = mocker.patch("ahriman.core.database.migrations.m000_initial.migrate_users_data")
|
||||
|
||||
migrate_data(connection, configuration)
|
||||
packages.assert_called_once_with(connection, configuration.repository_paths)
|
||||
patches.assert_called_once_with(connection, configuration.repository_paths)
|
||||
users.assert_called_once_with(connection, configuration)
|
||||
|
||||
|
||||
def test_migrate_package_statuses(connection: Connection, package_ahriman: Package, repository_paths: RepositoryPaths,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must migrate packages to database
|
||||
"""
|
||||
response = {"packages": [pytest.helpers.get_package_status_extended(package_ahriman)]}
|
||||
|
||||
mocker.patch("pathlib.Path.is_file", return_value=True)
|
||||
mocker.patch("pathlib.Path.open")
|
||||
mocker.patch("json.load", return_value=response)
|
||||
|
||||
migrate_package_statuses(connection, repository_paths)
|
||||
connection.execute.assert_has_calls([
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int)),
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int)),
|
||||
])
|
||||
connection.executemany.assert_has_calls([
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int)),
|
||||
])
|
||||
|
||||
|
||||
def test_migrate_package_statuses_skip(connection: Connection, repository_paths: RepositoryPaths,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip packages migration if no cache file found
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_file", return_value=False)
|
||||
migrate_package_statuses(connection, repository_paths)
|
||||
|
||||
|
||||
def test_migrate_patches(connection: Connection, repository_paths: RepositoryPaths,
|
||||
package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must perform migration for patches
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
mocker.patch("pathlib.Path.is_file", return_value=True)
|
||||
iterdir_mock = mocker.patch("pathlib.Path.iterdir", return_value=[Path(package_ahriman.base)])
|
||||
read_mock = mocker.patch("pathlib.Path.read_text", return_value="patch")
|
||||
|
||||
migrate_patches(connection, repository_paths)
|
||||
iterdir_mock.assert_called_once_with()
|
||||
read_mock.assert_called_once_with(encoding="utf8")
|
||||
connection.execute.assert_called_once_with(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_migrate_patches_skip(connection: Connection, repository_paths: RepositoryPaths,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip patches migration in case if no root found
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
iterdir_mock = mocker.patch("pathlib.Path.iterdir")
|
||||
|
||||
migrate_patches(connection, repository_paths)
|
||||
iterdir_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_migrate_patches_no_patch(connection: Connection, repository_paths: RepositoryPaths,
|
||||
package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip package if no match found
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
mocker.patch("pathlib.Path.is_file", return_value=False)
|
||||
iterdir_mock = mocker.patch("pathlib.Path.iterdir", return_value=[Path(package_ahriman.base)])
|
||||
read_mock = mocker.patch("pathlib.Path.read_text")
|
||||
|
||||
migrate_patches(connection, repository_paths)
|
||||
iterdir_mock.assert_called_once_with()
|
||||
read_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_migrate_users_data(connection: Connection, configuration: Configuration) -> None:
|
||||
"""
|
||||
must put users to database
|
||||
"""
|
||||
configuration.set_option("auth:read", "user1", "password1")
|
||||
configuration.set_option("auth:write", "user2", "password2")
|
||||
|
||||
migrate_users_data(connection, configuration)
|
||||
connection.execute.assert_has_calls([
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int)),
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int)),
|
||||
])
|
||||
|
@ -1,4 +1,12 @@
|
||||
from ahriman.core.database.migrations.m001_package_source import steps
|
||||
import pytest
|
||||
|
||||
from sqlite3 import Connection
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.database.migrations.m001_package_source import migrate_data, migrate_package_remotes, steps
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
|
||||
def test_migration_package_source() -> None:
|
||||
@ -6,3 +14,70 @@ def test_migration_package_source() -> None:
|
||||
migration must not be empty
|
||||
"""
|
||||
assert steps
|
||||
|
||||
|
||||
def test_migrate_data(connection: Connection, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must perform data migration
|
||||
"""
|
||||
remotes = mocker.patch("ahriman.core.database.migrations.m001_package_source.migrate_package_remotes")
|
||||
migrate_data(connection, configuration)
|
||||
remotes.assert_called_once_with(connection, configuration.repository_paths)
|
||||
|
||||
|
||||
def test_migrate_package_remotes(package_ahriman: Package, connection: Connection, repository_paths: RepositoryPaths,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must put package remotes to database
|
||||
"""
|
||||
mocker.patch(
|
||||
"ahriman.core.database.operations.PackageOperations._packages_get_select_package_bases",
|
||||
return_value={package_ahriman.base: package_ahriman})
|
||||
mocker.patch("pathlib.Path.exists", return_value=False)
|
||||
|
||||
migrate_package_remotes(connection, repository_paths)
|
||||
connection.execute.assert_called_once_with(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_migrate_package_remotes_has_local(package_ahriman: Package, connection: Connection,
|
||||
repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip processing for packages which have local cache
|
||||
"""
|
||||
mocker.patch(
|
||||
"ahriman.core.database.operations.PackageOperations._packages_get_select_package_bases",
|
||||
return_value={package_ahriman.base: package_ahriman})
|
||||
mocker.patch("pathlib.Path.exists", return_value=True)
|
||||
|
||||
migrate_package_remotes(connection, repository_paths)
|
||||
connection.execute.assert_not_called()
|
||||
|
||||
|
||||
def test_migrate_package_remotes_vcs(package_ahriman: Package, connection: Connection,
|
||||
repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must process VCS packages with local cache
|
||||
"""
|
||||
mocker.patch(
|
||||
"ahriman.core.database.operations.PackageOperations._packages_get_select_package_bases",
|
||||
return_value={package_ahriman.base: package_ahriman})
|
||||
mocker.patch("pathlib.Path.exists", return_value=True)
|
||||
mocker.patch.object(Package, "is_vcs", True)
|
||||
|
||||
migrate_package_remotes(connection, repository_paths)
|
||||
connection.execute.assert_called_once_with(pytest.helpers.anyvar(str, strict=True), pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_migrate_package_remotes_no_remotes(package_ahriman: Package, connection: Connection,
|
||||
repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip processing in case if no remotes generated (should never happen)
|
||||
"""
|
||||
mocker.patch(
|
||||
"ahriman.core.database.operations.PackageOperations._packages_get_select_package_bases",
|
||||
return_value={package_ahriman.base: package_ahriman})
|
||||
mocker.patch("pathlib.Path.exists", return_value=False)
|
||||
mocker.patch("ahriman.models.remote_source.RemoteSource.from_source", return_value=None)
|
||||
|
||||
migrate_package_remotes(connection, repository_paths)
|
||||
connection.execute.assert_not_called()
|
||||
|
@ -0,0 +1,53 @@
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
from sqlite3 import Connection
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.database.migrations.m005_make_opt_depends import migrate_data, migrate_package_depends, steps
|
||||
from ahriman.models.package import Package
|
||||
|
||||
|
||||
def test_migration_make_opt_depends() -> None:
|
||||
"""
|
||||
migration must not be empty
|
||||
"""
|
||||
assert steps
|
||||
|
||||
|
||||
def test_migrate_data(connection: Connection, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must perform data migration
|
||||
"""
|
||||
depends_mock = mocker.patch("ahriman.core.database.migrations.m005_make_opt_depends.migrate_package_depends")
|
||||
migrate_data(connection, configuration)
|
||||
depends_mock.assert_called_once_with(connection, configuration)
|
||||
|
||||
|
||||
def test_migrate_package_depends(connection: Connection, configuration: Configuration, package_ahriman: Package,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must update make and opt depends list
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
mocker.patch("pathlib.Path.iterdir", return_value=[package_ahriman.packages[package_ahriman.base].filepath])
|
||||
package_mock = mocker.patch("ahriman.models.package.Package.from_archive", return_value=package_ahriman)
|
||||
|
||||
migrate_package_depends(connection, configuration)
|
||||
package_mock.assert_called_once_with(
|
||||
package_ahriman.packages[package_ahriman.base].filepath, pytest.helpers.anyvar(int), remote=None)
|
||||
connection.executemany.assert_called_once_with(pytest.helpers.anyvar(str, strict=True), [{
|
||||
"make_depends": package_ahriman.packages[package_ahriman.base].make_depends,
|
||||
"opt_depends": package_ahriman.packages[package_ahriman.base].opt_depends,
|
||||
"package": package_ahriman.base,
|
||||
}])
|
||||
|
||||
|
||||
def test_migrate_package_depends_skip(connection: Connection, configuration: Configuration,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip update make and opt depends list if no repository directory found
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
migrate_package_depends(connection, configuration)
|
||||
connection.executemany.assert_not_called()
|
@ -19,6 +19,19 @@ def test_migrate(connection: Connection, configuration: Configuration, mocker: M
|
||||
run_mock.assert_called_once_with()
|
||||
|
||||
|
||||
def test_migration(migrations: Migrations, connection: Connection) -> None:
|
||||
"""
|
||||
must perform single migration
|
||||
"""
|
||||
migrate_data_mock = MagicMock()
|
||||
cursor = MagicMock()
|
||||
migration = Migration(index=0, name="test", steps=["select 1"], migrate_data=migrate_data_mock)
|
||||
|
||||
migrations.migration(cursor, migration)
|
||||
cursor.execute.assert_called_once_with("select 1")
|
||||
migrate_data_mock.assert_called_once_with(migrations.connection, migrations.configuration)
|
||||
|
||||
|
||||
def test_migrations(migrations: Migrations) -> None:
|
||||
"""
|
||||
must retrieve migrations
|
||||
@ -40,25 +53,23 @@ def test_run(migrations: Migrations, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run migration
|
||||
"""
|
||||
migration = Migration(index=0, name="test", steps=["select 1"], migrate_data=MagicMock())
|
||||
cursor = MagicMock()
|
||||
mocker.patch("ahriman.core.database.migrations.Migrations.user_version", return_value=0)
|
||||
mocker.patch("ahriman.core.database.migrations.Migrations.migrations",
|
||||
return_value=[Migration(index=0, name="test", steps=["select 1"])])
|
||||
mocker.patch("ahriman.core.database.migrations.Migrations.migrations", return_value=[migration])
|
||||
migrations.connection.cursor.return_value = cursor
|
||||
migration_mock = mocker.patch("ahriman.core.database.migrations.Migrations.migration")
|
||||
validate_mock = mocker.patch("ahriman.models.migration_result.MigrationResult.validate")
|
||||
migrate_data_mock = mocker.patch("ahriman.core.database.migrations.migrate_data")
|
||||
|
||||
migrations.run()
|
||||
validate_mock.assert_called_once_with()
|
||||
cursor.execute.assert_has_calls([
|
||||
MockCall("begin exclusive"),
|
||||
MockCall("select 1"),
|
||||
MockCall("pragma user_version = 1"),
|
||||
MockCall("commit"),
|
||||
])
|
||||
cursor.close.assert_called_once_with()
|
||||
migrate_data_mock.assert_called_once_with(
|
||||
MigrationResult(old_version=0, new_version=1), migrations.connection, migrations.configuration)
|
||||
migration_mock.assert_called_once_with(cursor, migration)
|
||||
|
||||
|
||||
def test_run_migration_exception(migrations: Migrations, mocker: MockerFixture) -> None:
|
||||
@ -69,7 +80,7 @@ def test_run_migration_exception(migrations: Migrations, mocker: MockerFixture)
|
||||
mocker.patch("logging.Logger.info", side_effect=Exception())
|
||||
mocker.patch("ahriman.core.database.migrations.Migrations.user_version", return_value=0)
|
||||
mocker.patch("ahriman.core.database.migrations.Migrations.migrations",
|
||||
return_value=[Migration(index=0, name="test", steps=["select 1"])])
|
||||
return_value=[Migration(index=0, name="test", steps=["select 1"], migrate_data=MagicMock())])
|
||||
mocker.patch("ahriman.models.migration_result.MigrationResult.validate")
|
||||
migrations.connection.cursor.return_value = cursor
|
||||
|
||||
@ -90,7 +101,7 @@ def test_run_sql_exception(migrations: Migrations, mocker: MockerFixture) -> Non
|
||||
cursor.execute.side_effect = Exception()
|
||||
mocker.patch("ahriman.core.database.migrations.Migrations.user_version", return_value=0)
|
||||
mocker.patch("ahriman.core.database.migrations.Migrations.migrations",
|
||||
return_value=[Migration(index=0, name="test", steps=["select 1"])])
|
||||
return_value=[Migration(index=0, name="test", steps=["select 1"], migrate_data=MagicMock())])
|
||||
mocker.patch("ahriman.models.migration_result.MigrationResult.validate")
|
||||
migrations.connection.cursor.return_value = cursor
|
||||
|
||||
|
@ -125,7 +125,7 @@ def test_packages_depend_on(repository: Repository, package_ahriman: Package, pa
|
||||
"""
|
||||
mocker.patch("ahriman.core.repository.repository.Repository.packages",
|
||||
return_value=[package_ahriman, package_python_schedule])
|
||||
assert repository.packages_depend_on([package_ahriman], ["python-aur"]) == [package_ahriman]
|
||||
assert repository.packages_depend_on([package_ahriman], ["python-srcinfo"]) == [package_ahriman]
|
||||
|
||||
|
||||
def test_packages_depend_on_empty(repository: Repository, package_ahriman: Package, package_python_schedule: Package,
|
||||
|
@ -1,12 +1,6 @@
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.core.database import SQLite
|
||||
from ahriman.core.tree import Leaf, Tree
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.package_description import PackageDescription
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
|
||||
def test_leaf_is_root_empty(leaf_ahriman: Leaf) -> None:
|
||||
@ -39,29 +33,11 @@ def test_leaf_is_root_true(leaf_ahriman: Leaf, leaf_python_schedule: Leaf) -> No
|
||||
assert not leaf_ahriman.is_root([leaf_python_schedule])
|
||||
|
||||
|
||||
def test_leaf_load(package_ahriman: Package, repository_paths: RepositoryPaths,
|
||||
database: SQLite, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must load with dependencies
|
||||
"""
|
||||
load_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.load")
|
||||
dependencies_mock = mocker.patch("ahriman.models.package.Package.dependencies", return_value={"ahriman-dependency"})
|
||||
|
||||
leaf = Leaf.load(package_ahriman, repository_paths, database)
|
||||
assert leaf.package == package_ahriman
|
||||
assert leaf.dependencies == {"ahriman-dependency"}
|
||||
load_mock.assert_called_once_with(pytest.helpers.anyvar(int), package_ahriman, [], repository_paths)
|
||||
dependencies_mock.assert_called_once_with(pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_tree_resolve(package_ahriman: Package, package_python_schedule: Package, repository_paths: RepositoryPaths,
|
||||
database: SQLite, mocker: MockerFixture) -> None:
|
||||
def test_tree_resolve(package_ahriman: Package, package_python_schedule: Package) -> None:
|
||||
"""
|
||||
must resolve denendecnies tree
|
||||
"""
|
||||
mocker.patch("ahriman.core.tree.Leaf.load", side_effect=lambda package, p, d: Leaf(package, set(package.depends)))
|
||||
|
||||
tree = Tree.resolve([package_ahriman, package_python_schedule], repository_paths, database)
|
||||
tree = Tree.resolve([package_ahriman, package_python_schedule])
|
||||
assert len(tree) == 1
|
||||
assert len(tree[0]) == 2
|
||||
|
||||
@ -87,36 +63,32 @@ def test_tree_levels_sorted() -> None:
|
||||
base="package1",
|
||||
version="1.0.0",
|
||||
remote=None,
|
||||
packages={"package1": PackageDescription()}
|
||||
),
|
||||
dependencies=set()
|
||||
packages={"package1": PackageDescription(depends=[])}
|
||||
)
|
||||
)
|
||||
leaf2 = Leaf(
|
||||
Package(
|
||||
base="package2",
|
||||
version="1.0.0",
|
||||
remote=None,
|
||||
packages={"package2": PackageDescription()}
|
||||
),
|
||||
dependencies={"package1"}
|
||||
packages={"package2": PackageDescription(depends=["package1"])}
|
||||
)
|
||||
)
|
||||
leaf3 = Leaf(
|
||||
Package(
|
||||
base="package3",
|
||||
version="1.0.0",
|
||||
remote=None,
|
||||
packages={"package3": PackageDescription()}
|
||||
),
|
||||
dependencies={"package1"}
|
||||
packages={"package3": PackageDescription(depends=["package1"])}
|
||||
)
|
||||
)
|
||||
leaf4 = Leaf(
|
||||
Package(
|
||||
base="package4",
|
||||
version="1.0.0",
|
||||
remote=None,
|
||||
packages={"package4": PackageDescription()}
|
||||
),
|
||||
dependencies={"package3"}
|
||||
packages={"package4": PackageDescription(depends=["package3"])}
|
||||
)
|
||||
)
|
||||
|
||||
tree = Tree([leaf1, leaf2, leaf3, leaf4])
|
||||
|
@ -12,7 +12,7 @@ from unittest.mock import MagicMock
|
||||
|
||||
from ahriman.core.exceptions import BuildError, OptionError, UnsafeRunError
|
||||
from ahriman.core.util import check_output, check_user, enum_values, exception_response_text, filter_json, \
|
||||
full_version, package_like, pretty_datetime, pretty_size, safe_filename, utcnow, walk
|
||||
full_version, package_like, pretty_datetime, pretty_size, safe_filename, trim_package, utcnow, walk
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.package_source import PackageSource
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
@ -322,6 +322,18 @@ def test_safe_filename() -> None:
|
||||
assert safe_filename("tolua++-1.0.93-4-x86_64.pkg.tar.zst") == "tolua---1.0.93-4-x86_64.pkg.tar.zst"
|
||||
|
||||
|
||||
def test_trim_package() -> None:
|
||||
"""
|
||||
must trim package version
|
||||
"""
|
||||
assert trim_package("package=1") == "package"
|
||||
assert trim_package("package>=1") == "package"
|
||||
assert trim_package("package>1") == "package"
|
||||
assert trim_package("package<1") == "package"
|
||||
assert trim_package("package<=1") == "package"
|
||||
assert trim_package("package: a description") == "package"
|
||||
|
||||
|
||||
def test_utcnow() -> None:
|
||||
"""
|
||||
must generate correct timestamp
|
||||
|
@ -22,7 +22,7 @@ def test_calculate_hash_small(resource_path_root: Path) -> None:
|
||||
must calculate checksum for path which is single chunk
|
||||
"""
|
||||
path = resource_path_root / "models" / "package_ahriman_srcinfo"
|
||||
assert HttpUpload.calculate_hash(path) == "fcfc0f2522b0ee92de89fcedc7e56010"
|
||||
assert HttpUpload.calculate_hash(path) == "79b0f84e0232ed34fd191a85c383ecc5"
|
||||
|
||||
|
||||
def test_get_body_get_hashes() -> None:
|
||||
|
@ -30,7 +30,7 @@ def test_calculate_etag_small(resource_path_root: Path) -> None:
|
||||
must calculate checksum for path which is single chunk
|
||||
"""
|
||||
path = resource_path_root / "models" / "package_ahriman_srcinfo"
|
||||
assert S3.calculate_etag(path, _chunk_size) == "fcfc0f2522b0ee92de89fcedc7e56010"
|
||||
assert S3.calculate_etag(path, _chunk_size) == "79b0f84e0232ed34fd191a85c383ecc5"
|
||||
|
||||
|
||||
def test_files_remove(s3_remote_objects: List[Any]) -> None:
|
||||
|
Reference in New Issue
Block a user