mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-24 15:27:17 +00:00
complete application tests
This commit is contained in:
parent
51c4160247
commit
3a518376c0
@ -21,8 +21,8 @@ from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
from multiprocessing import Pool
|
||||
|
||||
from multiprocessing import Pool
|
||||
from typing import Type
|
||||
|
||||
from ahriman.application.lock import Lock
|
||||
|
@ -15,6 +15,10 @@ def application(configuration: Configuration, mocker: MockerFixture) -> Applicat
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def lock(configuration: Configuration) -> Lock:
|
||||
return Lock(argparse.Namespace(lock=None, force=False, unsafe=False, no_report=True),
|
||||
"x86_64", configuration)
|
||||
def args() -> argparse.Namespace:
|
||||
return argparse.Namespace(lock=None, force=False, unsafe=False, no_report=True)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def lock(args: argparse.Namespace, configuration: Configuration) -> Lock:
|
||||
return Lock(args, "x86_64", configuration)
|
||||
|
27
tests/ahriman/application/handlers/test_handler.py
Normal file
27
tests/ahriman/application/handlers/test_handler.py
Normal file
@ -0,0 +1,27 @@
|
||||
import argparse
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.application.handlers import Handler
|
||||
from ahriman.core.configuration import Configuration
|
||||
|
||||
|
||||
def test_call(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must call inside lock
|
||||
"""
|
||||
mocker.patch("ahriman.application.handlers.Handler.run")
|
||||
enter_mock = mocker.patch("ahriman.application.lock.Lock.__enter__")
|
||||
exit_mock = mocker.patch("ahriman.application.lock.Lock.__exit__")
|
||||
|
||||
assert Handler._call(args, "x86_64", configuration)
|
||||
enter_mock.assert_called_once()
|
||||
exit_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_call_exception(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must process exception
|
||||
"""
|
||||
mocker.patch("ahriman.application.lock.Lock.__enter__", side_effect=Exception())
|
||||
assert not Handler._call(args, "x86_64", configuration)
|
19
tests/ahriman/application/handlers/test_handler_add.py
Normal file
19
tests/ahriman/application/handlers/test_handler_add.py
Normal file
@ -0,0 +1,19 @@
|
||||
import argparse
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.application.handlers import Add
|
||||
from ahriman.core.configuration import Configuration
|
||||
|
||||
|
||||
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run command
|
||||
"""
|
||||
args.package = []
|
||||
args.without_dependencies = False
|
||||
mocker.patch("pathlib.Path.mkdir")
|
||||
application_mock = mocker.patch("ahriman.application.application.Application.add")
|
||||
|
||||
Add.run(args, "x86_64", configuration)
|
||||
application_mock.assert_called_once()
|
22
tests/ahriman/application/handlers/test_handler_clean.py
Normal file
22
tests/ahriman/application/handlers/test_handler_clean.py
Normal file
@ -0,0 +1,22 @@
|
||||
import argparse
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.application.handlers import Clean
|
||||
from ahriman.core.configuration import Configuration
|
||||
|
||||
|
||||
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run command
|
||||
"""
|
||||
args.no_build = False
|
||||
args.no_cache = False
|
||||
args.no_chroot = False
|
||||
args.no_manual = False
|
||||
args.no_packages = False
|
||||
mocker.patch("pathlib.Path.mkdir")
|
||||
application_mock = mocker.patch("ahriman.application.application.Application.clean")
|
||||
|
||||
Clean.run(args, "x86_64", configuration)
|
||||
application_mock.assert_called_once()
|
17
tests/ahriman/application/handlers/test_handler_dump.py
Normal file
17
tests/ahriman/application/handlers/test_handler_dump.py
Normal file
@ -0,0 +1,17 @@
|
||||
import argparse
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.application.handlers import Dump
|
||||
from ahriman.core.configuration import Configuration
|
||||
|
||||
|
||||
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run command
|
||||
"""
|
||||
mocker.patch("pathlib.Path.mkdir")
|
||||
application_mock = mocker.patch("ahriman.core.configuration.Configuration.dump")
|
||||
|
||||
Dump.run(args, "x86_64", configuration)
|
||||
application_mock.assert_called_once()
|
19
tests/ahriman/application/handlers/test_handler_rebuild.py
Normal file
19
tests/ahriman/application/handlers/test_handler_rebuild.py
Normal file
@ -0,0 +1,19 @@
|
||||
import argparse
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.application.handlers import Rebuild
|
||||
from ahriman.core.configuration import Configuration
|
||||
|
||||
|
||||
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run command
|
||||
"""
|
||||
mocker.patch("pathlib.Path.mkdir")
|
||||
application_packages_mock = mocker.patch("ahriman.core.repository.repository.Repository.packages")
|
||||
application_mock = mocker.patch("ahriman.application.application.Application.update")
|
||||
|
||||
Rebuild.run(args, "x86_64", configuration)
|
||||
application_packages_mock.assert_called_once()
|
||||
application_mock.assert_called_once()
|
18
tests/ahriman/application/handlers/test_handler_remove.py
Normal file
18
tests/ahriman/application/handlers/test_handler_remove.py
Normal file
@ -0,0 +1,18 @@
|
||||
import argparse
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.application.handlers import Remove
|
||||
from ahriman.core.configuration import Configuration
|
||||
|
||||
|
||||
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run command
|
||||
"""
|
||||
args.package = []
|
||||
mocker.patch("pathlib.Path.mkdir")
|
||||
application_mock = mocker.patch("ahriman.application.application.Application.remove")
|
||||
|
||||
Remove.run(args, "x86_64", configuration)
|
||||
application_mock.assert_called_once()
|
18
tests/ahriman/application/handlers/test_handler_report.py
Normal file
18
tests/ahriman/application/handlers/test_handler_report.py
Normal file
@ -0,0 +1,18 @@
|
||||
import argparse
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.application.handlers import Report
|
||||
from ahriman.core.configuration import Configuration
|
||||
|
||||
|
||||
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run command
|
||||
"""
|
||||
args.target = []
|
||||
mocker.patch("pathlib.Path.mkdir")
|
||||
application_mock = mocker.patch("ahriman.application.application.Application.report")
|
||||
|
||||
Report.run(args, "x86_64", configuration)
|
||||
application_mock.assert_called_once()
|
22
tests/ahriman/application/handlers/test_handler_status.py
Normal file
22
tests/ahriman/application/handlers/test_handler_status.py
Normal file
@ -0,0 +1,22 @@
|
||||
import argparse
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.application.handlers import Status
|
||||
from ahriman.core.configuration import Configuration
|
||||
|
||||
|
||||
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run command
|
||||
"""
|
||||
args.ahriman = True
|
||||
args.package = []
|
||||
args.without_dependencies = False
|
||||
mocker.patch("pathlib.Path.mkdir")
|
||||
application_mock = mocker.patch("ahriman.core.status.client.Client.get_self")
|
||||
packages_mock = mocker.patch("ahriman.core.status.client.Client.get")
|
||||
|
||||
Status.run(args, "x86_64", configuration)
|
||||
application_mock.assert_called_once()
|
||||
packages_mock.assert_called_once()
|
18
tests/ahriman/application/handlers/test_handler_sync.py
Normal file
18
tests/ahriman/application/handlers/test_handler_sync.py
Normal file
@ -0,0 +1,18 @@
|
||||
import argparse
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.application.handlers import Sync
|
||||
from ahriman.core.configuration import Configuration
|
||||
|
||||
|
||||
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run command
|
||||
"""
|
||||
args.target = []
|
||||
mocker.patch("pathlib.Path.mkdir")
|
||||
application_mock = mocker.patch("ahriman.application.application.Application.sync")
|
||||
|
||||
Sync.run(args, "x86_64", configuration)
|
||||
application_mock.assert_called_once()
|
40
tests/ahriman/application/handlers/test_handler_update.py
Normal file
40
tests/ahriman/application/handlers/test_handler_update.py
Normal file
@ -0,0 +1,40 @@
|
||||
import argparse
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.application.handlers import Update
|
||||
from ahriman.core.configuration import Configuration
|
||||
|
||||
|
||||
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run command
|
||||
"""
|
||||
args.package = []
|
||||
args.dry_run = False
|
||||
args.no_aur = False
|
||||
args.no_manual = False
|
||||
args.no_vcs = False
|
||||
mocker.patch("pathlib.Path.mkdir")
|
||||
application_mock = mocker.patch("ahriman.application.application.Application.update")
|
||||
updates_mock = mocker.patch("ahriman.application.application.Application.get_updates")
|
||||
|
||||
Update.run(args, "x86_64", configuration)
|
||||
application_mock.assert_called_once()
|
||||
updates_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_run_dry_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run simplified command
|
||||
"""
|
||||
args.package = []
|
||||
args.dry_run = True
|
||||
args.no_aur = False
|
||||
args.no_manual = False
|
||||
args.no_vcs = False
|
||||
mocker.patch("pathlib.Path.mkdir")
|
||||
updates_mock = mocker.patch("ahriman.application.application.Application.get_updates")
|
||||
|
||||
Update.run(args, "x86_64", configuration)
|
||||
updates_mock.assert_called_once()
|
19
tests/ahriman/application/handlers/test_handler_web.py
Normal file
19
tests/ahriman/application/handlers/test_handler_web.py
Normal file
@ -0,0 +1,19 @@
|
||||
import argparse
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.application.handlers import Web
|
||||
from ahriman.core.configuration import Configuration
|
||||
|
||||
|
||||
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run command
|
||||
"""
|
||||
mocker.patch("pathlib.Path.mkdir")
|
||||
setup_mock = mocker.patch("ahriman.web.web.setup_service")
|
||||
run_mock = mocker.patch("ahriman.web.web.run_server")
|
||||
|
||||
Web.run(args, "x86_64", configuration)
|
||||
setup_mock.assert_called_once()
|
||||
run_mock.assert_called_once()
|
Loading…
Reference in New Issue
Block a user