mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-24 15:27:17 +00:00
refactor: fix pylint warnings in tests
This commit is contained in:
parent
706808fc97
commit
70b7fcf47a
@ -100,7 +100,7 @@ def test_add_local_cache(application_packages: ApplicationPackages, package_ahri
|
|||||||
"""
|
"""
|
||||||
mocker.patch("ahriman.models.package.Package.from_build", return_value=package_ahriman)
|
mocker.patch("ahriman.models.package.Package.from_build", return_value=package_ahriman)
|
||||||
mocker.patch("pathlib.Path.is_dir", autospec=True,
|
mocker.patch("pathlib.Path.is_dir", autospec=True,
|
||||||
side_effect=lambda p: True if p.is_relative_to(application_packages.repository.paths.cache) else False)
|
side_effect=lambda p: p.is_relative_to(application_packages.repository.paths.cache))
|
||||||
init_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.init")
|
init_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.init")
|
||||||
copytree_mock = mocker.patch("shutil.copytree")
|
copytree_mock = mocker.patch("shutil.copytree")
|
||||||
build_queue_mock = mocker.patch("ahriman.core.database.SQLite.build_queue_insert")
|
build_queue_mock = mocker.patch("ahriman.core.database.SQLite.build_queue_insert")
|
||||||
|
@ -47,7 +47,7 @@ def test_iter(updates_iterator: UpdatesIterator) -> None:
|
|||||||
"""
|
"""
|
||||||
must return self as iterator
|
must return self as iterator
|
||||||
"""
|
"""
|
||||||
assert updates_iterator.__iter__() == updates_iterator
|
assert iter(updates_iterator) == updates_iterator
|
||||||
|
|
||||||
|
|
||||||
def test_next(updates_iterator: UpdatesIterator, package_ahriman: Package, mocker: MockerFixture) -> None:
|
def test_next(updates_iterator: UpdatesIterator, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||||
@ -58,7 +58,7 @@ def test_next(updates_iterator: UpdatesIterator, package_ahriman: Package, mocke
|
|||||||
side_effect=[([package_ahriman.base], 2), (None, 2), StopIteration])
|
side_effect=[([package_ahriman.base], 2), (None, 2), StopIteration])
|
||||||
sleep_mock = mocker.patch("time.sleep")
|
sleep_mock = mocker.patch("time.sleep")
|
||||||
|
|
||||||
updates = [packages for packages in updates_iterator]
|
updates = list(updates_iterator)
|
||||||
assert updates == [[package_ahriman.base], None]
|
assert updates == [[package_ahriman.base], None]
|
||||||
sleep_mock.assert_has_calls([MockCall(0.5), MockCall(0.5)])
|
sleep_mock.assert_has_calls([MockCall(0.5), MockCall(0.5)])
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ def test_configuration_create_ahriman(args: argparse.Namespace, configuration: C
|
|||||||
|
|
||||||
|
|
||||||
def test_configuration_create_ahriman_no_multilib(args: argparse.Namespace, configuration: Configuration,
|
def test_configuration_create_ahriman_no_multilib(args: argparse.Namespace, configuration: Configuration,
|
||||||
repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must create configuration for the service without multilib repository
|
must create configuration for the service without multilib repository
|
||||||
"""
|
"""
|
||||||
|
@ -558,14 +558,13 @@ def user() -> User:
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def watcher(repository_id: RepositoryId, database: SQLite, repository: Repository) -> Watcher:
|
def watcher(repository_id: RepositoryId, database: SQLite) -> Watcher:
|
||||||
"""
|
"""
|
||||||
package status watcher fixture
|
package status watcher fixture
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
repository_id(RepositoryId): repository identifier fixture
|
repository_id(RepositoryId): repository identifier fixture
|
||||||
database(SQLite): database fixture
|
database(SQLite): database fixture
|
||||||
repository(Repository): repository fixture
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Watcher: package status watcher test instance
|
Watcher: package status watcher test instance
|
||||||
|
@ -48,7 +48,7 @@ def test_multisearch_single(aur_package_ahriman: AURPackage, pacman: Pacman, moc
|
|||||||
search_mock.assert_called_once_with("ahriman", pacman=pacman)
|
search_mock.assert_called_once_with("ahriman", pacman=pacman)
|
||||||
|
|
||||||
|
|
||||||
def test_remote_git_url(remote: Remote, pacman: Pacman) -> None:
|
def test_remote_git_url(remote: Remote) -> None:
|
||||||
"""
|
"""
|
||||||
must raise NotImplemented for missing remote git url
|
must raise NotImplemented for missing remote git url
|
||||||
"""
|
"""
|
||||||
@ -56,7 +56,7 @@ def test_remote_git_url(remote: Remote, pacman: Pacman) -> None:
|
|||||||
remote.remote_git_url("package", "repositorys")
|
remote.remote_git_url("package", "repositorys")
|
||||||
|
|
||||||
|
|
||||||
def test_remote_web_url(remote: Remote, pacman: Pacman) -> None:
|
def test_remote_web_url(remote: Remote) -> None:
|
||||||
"""
|
"""
|
||||||
must raise NotImplemented for missing remote web url
|
must raise NotImplemented for missing remote web url
|
||||||
"""
|
"""
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import importlib
|
import importlib
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import ahriman.core.auth.helpers as helpers
|
|
||||||
|
|
||||||
from pytest_mock import MockerFixture
|
from pytest_mock import MockerFixture
|
||||||
|
|
||||||
|
from ahriman.core.auth import helpers
|
||||||
|
|
||||||
|
|
||||||
def test_import_aiohttp_security() -> None:
|
def test_import_aiohttp_security() -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -27,7 +27,7 @@ def test_changes(mocker: MockerFixture) -> None:
|
|||||||
diff_mock.assert_called_once_with(local, last_commit_sha)
|
diff_mock.assert_called_once_with(local, last_commit_sha)
|
||||||
|
|
||||||
|
|
||||||
def test_changes_skip(package_ahriman: Package, mocker: MockerFixture) -> None:
|
def test_changes_skip(mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must return none in case if commit sha is not available
|
must return none in case if commit sha is not available
|
||||||
"""
|
"""
|
||||||
|
@ -19,7 +19,7 @@ def test_migrate(connection: Connection, configuration: Configuration, mocker: M
|
|||||||
run_mock.assert_called_once_with()
|
run_mock.assert_called_once_with()
|
||||||
|
|
||||||
|
|
||||||
def test_migration(migrations: Migrations, connection: Connection) -> None:
|
def test_migration(migrations: Migrations) -> None:
|
||||||
"""
|
"""
|
||||||
must perform single migration
|
must perform single migration
|
||||||
"""
|
"""
|
||||||
|
@ -22,10 +22,7 @@ def test_package_update(database: SQLite, configuration: Configuration, package_
|
|||||||
patch2 = PkgbuildPatch("key", "value")
|
patch2 = PkgbuildPatch("key", "value")
|
||||||
local = Path("local")
|
local = Path("local")
|
||||||
|
|
||||||
mocker.patch(
|
mocker.patch("pathlib.Path.is_file", autospec=True, side_effect=lambda p: p == Path(".gitignore"))
|
||||||
"pathlib.Path.is_file",
|
|
||||||
autospec=True,
|
|
||||||
side_effect=lambda p: True if p == Path(".gitignore") else False)
|
|
||||||
glob_mock = mocker.patch("pathlib.Path.glob", return_value=[Path(".git"), Path(".gitignore")])
|
glob_mock = mocker.patch("pathlib.Path.glob", return_value=[Path(".git"), Path(".gitignore")])
|
||||||
rmtree_mock = mocker.patch("shutil.rmtree")
|
rmtree_mock = mocker.patch("shutil.rmtree")
|
||||||
unlink_mock = mocker.patch("pathlib.Path.unlink")
|
unlink_mock = mocker.patch("pathlib.Path.unlink")
|
||||||
|
@ -29,7 +29,7 @@ def test_load_archives(package_ahriman: Package, package_python_schedule: Packag
|
|||||||
assert len(packages) == 2
|
assert len(packages) == 2
|
||||||
assert {package.base for package in packages} == {package_ahriman.base, package_python_schedule.base}
|
assert {package.base for package in packages} == {package_ahriman.base, package_python_schedule.base}
|
||||||
|
|
||||||
archives = sum([list(package.packages.keys()) for package in packages], start=[])
|
archives = sum((list(package.packages.keys()) for package in packages), start=[])
|
||||||
assert len(archives) == 3
|
assert len(archives) == 3
|
||||||
expected = set(package_ahriman.packages.keys())
|
expected = set(package_ahriman.packages.keys())
|
||||||
expected.update(package_python_schedule.packages.keys())
|
expected.update(package_python_schedule.packages.keys())
|
||||||
|
@ -56,7 +56,7 @@ def test_configuration_schema_empty(configuration: Configuration) -> None:
|
|||||||
assert ReportTrigger.configuration_schema(repository_id, None) == ReportTrigger.CONFIGURATION_SCHEMA
|
assert ReportTrigger.configuration_schema(repository_id, None) == ReportTrigger.CONFIGURATION_SCHEMA
|
||||||
|
|
||||||
|
|
||||||
def test_configuration_schema_variables(configuration: Configuration) -> None:
|
def test_configuration_schema_variables() -> None:
|
||||||
"""
|
"""
|
||||||
must return empty schema
|
must return empty schema
|
||||||
"""
|
"""
|
||||||
|
@ -147,7 +147,7 @@ def test_on_result_exception(trigger_loader: TriggerLoader, package_ahriman: Pac
|
|||||||
log_mock.assert_called_once()
|
log_mock.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
def test_on_start(trigger_loader: TriggerLoader, package_ahriman: Package, mocker: MockerFixture) -> None:
|
def test_on_start(trigger_loader: TriggerLoader, mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must run triggers on start
|
must run triggers on start
|
||||||
"""
|
"""
|
||||||
@ -187,7 +187,7 @@ def test_on_stop_without_on_start(configuration: Configuration, mocker: MockerFi
|
|||||||
on_stop_mock.assert_not_called()
|
on_stop_mock.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
def test_on_stop(trigger_loader: TriggerLoader, package_ahriman: Package, mocker: MockerFixture) -> None:
|
def test_on_stop(trigger_loader: TriggerLoader, mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must run triggers on stop
|
must run triggers on stop
|
||||||
"""
|
"""
|
||||||
|
@ -78,7 +78,7 @@ def test_from_repo(aur_package_akonadi: AURPackage, resource_path_root: Path) ->
|
|||||||
assert AURPackage.from_repo(model) == aur_package_akonadi
|
assert AURPackage.from_repo(model) == aur_package_akonadi
|
||||||
|
|
||||||
|
|
||||||
def test_convert(aur_package_ahriman: AURPackage, resource_path_root: Path) -> None:
|
def test_convert(resource_path_root: Path) -> None:
|
||||||
"""
|
"""
|
||||||
must convert fields to snakecase and also apply converters
|
must convert fields to snakecase and also apply converters
|
||||||
"""
|
"""
|
||||||
|
@ -249,7 +249,7 @@ def test_from_build_architecture(mocker: MockerFixture, resource_path_root: Path
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_from_build_failed(package_ahriman: Package, mocker: MockerFixture) -> None:
|
def test_from_build_failed(mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must raise exception if there are errors during srcinfo load
|
must raise exception if there are errors during srcinfo load
|
||||||
"""
|
"""
|
||||||
@ -317,7 +317,7 @@ def test_local_files_empty(mocker: MockerFixture, resource_path_root: Path) -> N
|
|||||||
mocker.patch("ahriman.models.package.check_output", return_value=srcinfo)
|
mocker.patch("ahriman.models.package.check_output", return_value=srcinfo)
|
||||||
mocker.patch("ahriman.models.package.Package.supported_architectures", return_value=["any"])
|
mocker.patch("ahriman.models.package.Package.supported_architectures", return_value=["any"])
|
||||||
|
|
||||||
assert list(Package.local_files(Path("path"))) == []
|
assert not list(Package.local_files(Path("path")))
|
||||||
|
|
||||||
|
|
||||||
def test_local_files_error(mocker: MockerFixture) -> None:
|
def test_local_files_error(mocker: MockerFixture) -> None:
|
||||||
@ -342,7 +342,7 @@ def test_local_files_schema(mocker: MockerFixture, resource_path_root: Path) ->
|
|||||||
mocker.patch("ahriman.models.package.check_output", return_value="")
|
mocker.patch("ahriman.models.package.check_output", return_value="")
|
||||||
mocker.patch("ahriman.models.package.Package.supported_architectures", return_value=["any"])
|
mocker.patch("ahriman.models.package.Package.supported_architectures", return_value=["any"])
|
||||||
|
|
||||||
assert list(Package.local_files(Path("path"))) == []
|
assert not list(Package.local_files(Path("path")))
|
||||||
|
|
||||||
|
|
||||||
def test_local_files_with_install(mocker: MockerFixture, resource_path_root: Path) -> None:
|
def test_local_files_with_install(mocker: MockerFixture, resource_path_root: Path) -> None:
|
||||||
|
@ -73,7 +73,7 @@ def request(application: Application, path: str, method: str, params: Any = None
|
|||||||
request_mock.match_info = UrlMappingMatchInfo({}, route_mock)
|
request_mock.match_info = UrlMappingMatchInfo({}, route_mock)
|
||||||
|
|
||||||
extra = extra or {}
|
extra = extra or {}
|
||||||
request_mock.get_extra_info.side_effect = lambda key: extra.get(key)
|
request_mock.get_extra_info.side_effect = extra.get
|
||||||
|
|
||||||
return request_mock
|
return request_mock
|
||||||
|
|
||||||
@ -167,14 +167,13 @@ def application_with_auth(configuration: Configuration, user: User, spawner: Spa
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def application_with_debug(configuration: Configuration, user: User, spawner: Spawn, database: SQLite,
|
def application_with_debug(configuration: Configuration, spawner: Spawn, database: SQLite,
|
||||||
mocker: MockerFixture) -> Application:
|
mocker: MockerFixture) -> Application:
|
||||||
"""
|
"""
|
||||||
application fixture with debug enabled
|
application fixture with debug enabled
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
configuration(Configuration): configuration fixture
|
configuration(Configuration): configuration fixture
|
||||||
user(User): user descriptor fixture
|
|
||||||
spawner(Spawn): spawner fixture
|
spawner(Spawn): spawner fixture
|
||||||
database(SQLite): database fixture
|
database(SQLite): database fixture
|
||||||
mocker(MockerFixture): mocker object
|
mocker(MockerFixture): mocker object
|
||||||
|
@ -3,19 +3,17 @@ import pytest
|
|||||||
from ahriman.core.auth import Auth
|
from ahriman.core.auth import Auth
|
||||||
from ahriman.core.configuration import Configuration
|
from ahriman.core.configuration import Configuration
|
||||||
from ahriman.core.database import SQLite
|
from ahriman.core.database import SQLite
|
||||||
from ahriman.models.user import User
|
|
||||||
from ahriman.web.middlewares.auth_handler import _AuthorizationPolicy
|
from ahriman.web.middlewares.auth_handler import _AuthorizationPolicy
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def authorization_policy(configuration: Configuration, database: SQLite, user: User) -> _AuthorizationPolicy:
|
def authorization_policy(configuration: Configuration, database: SQLite) -> _AuthorizationPolicy:
|
||||||
"""
|
"""
|
||||||
fixture for authorization policy
|
fixture for authorization policy
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
configuration(Configuration): configuration fixture
|
configuration(Configuration): configuration fixture
|
||||||
database(SQLite): database fixture
|
database(SQLite): database fixture
|
||||||
user(User): user fixture
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
AuthorizationPolicy: authorization policy fixture
|
AuthorizationPolicy: authorization policy fixture
|
||||||
|
@ -24,7 +24,7 @@ async def test_authorized_userid(authorization_policy: _AuthorizationPolicy, use
|
|||||||
assert await authorization_policy.authorized_userid(user.username) == user.username
|
assert await authorization_policy.authorized_userid(user.username) == user.username
|
||||||
|
|
||||||
|
|
||||||
async def test_authorized_userid_unknown(authorization_policy: _AuthorizationPolicy, user: User) -> None:
|
async def test_authorized_userid_unknown(authorization_policy: _AuthorizationPolicy) -> None:
|
||||||
"""
|
"""
|
||||||
must not allow unknown user id for authorization
|
must not allow unknown user id for authorization
|
||||||
"""
|
"""
|
||||||
@ -51,7 +51,7 @@ async def test_permits(authorization_policy: _AuthorizationPolicy, user: User) -
|
|||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
async def test_auth_handler_unix_socket(client_with_auth: TestClient, mocker: MockerFixture) -> None:
|
async def test_auth_handler_unix_socket(mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must allow calls via unix sockets
|
must allow calls via unix sockets
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user