mirror of
https://github.com/arcan1s/ahriman.git
synced 2026-07-14 14:51:08 +00:00
straight forward conftest
This commit is contained in:
@@ -3,4 +3,5 @@ addopts = --cov=ahriman --cov-report=term-missing:skip-covered --no-cov-on-fail
|
|||||||
asyncio_default_fixture_loop_scope = function
|
asyncio_default_fixture_loop_scope = function
|
||||||
asyncio_mode = auto
|
asyncio_mode = auto
|
||||||
pythonpath = tests
|
pythonpath = tests
|
||||||
|
resource-path.directory-name-test-resources = ../../tests/testresources
|
||||||
spec_test_format = {result} {docstring_summary}
|
spec_test_format = {result} {docstring_summary}
|
||||||
|
|||||||
@@ -1,10 +1,162 @@
|
|||||||
from pathlib import Path
|
import datetime
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from fixtures import * # pylint: disable=wildcard-import,unused-wildcard-import
|
from unittest.mock import MagicMock, PropertyMock
|
||||||
|
|
||||||
|
from ahriman.core.alpm.pacman import Pacman
|
||||||
|
from ahriman.core.alpm.remote import AUR
|
||||||
|
from ahriman.core.configuration import Configuration
|
||||||
|
from ahriman.models.aur_package import AURPackage
|
||||||
|
from ahriman.models.package import Package
|
||||||
|
from ahriman.models.package_description import PackageDescription
|
||||||
|
from ahriman.models.package_source import PackageSource
|
||||||
|
from ahriman.models.pacman_synchronization import PacmanSynchronization
|
||||||
|
from ahriman.models.remote_source import RemoteSource
|
||||||
|
from ahriman.models.scan_paths import ScanPaths
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def resource_path_root() -> Path:
|
def aur_package_akonadi() -> AURPackage:
|
||||||
return Path(__file__).resolve().parents[2] / "tests" / "testresources"
|
"""
|
||||||
|
fixture for AUR package
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
AURPackage: AUR package test instance
|
||||||
|
"""
|
||||||
|
return AURPackage(
|
||||||
|
id=0,
|
||||||
|
name="akonadi",
|
||||||
|
package_base_id=0,
|
||||||
|
package_base="akonadi",
|
||||||
|
version="21.12.3-2",
|
||||||
|
description="PIM layer, which provides an asynchronous API to access all kind of PIM data",
|
||||||
|
num_votes=0,
|
||||||
|
popularity=0.0,
|
||||||
|
first_submitted=datetime.datetime.fromtimestamp(0, datetime.UTC),
|
||||||
|
last_modified=datetime.datetime.fromtimestamp(1646555990.610, datetime.UTC),
|
||||||
|
url_path="",
|
||||||
|
url="https://kontact.kde.org",
|
||||||
|
out_of_date=None,
|
||||||
|
maintainer="felixonmars",
|
||||||
|
repository="extra",
|
||||||
|
depends=[
|
||||||
|
"libakonadi",
|
||||||
|
"mariadb",
|
||||||
|
],
|
||||||
|
make_depends=[
|
||||||
|
"boost",
|
||||||
|
"doxygen",
|
||||||
|
"extra-cmake-modules",
|
||||||
|
"kaccounts-integration",
|
||||||
|
"kitemmodels",
|
||||||
|
"postgresql",
|
||||||
|
"qt5-tools",
|
||||||
|
],
|
||||||
|
opt_depends=[
|
||||||
|
"postgresql: PostgreSQL backend",
|
||||||
|
],
|
||||||
|
conflicts=[],
|
||||||
|
provides=[],
|
||||||
|
license=["LGPL"],
|
||||||
|
keywords=[],
|
||||||
|
groups=[],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def package_tpacpi_bat_git() -> Package:
|
||||||
|
"""
|
||||||
|
git package fixture
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Package: git package test instance
|
||||||
|
"""
|
||||||
|
return Package(
|
||||||
|
base="tpacpi-bat-git",
|
||||||
|
version="3.1.r12.g4959b52-1",
|
||||||
|
remote=RemoteSource(
|
||||||
|
source=PackageSource.AUR,
|
||||||
|
git_url=AUR.remote_git_url("tpacpi-bat-git", "aur"),
|
||||||
|
web_url=AUR.remote_web_url("tpacpi-bat-git"),
|
||||||
|
path=".",
|
||||||
|
branch="master",
|
||||||
|
),
|
||||||
|
packages={"tpacpi-bat-git": PackageDescription()})
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def pacman(configuration: Configuration) -> Pacman:
|
||||||
|
"""
|
||||||
|
fixture for pacman wrapper
|
||||||
|
|
||||||
|
Args:
|
||||||
|
configuration(Configuration): configuration fixture
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Pacman: pacman wrapper test instance
|
||||||
|
"""
|
||||||
|
_, repository_id = configuration.check_loaded()
|
||||||
|
return Pacman(repository_id, configuration, refresh_database=PacmanSynchronization.Disabled)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def passwd() -> MagicMock:
|
||||||
|
"""
|
||||||
|
get passwd structure for the user
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
MagicMock: passwd structure test instance
|
||||||
|
"""
|
||||||
|
passwd = MagicMock()
|
||||||
|
passwd.pw_dir = "home"
|
||||||
|
passwd.pw_name = "ahriman"
|
||||||
|
return passwd
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def pyalpm_package_ahriman(aur_package_ahriman: AURPackage) -> MagicMock:
|
||||||
|
"""
|
||||||
|
mock object for pyalpm package
|
||||||
|
|
||||||
|
Args:
|
||||||
|
aur_package_ahriman(AURPackage): package fixture
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
MagicMock: pyalpm package mock
|
||||||
|
"""
|
||||||
|
mock = MagicMock()
|
||||||
|
db = type(mock).db = MagicMock()
|
||||||
|
|
||||||
|
type(mock).base = PropertyMock(return_value=aur_package_ahriman.package_base)
|
||||||
|
type(mock).builddate = PropertyMock(
|
||||||
|
return_value=aur_package_ahriman.last_modified.replace(tzinfo=datetime.timezone.utc).timestamp())
|
||||||
|
type(mock).conflicts = PropertyMock(return_value=aur_package_ahriman.conflicts)
|
||||||
|
type(db).name = PropertyMock(return_value="aur")
|
||||||
|
type(mock).depends = PropertyMock(return_value=aur_package_ahriman.depends)
|
||||||
|
type(mock).desc = PropertyMock(return_value=aur_package_ahriman.description)
|
||||||
|
type(mock).licenses = PropertyMock(return_value=aur_package_ahriman.license)
|
||||||
|
type(mock).makedepends = PropertyMock(return_value=aur_package_ahriman.make_depends)
|
||||||
|
type(mock).name = PropertyMock(return_value=aur_package_ahriman.name)
|
||||||
|
type(mock).optdepends = PropertyMock(return_value=aur_package_ahriman.opt_depends)
|
||||||
|
type(mock).checkdepends = PropertyMock(return_value=aur_package_ahriman.check_depends)
|
||||||
|
type(mock).packager = PropertyMock(return_value="packager")
|
||||||
|
type(mock).provides = PropertyMock(return_value=aur_package_ahriman.provides)
|
||||||
|
type(mock).version = PropertyMock(return_value=aur_package_ahriman.version)
|
||||||
|
type(mock).url = PropertyMock(return_value=aur_package_ahriman.url)
|
||||||
|
type(mock).groups = PropertyMock(return_value=aur_package_ahriman.groups)
|
||||||
|
|
||||||
|
return mock
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def scan_paths(configuration: Configuration) -> ScanPaths:
|
||||||
|
"""
|
||||||
|
scan paths fixture
|
||||||
|
|
||||||
|
Args:
|
||||||
|
configuration(Configuration): configuration test instance
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
ScanPaths: scan paths test instance
|
||||||
|
"""
|
||||||
|
return ScanPaths(configuration.getlist("build", "scan_paths", fallback=[]))
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from fixtures import * # pylint: disable=wildcard-import,unused-wildcard-import
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def resource_path_root() -> Path:
|
|
||||||
return Path(__file__).resolve().parents[2] / "tests" / "testresources"
|
|
||||||
|
|||||||
@@ -1,10 +1,18 @@
|
|||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from fixtures import * # pylint: disable=wildcard-import,unused-wildcard-import
|
from ahriman.core.auth import Auth
|
||||||
|
from ahriman.core.configuration import Configuration
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def resource_path_root() -> Path:
|
def auth(configuration: Configuration) -> Auth:
|
||||||
return Path(__file__).resolve().parents[2] / "tests" / "testresources"
|
"""
|
||||||
|
auth provider fixture
|
||||||
|
|
||||||
|
Args:
|
||||||
|
configuration(Configuration): configuration fixture
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Auth: auth service instance
|
||||||
|
"""
|
||||||
|
return Auth(configuration)
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"""Shared pytest fixtures."""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import datetime
|
import datetime
|
||||||
import pytest
|
import pytest
|
||||||
@@ -7,12 +9,10 @@ from pathlib import Path
|
|||||||
from pytest_mock import MockerFixture
|
from pytest_mock import MockerFixture
|
||||||
from sqlite3 import Cursor
|
from sqlite3 import Cursor
|
||||||
from typing import Any, TypeVar
|
from typing import Any, TypeVar
|
||||||
from unittest.mock import MagicMock, PropertyMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
from ahriman.application.ahriman import _parser
|
from ahriman.application.ahriman import _parser
|
||||||
from ahriman.core.alpm.pacman import Pacman
|
|
||||||
from ahriman.core.alpm.remote import AUR
|
from ahriman.core.alpm.remote import AUR
|
||||||
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.core.database.migrations import Migrations
|
from ahriman.core.database.migrations import Migrations
|
||||||
@@ -30,12 +30,10 @@ from ahriman.models.migration import Migration
|
|||||||
from ahriman.models.package import Package
|
from ahriman.models.package import Package
|
||||||
from ahriman.models.package_description import PackageDescription
|
from ahriman.models.package_description import PackageDescription
|
||||||
from ahriman.models.package_source import PackageSource
|
from ahriman.models.package_source import PackageSource
|
||||||
from ahriman.models.pacman_synchronization import PacmanSynchronization
|
|
||||||
from ahriman.models.remote_source import RemoteSource
|
from ahriman.models.remote_source import RemoteSource
|
||||||
from ahriman.models.repository_id import RepositoryId
|
from ahriman.models.repository_id import RepositoryId
|
||||||
from ahriman.models.repository_paths import RepositoryPaths
|
from ahriman.models.repository_paths import RepositoryPaths
|
||||||
from ahriman.models.result import Result
|
from ahriman.models.result import Result
|
||||||
from ahriman.models.scan_paths import ScanPaths
|
|
||||||
from ahriman.models.user import User
|
from ahriman.models.user import User
|
||||||
from ahriman.models.user_access import UserAccess
|
from ahriman.models.user_access import UserAccess
|
||||||
|
|
||||||
@@ -243,68 +241,6 @@ def aur_package_ahriman() -> AURPackage:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def aur_package_akonadi() -> AURPackage:
|
|
||||||
"""
|
|
||||||
fixture for AUR package
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
AURPackage: AUR package test instance
|
|
||||||
"""
|
|
||||||
return AURPackage(
|
|
||||||
id=0,
|
|
||||||
name="akonadi",
|
|
||||||
package_base_id=0,
|
|
||||||
package_base="akonadi",
|
|
||||||
version="21.12.3-2",
|
|
||||||
description="PIM layer, which provides an asynchronous API to access all kind of PIM data",
|
|
||||||
num_votes=0,
|
|
||||||
popularity=0.0,
|
|
||||||
first_submitted=datetime.datetime.fromtimestamp(0, datetime.UTC),
|
|
||||||
last_modified=datetime.datetime.fromtimestamp(1646555990.610, datetime.UTC),
|
|
||||||
url_path="",
|
|
||||||
url="https://kontact.kde.org",
|
|
||||||
out_of_date=None,
|
|
||||||
maintainer="felixonmars",
|
|
||||||
repository="extra",
|
|
||||||
depends=[
|
|
||||||
"libakonadi",
|
|
||||||
"mariadb",
|
|
||||||
],
|
|
||||||
make_depends=[
|
|
||||||
"boost",
|
|
||||||
"doxygen",
|
|
||||||
"extra-cmake-modules",
|
|
||||||
"kaccounts-integration",
|
|
||||||
"kitemmodels",
|
|
||||||
"postgresql",
|
|
||||||
"qt5-tools",
|
|
||||||
],
|
|
||||||
opt_depends=[
|
|
||||||
"postgresql: PostgreSQL backend",
|
|
||||||
],
|
|
||||||
conflicts=[],
|
|
||||||
provides=[],
|
|
||||||
license=["LGPL"],
|
|
||||||
keywords=[],
|
|
||||||
groups=[],
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def auth(configuration: Configuration) -> Auth:
|
|
||||||
"""
|
|
||||||
auth provider fixture
|
|
||||||
|
|
||||||
Args:
|
|
||||||
configuration(Configuration): configuration fixture
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Auth: auth service instance
|
|
||||||
"""
|
|
||||||
return Auth(configuration)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def configuration(repository_id: RepositoryId, tmp_path: Path, resource_path_root: Path) -> Configuration:
|
def configuration(repository_id: RepositoryId, tmp_path: Path, resource_path_root: Path) -> Configuration:
|
||||||
"""
|
"""
|
||||||
@@ -453,27 +389,6 @@ def package_python_schedule(
|
|||||||
packages=packages)
|
packages=packages)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def package_tpacpi_bat_git() -> Package:
|
|
||||||
"""
|
|
||||||
git package fixture
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Package: git package test instance
|
|
||||||
"""
|
|
||||||
return Package(
|
|
||||||
base="tpacpi-bat-git",
|
|
||||||
version="3.1.r12.g4959b52-1",
|
|
||||||
remote=RemoteSource(
|
|
||||||
source=PackageSource.AUR,
|
|
||||||
git_url=AUR.remote_git_url("tpacpi-bat-git", "aur"),
|
|
||||||
web_url=AUR.remote_web_url("tpacpi-bat-git"),
|
|
||||||
path=".",
|
|
||||||
branch="master",
|
|
||||||
),
|
|
||||||
packages={"tpacpi-bat-git": PackageDescription()})
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def package_description_ahriman() -> PackageDescription:
|
def package_description_ahriman() -> PackageDescription:
|
||||||
"""
|
"""
|
||||||
@@ -575,70 +490,6 @@ def package_description_python2_schedule() -> PackageDescription:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def pacman(configuration: Configuration) -> Pacman:
|
|
||||||
"""
|
|
||||||
fixture for pacman wrapper
|
|
||||||
|
|
||||||
Args:
|
|
||||||
configuration(Configuration): configuration fixture
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Pacman: pacman wrapper test instance
|
|
||||||
"""
|
|
||||||
_, repository_id = configuration.check_loaded()
|
|
||||||
return Pacman(repository_id, configuration, refresh_database=PacmanSynchronization.Disabled)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def passwd() -> MagicMock:
|
|
||||||
"""
|
|
||||||
get passwd structure for the user
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
MagicMock: passwd structure test instance
|
|
||||||
"""
|
|
||||||
passwd = MagicMock()
|
|
||||||
passwd.pw_dir = "home"
|
|
||||||
passwd.pw_name = "ahriman"
|
|
||||||
return passwd
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def pyalpm_package_ahriman(aur_package_ahriman: AURPackage) -> MagicMock:
|
|
||||||
"""
|
|
||||||
mock object for pyalpm package
|
|
||||||
|
|
||||||
Args:
|
|
||||||
aur_package_ahriman(AURPackage): package fixture
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
MagicMock: pyalpm package mock
|
|
||||||
"""
|
|
||||||
mock = MagicMock()
|
|
||||||
db = type(mock).db = MagicMock()
|
|
||||||
|
|
||||||
type(mock).base = PropertyMock(return_value=aur_package_ahriman.package_base)
|
|
||||||
type(mock).builddate = PropertyMock(
|
|
||||||
return_value=aur_package_ahriman.last_modified.replace(tzinfo=datetime.timezone.utc).timestamp())
|
|
||||||
type(mock).conflicts = PropertyMock(return_value=aur_package_ahriman.conflicts)
|
|
||||||
type(db).name = PropertyMock(return_value="aur")
|
|
||||||
type(mock).depends = PropertyMock(return_value=aur_package_ahriman.depends)
|
|
||||||
type(mock).desc = PropertyMock(return_value=aur_package_ahriman.description)
|
|
||||||
type(mock).licenses = PropertyMock(return_value=aur_package_ahriman.license)
|
|
||||||
type(mock).makedepends = PropertyMock(return_value=aur_package_ahriman.make_depends)
|
|
||||||
type(mock).name = PropertyMock(return_value=aur_package_ahriman.name)
|
|
||||||
type(mock).optdepends = PropertyMock(return_value=aur_package_ahriman.opt_depends)
|
|
||||||
type(mock).checkdepends = PropertyMock(return_value=aur_package_ahriman.check_depends)
|
|
||||||
type(mock).packager = PropertyMock(return_value="packager")
|
|
||||||
type(mock).provides = PropertyMock(return_value=aur_package_ahriman.provides)
|
|
||||||
type(mock).version = PropertyMock(return_value=aur_package_ahriman.version)
|
|
||||||
type(mock).url = PropertyMock(return_value=aur_package_ahriman.url)
|
|
||||||
type(mock).groups = PropertyMock(return_value=aur_package_ahriman.groups)
|
|
||||||
|
|
||||||
return mock
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def remote_source() -> RemoteSource:
|
def remote_source() -> RemoteSource:
|
||||||
"""
|
"""
|
||||||
@@ -715,20 +566,6 @@ def result(package_ahriman: Package) -> Result:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def scan_paths(configuration: Configuration) -> ScanPaths:
|
|
||||||
"""
|
|
||||||
scan paths fixture
|
|
||||||
|
|
||||||
Args:
|
|
||||||
configuration(Configuration): configuration test instance
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
ScanPaths: scan paths test instance
|
|
||||||
"""
|
|
||||||
return ScanPaths(configuration.getlist("build", "scan_paths", fallback=[]))
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def spawner(configuration: Configuration) -> Spawn:
|
def spawner(configuration: Configuration) -> Spawn:
|
||||||
"""
|
"""
|
||||||
Reference in New Issue
Block a user