add also init command to repository object

This commit is contained in:
Evgenii Alekseev 2021-05-20 01:01:22 +03:00
parent 10806e78ae
commit e5ed74f825
4 changed files with 24 additions and 1 deletions

View File

@ -39,4 +39,4 @@ class Init(Handler):
:param architecture: repository architecture
:param configuration: configuration instance
"""
Application(architecture, configuration)
Application(architecture, configuration).repository.repo.init()

View File

@ -68,6 +68,16 @@ class Repo:
cwd=self.paths.repository,
logger=self.logger)
def init(self) -> None:
"""
create empty repository database
"""
Repo._check_output(
"repo-add", *self.sign_args, str(self.repo_path),
exception=None,
cwd=self.paths.repository,
logger=self.logger)
def remove(self, package: str, filename: Path) -> None:
"""
remove package from repository

View File

@ -11,6 +11,8 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
must run command
"""
create_tree_mock = mocker.patch("ahriman.models.repository_paths.RepositoryPaths.create_tree")
init_mock = mocker.patch("ahriman.core.alpm.repo.Repo.init")
Init.run(args, "x86_64", configuration)
create_tree_mock.assert_called_once()
init_mock.assert_called_once()

View File

@ -24,6 +24,17 @@ def test_repo_add(repo: Repo, mocker: MockerFixture) -> None:
assert check_output_mock.call_args[0][0] == "repo-add"
def test_repo_init(repo: Repo, mocker: MockerFixture) -> None:
"""
must call repo-add with empty package list on repo initializing
"""
check_output_mock = mocker.patch("ahriman.core.alpm.repo.Repo._check_output")
repo.init()
check_output_mock.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