From 6946745153381dff25561e7f3ada951376cf1c65 Mon Sep 17 00:00:00 2001 From: Evgeniy Alekseev Date: Wed, 6 Apr 2022 01:48:03 +0300 Subject: [PATCH] fix descriptions --- .../application/application/packages.py | 6 ++++-- src/ahriman/core/database/data/__init__.py | 6 +++--- .../database/operations/auth_operations.py | 4 +--- src/ahriman/core/database/sqlite.py | 13 ++++++++++++- src/ahriman/models/package_source.py | 2 ++ .../application/test_application_packages.py | 10 +++++----- .../handlers/test_handler_search.py | 2 +- .../handlers/test_handler_status.py | 2 +- .../handlers/test_handler_unsafe_commands.py | 2 +- .../application/handlers/test_handler_web.py | 2 +- tests/ahriman/conftest.py | 4 +--- .../core/database/data/test_data_init.py | 2 ++ .../core/formatters/test_build_printer.py | 4 ++-- tests/ahriman/core/report/test_email.py | 2 +- tests/ahriman/core/repository/test_executor.py | 4 ++++ tests/ahriman/core/status/test_client.py | 2 +- tests/ahriman/core/status/test_web_client.py | 18 +++++++++--------- tests/ahriman/core/test_configuration.py | 2 +- tests/ahriman/models/test_build_status.py | 2 +- tests/ahriman/models/test_package.py | 4 ++-- 20 files changed, 55 insertions(+), 38 deletions(-) diff --git a/src/ahriman/application/application/packages.py b/src/ahriman/application/application/packages.py index 52b618c1..e2dc5747 100644 --- a/src/ahriman/application/application/packages.py +++ b/src/ahriman/application/application/packages.py @@ -67,7 +67,8 @@ class Packages(Properties): :param without_dependencies: if set, dependency check will be disabled """ package = Package.load(source, PackageSource.AUR, self.repository.pacman, self.repository.aur_url) - self.repository.database.build_queue_insert(package) + + self.database.build_queue_insert(package) with tmpdir() as local_path: Sources.load(local_path, package.git_url, self.database.patches_get(package.base)) @@ -93,7 +94,8 @@ class Packages(Properties): cache_dir = self.repository.paths.cache_for(package.base) shutil.copytree(Path(source), cache_dir) # copy package to store in caches Sources.init(cache_dir) # we need to run init command in directory where we do have permissions - self.repository.database.build_queue_insert(package) + + self.database.build_queue_insert(package) self._process_dependencies(cache_dir, known_packages, without_dependencies) diff --git a/src/ahriman/core/database/data/__init__.py b/src/ahriman/core/database/data/__init__.py index 17aadaca..bf93944e 100644 --- a/src/ahriman/core/database/data/__init__.py +++ b/src/ahriman/core/database/data/__init__.py @@ -20,9 +20,9 @@ from sqlite3 import Connection from ahriman.core.configuration import Configuration +from ahriman.core.database.data.package_statuses import migrate_package_statuses from ahriman.core.database.data.patches import migrate_patches from ahriman.core.database.data.users import migrate_users_data -from ahriman.core.database.data.package_statuses import migrate_package_statuses from ahriman.models.migration_result import MigrationResult from ahriman.models.repository_paths import RepositoryPaths @@ -37,7 +37,7 @@ def migrate_data(result: MigrationResult, connection: Connection, :param paths: repository paths instance """ # initial data migration - if result.old_version == 0: + if result.old_version <= 0: migrate_package_statuses(connection, paths) - migrate_users_data(connection, configuration) migrate_patches(connection, paths) + migrate_users_data(connection, configuration) diff --git a/src/ahriman/core/database/operations/auth_operations.py b/src/ahriman/core/database/operations/auth_operations.py index f9831da0..bd6c97fc 100644 --- a/src/ahriman/core/database/operations/auth_operations.py +++ b/src/ahriman/core/database/operations/auth_operations.py @@ -17,8 +17,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -from __future__ import annotations - from sqlite3 import Connection from typing import List, Optional @@ -75,7 +73,7 @@ class AuthOperations(Operations): def user_update(self, user: User) -> None: """ - get user by username + update user by username :param user: user descriptor """ def run(connection: Connection) -> None: diff --git a/src/ahriman/core/database/sqlite.py b/src/ahriman/core/database/sqlite.py index 7f98f8ae..433bab1d 100644 --- a/src/ahriman/core/database/sqlite.py +++ b/src/ahriman/core/database/sqlite.py @@ -22,6 +22,7 @@ from __future__ import annotations import json import sqlite3 +from pathlib import Path from sqlite3 import Connection from typing import Type @@ -46,10 +47,20 @@ class SQLite(AuthOperations, BuildOperations, PackageOperations, PatchOperations :param configuration: configuration instance :return: fully initialized instance of the database """ - database = cls(configuration.getpath("settings", "database")) + path = cls.database_path(configuration) + database = cls(path) database.init(configuration) return database + @staticmethod + def database_path(configuration: Configuration) -> Path: + """ + read database from configuration + :param configuration: configuration instance + :return: database path according to the configuration + """ + return configuration.getpath("settings", "database") + def init(self, configuration: Configuration) -> None: """ perform database migrations diff --git a/src/ahriman/models/package_source.py b/src/ahriman/models/package_source.py index be3f587e..34b3b446 100644 --- a/src/ahriman/models/package_source.py +++ b/src/ahriman/models/package_source.py @@ -35,6 +35,7 @@ class PackageSource(Enum): :cvar Directory: source is a directory which contains packages :cvar Local: source is locally stored PKGBUILD :cvar Remote: source is remote (http, ftp etc) link + :cvar Repository: source is official repository """ Auto = "auto" @@ -43,6 +44,7 @@ class PackageSource(Enum): Directory = "directory" Local = "local" Remote = "remote" + Repository = "repository" def resolve(self, source: str) -> PackageSource: """ diff --git a/tests/ahriman/application/application/test_application_packages.py b/tests/ahriman/application/application/test_application_packages.py index 50d4c07c..938ea6ce 100644 --- a/tests/ahriman/application/application/test_application_packages.py +++ b/tests/ahriman/application/application/test_application_packages.py @@ -21,7 +21,7 @@ def test_finalize(application_packages: Packages) -> None: def test_known_packages(application_packages: Packages) -> None: """ - must raise NotImplemented for missing finalize method + must raise NotImplemented for missing known_packages method """ with pytest.raises(NotImplementedError): application_packages._known_packages() @@ -42,17 +42,17 @@ def test_add_aur(application_packages: Packages, package_ahriman: Package, mocke must add package from AUR """ mocker.patch("ahriman.models.package.Package.load", return_value=package_ahriman) - insert_mock = mocker.patch("ahriman.core.database.sqlite.SQLite.build_queue_insert") load_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.load") dependencies_mock = mocker.patch("ahriman.application.application.packages.Packages._process_dependencies") + build_queue_mock = mocker.patch("ahriman.core.database.sqlite.SQLite.build_queue_insert") application_packages._add_aur(package_ahriman.base, set(), False) - insert_mock.assert_called_once_with(package_ahriman) load_mock.assert_called_once_with( pytest.helpers.anyvar(int), package_ahriman.git_url, pytest.helpers.anyvar(int)) dependencies_mock.assert_called_once_with(pytest.helpers.anyvar(int), set(), False) + build_queue_mock.assert_called_once_with(package_ahriman) def test_add_directory(application_packages: Packages, package_ahriman: Package, mocker: MockerFixture) -> None: @@ -75,16 +75,16 @@ def test_add_local(application_packages: Packages, package_ahriman: Package, moc """ mocker.patch("ahriman.models.package.Package.load", return_value=package_ahriman) init_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.init") - insert_mock = mocker.patch("ahriman.core.database.sqlite.SQLite.build_queue_insert") copytree_mock = mocker.patch("shutil.copytree") dependencies_mock = mocker.patch("ahriman.application.application.packages.Packages._process_dependencies") + build_queue_mock = mocker.patch("ahriman.core.database.sqlite.SQLite.build_queue_insert") application_packages._add_local(package_ahriman.base, set(), False) copytree_mock.assert_called_once_with( Path(package_ahriman.base), application_packages.repository.paths.cache_for(package_ahriman.base)) init_mock.assert_called_once_with(application_packages.repository.paths.cache_for(package_ahriman.base)) - insert_mock.assert_called_once_with(package_ahriman) dependencies_mock.assert_called_once_with(pytest.helpers.anyvar(int), set(), False) + build_queue_mock.assert_called_once_with(package_ahriman) def test_add_remote(application_packages: Packages, package_description_ahriman: PackageDescription, diff --git a/tests/ahriman/application/handlers/test_handler_search.py b/tests/ahriman/application/handlers/test_handler_search.py index 01792214..3ec8bbe8 100644 --- a/tests/ahriman/application/handlers/test_handler_search.py +++ b/tests/ahriman/application/handlers/test_handler_search.py @@ -41,7 +41,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, aur_package def test_run_empty_exception(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None: """ - must run command + must raise ExitCode exception on empty result list """ args = _default_args(args) args.exit_code = True diff --git a/tests/ahriman/application/handlers/test_handler_status.py b/tests/ahriman/application/handlers/test_handler_status.py index fbba30a8..6fd2e22d 100644 --- a/tests/ahriman/application/handlers/test_handler_status.py +++ b/tests/ahriman/application/handlers/test_handler_status.py @@ -62,7 +62,7 @@ def test_run_empty_exception(args: argparse.Namespace, configuration: Configurat def test_run_verbose(args: argparse.Namespace, configuration: Configuration, package_ahriman: Package, mocker: MockerFixture) -> None: """ - must run command + must run command with detailed info """ args = _default_args(args) args.info = True diff --git a/tests/ahriman/application/handlers/test_handler_unsafe_commands.py b/tests/ahriman/application/handlers/test_handler_unsafe_commands.py index 720e3d26..8e5a1279 100644 --- a/tests/ahriman/application/handlers/test_handler_unsafe_commands.py +++ b/tests/ahriman/application/handlers/test_handler_unsafe_commands.py @@ -59,7 +59,7 @@ def test_check_unsafe() -> None: def test_check_unsafe_safe() -> None: """ - must check if command is unsafe + must check if command is safe """ UnsafeCommands.check_unsafe("package-status", ["repo-clean"], _parser()) diff --git a/tests/ahriman/application/handlers/test_handler_web.py b/tests/ahriman/application/handlers/test_handler_web.py index f85bc28f..8f42130c 100644 --- a/tests/ahriman/application/handlers/test_handler_web.py +++ b/tests/ahriman/application/handlers/test_handler_web.py @@ -34,7 +34,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc def test_disallow_auto_architecture_run() -> None: """ - must not allow multi architecture run + must not allow auto architecture run """ assert not Web.ALLOW_AUTO_ARCHITECTURE_RUN diff --git a/tests/ahriman/conftest.py b/tests/ahriman/conftest.py index fe9ae82d..301edbda 100644 --- a/tests/ahriman/conftest.py +++ b/tests/ahriman/conftest.py @@ -264,9 +264,7 @@ def repository_paths(configuration: Configuration) -> RepositoryPaths: :param configuration: configuration fixture :return: repository paths test instance """ - return RepositoryPaths( - architecture="x86_64", - root=configuration.getpath("repository", "root")) + return configuration.repository_paths @pytest.fixture diff --git a/tests/ahriman/core/database/data/test_data_init.py b/tests/ahriman/core/database/data/test_data_init.py index cd7bf1fa..a02440fb 100644 --- a/tests/ahriman/core/database/data/test_data_init.py +++ b/tests/ahriman/core/database/data/test_data_init.py @@ -13,10 +13,12 @@ def test_migrate_data_initial(connection: Connection, configuration: Configurati 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") migrate_data(MigrationResult(old_version=0, new_version=900), connection, configuration, repository_paths) packages.assert_called_once_with(connection, repository_paths) + patches.assert_called_once_with(connection, repository_paths) users.assert_called_once_with(connection, configuration) diff --git a/tests/ahriman/core/formatters/test_build_printer.py b/tests/ahriman/core/formatters/test_build_printer.py index 285f6a46..fd5ac9e4 100644 --- a/tests/ahriman/core/formatters/test_build_printer.py +++ b/tests/ahriman/core/formatters/test_build_printer.py @@ -21,7 +21,7 @@ def test_sign_ascii(package_ahriman: Package) -> None: def test_sign_utf8(package_ahriman: Package) -> None: """ - must correctly generate sign in ascii + must correctly generate sign in utf8 """ with pytest.raises(UnicodeEncodeError): BuildPrinter(package_ahriman, is_success=True, use_utf=True).title().encode("ascii") @@ -31,6 +31,6 @@ def test_sign_utf8(package_ahriman: Package) -> None: def test_title(package_ahriman: Package) -> None: """ - must return non empty title + must return non-empty title """ assert BuildPrinter(package_ahriman, is_success=True, use_utf=False).title() is not None diff --git a/tests/ahriman/core/report/test_email.py b/tests/ahriman/core/report/test_email.py index 343e4ee0..f215702d 100644 --- a/tests/ahriman/core/report/test_email.py +++ b/tests/ahriman/core/report/test_email.py @@ -115,7 +115,7 @@ def test_generate_with_built_and_full_path( result: Result, mocker: MockerFixture) -> None: """ - must generate report with built packages + must generate report with built packages and full packages lists """ send_mock = mocker.patch("ahriman.core.report.email.Email._send") diff --git a/tests/ahriman/core/repository/test_executor.py b/tests/ahriman/core/repository/test_executor.py index eb51e7dd..c1c24075 100644 --- a/tests/ahriman/core/repository/test_executor.py +++ b/tests/ahriman/core/repository/test_executor.py @@ -64,6 +64,8 @@ def test_process_remove_base(executor: Executor, package_ahriman: Package, mocke mocker.patch("ahriman.core.repository.executor.Executor.packages", return_value=[package_ahriman]) tree_clear_mock = mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_clear") repo_remove_mock = mocker.patch("ahriman.core.alpm.repo.Repo.remove") + build_queue_mock = mocker.patch("ahriman.core.database.sqlite.SQLite.build_queue_clear") + patches_mock = mocker.patch("ahriman.core.database.sqlite.SQLite.patches_remove") status_client_mock = mocker.patch("ahriman.core.status.client.Client.remove") executor.process_remove([package_ahriman.base]) @@ -72,6 +74,8 @@ def test_process_remove_base(executor: Executor, package_ahriman: Package, mocke package_ahriman.base, package_ahriman.packages[package_ahriman.base].filepath) # must update status and remove package files tree_clear_mock.assert_called_once_with(package_ahriman.base) + build_queue_mock.assert_called_once_with(package_ahriman.base) + patches_mock.assert_called_once_with(package_ahriman.base) status_client_mock.assert_called_once_with(package_ahriman.base) diff --git a/tests/ahriman/core/status/test_client.py b/tests/ahriman/core/status/test_client.py index f22c848f..bc1518e3 100644 --- a/tests/ahriman/core/status/test_client.py +++ b/tests/ahriman/core/status/test_client.py @@ -26,7 +26,7 @@ def test_load_full_client(configuration: Configuration) -> None: def test_load_full_client_from_address(configuration: Configuration) -> None: """ - must load full client if settings set + must load full client by using address """ configuration.set_option("web", "address", "http://localhost:8080") assert isinstance(Client.load(configuration), WebClient) diff --git a/tests/ahriman/core/status/test_web_client.py b/tests/ahriman/core/status/test_web_client.py index a8ffa2ba..9e2eef85 100644 --- a/tests/ahriman/core/status/test_web_client.py +++ b/tests/ahriman/core/status/test_web_client.py @@ -23,7 +23,7 @@ def test_ahriman_url(web_client: WebClient) -> None: def test_status_url(web_client: WebClient) -> None: """ - must generate service status url correctly + must generate package status url correctly """ assert web_client._status_url.startswith(web_client.address) assert web_client._status_url.endswith("/status-api/v1/status") @@ -67,7 +67,7 @@ def test_login_failed(web_client: WebClient, user: User, mocker: MockerFixture) def test_login_failed_http_error(web_client: WebClient, user: User, mocker: MockerFixture) -> None: """ - must suppress any exception happened during login + must suppress HTTP exception happened during login """ web_client.user = user mocker.patch("requests.Session.post", side_effect=requests.exceptions.HTTPError()) @@ -112,7 +112,7 @@ def test_add_failed(web_client: WebClient, package_ahriman: Package, mocker: Moc def test_add_failed_http_error(web_client: WebClient, package_ahriman: Package, mocker: MockerFixture) -> None: """ - must suppress any exception happened during addition + must suppress HTTP exception happened during addition """ mocker.patch("requests.Session.post", side_effect=requests.exceptions.HTTPError()) web_client.add(package_ahriman, BuildStatusEnum.Unknown) @@ -145,7 +145,7 @@ def test_get_failed(web_client: WebClient, mocker: MockerFixture) -> None: def test_get_failed_http_error(web_client: WebClient, mocker: MockerFixture) -> None: """ - must suppress any exception happened during status getting + must suppress HTTP exception happened during status getting """ mocker.patch("requests.Session.get", side_effect=requests.exceptions.HTTPError()) assert web_client.get(None) == [] @@ -193,7 +193,7 @@ def test_get_internal_failed(web_client: WebClient, mocker: MockerFixture) -> No def test_get_internal_failed_http_error(web_client: WebClient, mocker: MockerFixture) -> None: """ - must suppress any exception happened during web service status getting + must suppress HTTP exception happened during web service status getting """ mocker.patch("requests.Session.get", side_effect=requests.exceptions.HTTPError()) assert web_client.get_internal() == InternalStatus() @@ -224,7 +224,7 @@ def test_get_self_failed(web_client: WebClient, mocker: MockerFixture) -> None: def test_get_self_failed_http_error(web_client: WebClient, mocker: MockerFixture) -> None: """ - must suppress any exception happened during service status getting + must suppress HTTP exception happened during service status getting """ mocker.patch("requests.Session.get", side_effect=requests.exceptions.HTTPError()) assert web_client.get_self().status == BuildStatusEnum.Unknown @@ -250,7 +250,7 @@ def test_remove_failed(web_client: WebClient, package_ahriman: Package, mocker: def test_remove_failed_http_error(web_client: WebClient, package_ahriman: Package, mocker: MockerFixture) -> None: """ - must suppress any exception happened during removal + must suppress HTTP exception happened during removal """ mocker.patch("requests.Session.delete", side_effect=requests.exceptions.HTTPError()) web_client.remove(package_ahriman.base) @@ -277,7 +277,7 @@ def test_update_failed(web_client: WebClient, package_ahriman: Package, mocker: def test_update_failed_http_error(web_client: WebClient, package_ahriman: Package, mocker: MockerFixture) -> None: """ - must suppress any exception happened during update + must suppress HTTP exception happened during update """ mocker.patch("requests.Session.post", side_effect=requests.exceptions.HTTPError()) web_client.update(package_ahriman.base, BuildStatusEnum.Unknown) @@ -304,7 +304,7 @@ def test_update_self_failed(web_client: WebClient, mocker: MockerFixture) -> Non def test_update_self_failed_http_error(web_client: WebClient, mocker: MockerFixture) -> None: """ - must suppress any exception happened during service update + must suppress HTTP exception happened during service update """ mocker.patch("requests.Session.post", side_effect=requests.exceptions.HTTPError()) web_client.update_self(BuildStatusEnum.Unknown) diff --git a/tests/ahriman/core/test_configuration.py b/tests/ahriman/core/test_configuration.py index 0106d16f..790750eb 100644 --- a/tests/ahriman/core/test_configuration.py +++ b/tests/ahriman/core/test_configuration.py @@ -231,7 +231,7 @@ def test_gettype_from_section_with_architecture(configuration: Configuration) -> def test_gettype_from_section_no_section(configuration: Configuration) -> None: """ - must extract type from section name with architecture + must raise NoSectionError during type extraction from section name with architecture """ # technically rsync:x86_64 is valid section # but in current configuration it must be considered as missing section diff --git a/tests/ahriman/models/test_build_status.py b/tests/ahriman/models/test_build_status.py index 7af4a9b7..1473d823 100644 --- a/tests/ahriman/models/test_build_status.py +++ b/tests/ahriman/models/test_build_status.py @@ -19,7 +19,7 @@ def test_build_status_enum_badges_color() -> None: def test_build_status_enum_bootstrap_color() -> None: """ - status color must be one of shields.io supported + status color must be one of bootstrap supported """ SUPPORTED_COLORS = [ "primary", "secondary", "success", "danger", "warning", "info", "light", "dark" diff --git a/tests/ahriman/models/test_package.py b/tests/ahriman/models/test_package.py index 675538e3..61454993 100644 --- a/tests/ahriman/models/test_package.py +++ b/tests/ahriman/models/test_package.py @@ -281,7 +281,7 @@ def test_actual_version_srcinfo_failed(package_tpacpi_bat_git: Package, reposito def test_actual_version_vcs_failed(package_tpacpi_bat_git: Package, repository_paths: RepositoryPaths, mocker: MockerFixture) -> None: """ - must return same version in case if exception occurred + must return same version in case if there are errors during parse """ mocker.patch("pathlib.Path.read_text", return_value="") mocker.patch("ahriman.models.package.parse_srcinfo", return_value=({"packages": {}}, ["an error"])) @@ -292,7 +292,7 @@ def test_actual_version_vcs_failed(package_tpacpi_bat_git: Package, repository_p def test_full_depends(package_ahriman: Package, package_python_schedule: Package, pyalpm_package_ahriman: MagicMock, - pyalpm_handle: MagicMock, mocker: MockerFixture) -> None: + pyalpm_handle: MagicMock) -> None: """ must extract all dependencies from the package """