mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-05-05 12:43:49 +00:00
Compare commits
2 Commits
ab6f12b4af
...
5e720722df
Author | SHA1 | Date | |
---|---|---|---|
5e720722df | |||
077e9088c4 |
@ -218,6 +218,21 @@ class PackageOperations(Operations):
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def package_base_update(self, package: Package, repository_id: RepositoryId | None = None) -> None:
|
||||||
|
"""
|
||||||
|
update package base only
|
||||||
|
|
||||||
|
Args:
|
||||||
|
package(Package): package properties
|
||||||
|
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None)
|
||||||
|
"""
|
||||||
|
repository_id = repository_id or self._repository_id
|
||||||
|
|
||||||
|
def run(connection: Connection) -> None:
|
||||||
|
self._package_update_insert_base(connection, package, repository_id)
|
||||||
|
|
||||||
|
return self.with_connection(run, commit=True)
|
||||||
|
|
||||||
def package_remove(self, package_base: str, repository_id: RepositoryId | None = None) -> None:
|
def package_remove(self, package_base: str, repository_id: RepositoryId | None = None) -> None:
|
||||||
"""
|
"""
|
||||||
remove package from database
|
remove package from database
|
||||||
@ -272,6 +287,26 @@ class PackageOperations(Operations):
|
|||||||
|
|
||||||
return self.with_connection(lambda connection: list(run(connection)))
|
return self.with_connection(lambda connection: list(run(connection)))
|
||||||
|
|
||||||
|
def remotes_get(self, repository_id: RepositoryId | None = None) -> dict[str, RemoteSource]:
|
||||||
|
"""
|
||||||
|
get packages remotes based on current settings
|
||||||
|
|
||||||
|
Args:
|
||||||
|
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict[str, RemoteSource]: map of package base to its remote sources
|
||||||
|
"""
|
||||||
|
repository_id = repository_id or self._repository_id
|
||||||
|
|
||||||
|
def run(connection: Connection) -> dict[str, Package]:
|
||||||
|
return self._packages_get_select_package_bases(connection, repository_id)
|
||||||
|
|
||||||
|
return {
|
||||||
|
package_base: package.remote
|
||||||
|
for package_base, package in self.with_connection(run).items()
|
||||||
|
}
|
||||||
|
|
||||||
def status_update(self, package_base: str, status: BuildStatus, repository_id: RepositoryId | None = None) -> None:
|
def status_update(self, package_base: str, status: BuildStatus, repository_id: RepositoryId | None = None) -> None:
|
||||||
"""
|
"""
|
||||||
insert base package status into table
|
insert base package status into table
|
||||||
|
@ -22,7 +22,6 @@ import logging
|
|||||||
from typing import Self
|
from typing import Self
|
||||||
|
|
||||||
from ahriman.core.configuration import Configuration
|
from ahriman.core.configuration import Configuration
|
||||||
from ahriman.core.status import Client
|
|
||||||
from ahriman.models.repository_id import RepositoryId
|
from ahriman.models.repository_id import RepositoryId
|
||||||
|
|
||||||
|
|
||||||
@ -50,6 +49,8 @@ class HttpLogHandler(logging.Handler):
|
|||||||
# we don't really care about those parameters because they will be handled by the reporter
|
# we don't really care about those parameters because they will be handled by the reporter
|
||||||
logging.Handler.__init__(self)
|
logging.Handler.__init__(self)
|
||||||
|
|
||||||
|
# client has to be imported here because of circular imports
|
||||||
|
from ahriman.core.status import Client
|
||||||
self.reporter = Client.load(repository_id, configuration, report=report)
|
self.reporter = Client.load(repository_id, configuration, report=report)
|
||||||
self.suppress_errors = suppress_errors
|
self.suppress_errors = suppress_errors
|
||||||
|
|
||||||
|
@ -43,15 +43,14 @@ class PackageInfo(RepositoryProperties):
|
|||||||
Returns:
|
Returns:
|
||||||
list[Package]: list of read packages
|
list[Package]: list of read packages
|
||||||
"""
|
"""
|
||||||
sources = {package.base: package.remote for package, _, in self.reporter.package_get(None)}
|
|
||||||
|
|
||||||
result: dict[str, Package] = {}
|
result: dict[str, Package] = {}
|
||||||
# we are iterating over bases, not single packages
|
# we are iterating over bases, not single packages
|
||||||
for full_path in packages:
|
for full_path in packages:
|
||||||
try:
|
try:
|
||||||
local = Package.from_archive(full_path, self.pacman)
|
local = Package.from_archive(full_path, self.pacman)
|
||||||
if (source := sources.get(local.base)) is not None: # update source with remote
|
remote, _ = next(iter(self.reporter.package_get(local.base)), (None, None))
|
||||||
local.remote = source
|
if remote is not None: # update source with remote
|
||||||
|
local.remote = remote.remote
|
||||||
|
|
||||||
current = result.setdefault(local.base, local)
|
current = result.setdefault(local.base, local)
|
||||||
if current.version != local.version:
|
if current.version != local.version:
|
||||||
|
@ -79,6 +79,19 @@ class Client:
|
|||||||
|
|
||||||
return make_local_client()
|
return make_local_client()
|
||||||
|
|
||||||
|
def package_add(self, package: Package, status: BuildStatusEnum) -> None:
|
||||||
|
"""
|
||||||
|
add new package with status
|
||||||
|
|
||||||
|
Args:
|
||||||
|
package(Package): package properties
|
||||||
|
status(BuildStatusEnum): current package build status
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
NotImplementedError: not implemented method
|
||||||
|
"""
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
def package_changes_get(self, package_base: str) -> Changes:
|
def package_changes_get(self, package_base: str) -> Changes:
|
||||||
"""
|
"""
|
||||||
get package changes
|
get package changes
|
||||||
@ -245,9 +258,9 @@ class Client:
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def package_status_update(self, package_base: str, status: BuildStatusEnum) -> None:
|
def package_update(self, package_base: str, status: BuildStatusEnum) -> None:
|
||||||
"""
|
"""
|
||||||
update package build status. Unlike :func:`package_update()` it does not update package properties
|
update package build status. Unlike :func:`package_add()` it does not update package properties
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
package_base(str): package base to update
|
package_base(str): package base to update
|
||||||
@ -258,19 +271,6 @@ class Client:
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def package_update(self, package: Package, status: BuildStatusEnum) -> None:
|
|
||||||
"""
|
|
||||||
add new package or update existing one with status
|
|
||||||
|
|
||||||
Args:
|
|
||||||
package(Package): package properties
|
|
||||||
status(BuildStatusEnum): current package build status
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
NotImplementedError: not implemented method
|
|
||||||
"""
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
def set_building(self, package_base: str) -> None:
|
def set_building(self, package_base: str) -> None:
|
||||||
"""
|
"""
|
||||||
set package status to building
|
set package status to building
|
||||||
@ -278,7 +278,7 @@ class Client:
|
|||||||
Args:
|
Args:
|
||||||
package_base(str): package base to update
|
package_base(str): package base to update
|
||||||
"""
|
"""
|
||||||
self.package_status_update(package_base, BuildStatusEnum.Building)
|
return self.package_update(package_base, BuildStatusEnum.Building)
|
||||||
|
|
||||||
def set_failed(self, package_base: str) -> None:
|
def set_failed(self, package_base: str) -> None:
|
||||||
"""
|
"""
|
||||||
@ -287,7 +287,7 @@ class Client:
|
|||||||
Args:
|
Args:
|
||||||
package_base(str): package base to update
|
package_base(str): package base to update
|
||||||
"""
|
"""
|
||||||
self.package_status_update(package_base, BuildStatusEnum.Failed)
|
return self.package_update(package_base, BuildStatusEnum.Failed)
|
||||||
|
|
||||||
def set_pending(self, package_base: str) -> None:
|
def set_pending(self, package_base: str) -> None:
|
||||||
"""
|
"""
|
||||||
@ -296,7 +296,7 @@ class Client:
|
|||||||
Args:
|
Args:
|
||||||
package_base(str): package base to update
|
package_base(str): package base to update
|
||||||
"""
|
"""
|
||||||
self.package_status_update(package_base, BuildStatusEnum.Pending)
|
return self.package_update(package_base, BuildStatusEnum.Pending)
|
||||||
|
|
||||||
def set_success(self, package: Package) -> None:
|
def set_success(self, package: Package) -> None:
|
||||||
"""
|
"""
|
||||||
@ -305,19 +305,16 @@ class Client:
|
|||||||
Args:
|
Args:
|
||||||
package(Package): current package properties
|
package(Package): current package properties
|
||||||
"""
|
"""
|
||||||
self.package_update(package, BuildStatusEnum.Success)
|
return self.package_add(package, BuildStatusEnum.Success)
|
||||||
|
|
||||||
def set_unknown(self, package: Package) -> None:
|
def set_unknown(self, package: Package) -> None:
|
||||||
"""
|
"""
|
||||||
set package status to unknown. Unlike other methods, this method also checks if package is known,
|
set package status to unknown
|
||||||
and - in case if it is - it silently skips updatd
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
package(Package): current package properties
|
package(Package): current package properties
|
||||||
"""
|
"""
|
||||||
if self.package_get(package.base):
|
return self.package_add(package, BuildStatusEnum.Unknown)
|
||||||
return # skip update in case if package is already known
|
|
||||||
self.package_update(package, BuildStatusEnum.Unknown)
|
|
||||||
|
|
||||||
def status_get(self) -> InternalStatus:
|
def status_get(self) -> InternalStatus:
|
||||||
"""
|
"""
|
||||||
|
@ -48,6 +48,17 @@ class LocalClient(Client):
|
|||||||
self.database = database
|
self.database = database
|
||||||
self.repository_id = repository_id
|
self.repository_id = repository_id
|
||||||
|
|
||||||
|
def package_add(self, package: Package, status: BuildStatusEnum) -> None:
|
||||||
|
"""
|
||||||
|
add new package with status
|
||||||
|
|
||||||
|
Args:
|
||||||
|
package(Package): package properties
|
||||||
|
status(BuildStatusEnum): current package build status
|
||||||
|
"""
|
||||||
|
self.database.package_update(package, self.repository_id)
|
||||||
|
self.database.status_update(package.base, BuildStatus(status), self.repository_id)
|
||||||
|
|
||||||
def package_changes_get(self, package_base: str) -> Changes:
|
def package_changes_get(self, package_base: str) -> Changes:
|
||||||
"""
|
"""
|
||||||
get package changes
|
get package changes
|
||||||
@ -186,29 +197,12 @@ class LocalClient(Client):
|
|||||||
"""
|
"""
|
||||||
self.database.package_clear(package_base)
|
self.database.package_clear(package_base)
|
||||||
|
|
||||||
def package_status_update(self, package_base: str, status: BuildStatusEnum) -> None:
|
def package_update(self, package_base: str, status: BuildStatusEnum) -> None:
|
||||||
"""
|
"""
|
||||||
update package build status. Unlike :func:`package_update()` it does not update package properties
|
update package build status. Unlike :func:`package_add()` it does not update package properties
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
package_base(str): package base to update
|
package_base(str): package base to update
|
||||||
status(BuildStatusEnum): current package build status
|
status(BuildStatusEnum): current package build status
|
||||||
|
|
||||||
Raises:
|
|
||||||
NotImplementedError: not implemented method
|
|
||||||
"""
|
"""
|
||||||
self.database.status_update(package_base, BuildStatus(status), self.repository_id)
|
self.database.status_update(package_base, BuildStatus(status), self.repository_id)
|
||||||
|
|
||||||
def package_update(self, package: Package, status: BuildStatusEnum) -> None:
|
|
||||||
"""
|
|
||||||
add new package or update existing one with status
|
|
||||||
|
|
||||||
Args:
|
|
||||||
package(Package): package properties
|
|
||||||
status(BuildStatusEnum): current package build status
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
NotImplementedError: not implemented method
|
|
||||||
"""
|
|
||||||
self.database.package_update(package, self.repository_id)
|
|
||||||
self.database.status_update(package.base, BuildStatus(status), self.repository_id)
|
|
||||||
|
@ -78,6 +78,18 @@ class Watcher(LazyLogging):
|
|||||||
for package, status in self.client.package_get(None)
|
for package, status in self.client.package_get(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def package_add(self, package: Package, status: BuildStatusEnum) -> None:
|
||||||
|
"""
|
||||||
|
update package
|
||||||
|
|
||||||
|
Args:
|
||||||
|
package(Package): package description
|
||||||
|
status(BuildStatusEnum): new build status
|
||||||
|
"""
|
||||||
|
with self._lock:
|
||||||
|
self._known[package.base] = (package, BuildStatus(status))
|
||||||
|
self.client.package_add(package, status)
|
||||||
|
|
||||||
package_changes_get: Callable[[str], Changes]
|
package_changes_get: Callable[[str], Changes]
|
||||||
|
|
||||||
package_changes_update: Callable[[str, Changes], None]
|
package_changes_update: Callable[[str, Changes], None]
|
||||||
@ -142,7 +154,7 @@ class Watcher(LazyLogging):
|
|||||||
self.client.package_remove(package_base)
|
self.client.package_remove(package_base)
|
||||||
self.package_logs_remove(package_base, None)
|
self.package_logs_remove(package_base, None)
|
||||||
|
|
||||||
def package_status_update(self, package_base: str, status: BuildStatusEnum) -> None:
|
def package_update(self, package_base: str, status: BuildStatusEnum) -> None:
|
||||||
"""
|
"""
|
||||||
update package status
|
update package status
|
||||||
|
|
||||||
@ -153,19 +165,7 @@ class Watcher(LazyLogging):
|
|||||||
package, _ = self.package_get(package_base)
|
package, _ = self.package_get(package_base)
|
||||||
with self._lock:
|
with self._lock:
|
||||||
self._known[package_base] = (package, BuildStatus(status))
|
self._known[package_base] = (package, BuildStatus(status))
|
||||||
self.client.package_status_update(package_base, status)
|
self.client.package_update(package_base, status)
|
||||||
|
|
||||||
def package_update(self, package: Package, status: BuildStatusEnum) -> None:
|
|
||||||
"""
|
|
||||||
update package
|
|
||||||
|
|
||||||
Args:
|
|
||||||
package(Package): package description
|
|
||||||
status(BuildStatusEnum): new build status
|
|
||||||
"""
|
|
||||||
with self._lock:
|
|
||||||
self._known[package.base] = (package, BuildStatus(status))
|
|
||||||
self.client.package_update(package, status)
|
|
||||||
|
|
||||||
def status_update(self, status: BuildStatusEnum) -> None:
|
def status_update(self, status: BuildStatusEnum) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -157,6 +157,22 @@ class WebClient(Client, SyncAhrimanClient):
|
|||||||
"""
|
"""
|
||||||
return f"{self.address}/api/v1/status"
|
return f"{self.address}/api/v1/status"
|
||||||
|
|
||||||
|
def package_add(self, package: Package, status: BuildStatusEnum) -> None:
|
||||||
|
"""
|
||||||
|
add new package with status
|
||||||
|
|
||||||
|
Args:
|
||||||
|
package(Package): package properties
|
||||||
|
status(BuildStatusEnum): current package build status
|
||||||
|
"""
|
||||||
|
payload = {
|
||||||
|
"status": status.value,
|
||||||
|
"package": package.view()
|
||||||
|
}
|
||||||
|
with contextlib.suppress(Exception):
|
||||||
|
self.make_request("POST", self._package_url(package.base),
|
||||||
|
params=self.repository_id.query(), json=payload)
|
||||||
|
|
||||||
def package_changes_get(self, package_base: str) -> Changes:
|
def package_changes_get(self, package_base: str) -> Changes:
|
||||||
"""
|
"""
|
||||||
get package changes
|
get package changes
|
||||||
@ -349,41 +365,19 @@ class WebClient(Client, SyncAhrimanClient):
|
|||||||
with contextlib.suppress(Exception):
|
with contextlib.suppress(Exception):
|
||||||
self.make_request("DELETE", self._package_url(package_base), params=self.repository_id.query())
|
self.make_request("DELETE", self._package_url(package_base), params=self.repository_id.query())
|
||||||
|
|
||||||
def package_status_update(self, package_base: str, status: BuildStatusEnum) -> None:
|
def package_update(self, package_base: str, status: BuildStatusEnum) -> None:
|
||||||
"""
|
"""
|
||||||
update package build status. Unlike :func:`package_update()` it does not update package properties
|
update package build status. Unlike :func:`package_add()` it does not update package properties
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
package_base(str): package base to update
|
package_base(str): package base to update
|
||||||
status(BuildStatusEnum): current package build status
|
status(BuildStatusEnum): current package build status
|
||||||
|
|
||||||
Raises:
|
|
||||||
NotImplementedError: not implemented method
|
|
||||||
"""
|
"""
|
||||||
payload = {"status": status.value}
|
payload = {"status": status.value}
|
||||||
with contextlib.suppress(Exception):
|
with contextlib.suppress(Exception):
|
||||||
self.make_request("POST", self._package_url(package_base),
|
self.make_request("POST", self._package_url(package_base),
|
||||||
params=self.repository_id.query(), json=payload)
|
params=self.repository_id.query(), json=payload)
|
||||||
|
|
||||||
def package_update(self, package: Package, status: BuildStatusEnum) -> None:
|
|
||||||
"""
|
|
||||||
add new package or update existing one with status
|
|
||||||
|
|
||||||
Args:
|
|
||||||
package(Package): package properties
|
|
||||||
status(BuildStatusEnum): current package build status
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
NotImplementedError: not implemented method
|
|
||||||
"""
|
|
||||||
payload = {
|
|
||||||
"status": status.value,
|
|
||||||
"package": package.view(),
|
|
||||||
}
|
|
||||||
with contextlib.suppress(Exception):
|
|
||||||
self.make_request("POST", self._package_url(package.base),
|
|
||||||
params=self.repository_id.query(), json=payload)
|
|
||||||
|
|
||||||
def status_get(self) -> InternalStatus:
|
def status_get(self) -> InternalStatus:
|
||||||
"""
|
"""
|
||||||
get internal service status
|
get internal service status
|
||||||
|
@ -25,7 +25,6 @@ from typing import TypeVar
|
|||||||
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.distributed import WorkersCache
|
from ahriman.core.distributed import WorkersCache
|
||||||
from ahriman.core.exceptions import UnknownPackageError
|
|
||||||
from ahriman.core.sign.gpg import GPG
|
from ahriman.core.sign.gpg import GPG
|
||||||
from ahriman.core.spawn import Spawn
|
from ahriman.core.spawn import Spawn
|
||||||
from ahriman.core.status.watcher import Watcher
|
from ahriman.core.status.watcher import Watcher
|
||||||
@ -239,8 +238,6 @@ class BaseView(View, CorsViewMixin):
|
|||||||
return self.services[repository_id](package_base)
|
return self.services[repository_id](package_base)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise HTTPNotFound(reason=f"Repository {repository_id.id} is unknown")
|
raise HTTPNotFound(reason=f"Repository {repository_id.id} is unknown")
|
||||||
except UnknownPackageError:
|
|
||||||
raise HTTPNotFound(reason=f"Package {package_base} is unknown")
|
|
||||||
|
|
||||||
async def username(self) -> str | None:
|
async def username(self) -> str | None:
|
||||||
"""
|
"""
|
||||||
|
@ -19,8 +19,9 @@
|
|||||||
#
|
#
|
||||||
import aiohttp_apispec # type: ignore[import-untyped]
|
import aiohttp_apispec # type: ignore[import-untyped]
|
||||||
|
|
||||||
from aiohttp.web import HTTPBadRequest, HTTPNoContent, Response, json_response
|
from aiohttp.web import HTTPBadRequest, HTTPNoContent, HTTPNotFound, Response, json_response
|
||||||
|
|
||||||
|
from ahriman.core.exceptions import UnknownPackageError
|
||||||
from ahriman.models.changes import Changes
|
from ahriman.models.changes import Changes
|
||||||
from ahriman.models.user_access import UserAccess
|
from ahriman.models.user_access import UserAccess
|
||||||
from ahriman.web.schemas import AuthSchema, ChangesSchema, ErrorSchema, PackageNameSchema, RepositoryIdSchema
|
from ahriman.web.schemas import AuthSchema, ChangesSchema, ErrorSchema, PackageNameSchema, RepositoryIdSchema
|
||||||
@ -69,7 +70,10 @@ class ChangesView(StatusViewGuard, BaseView):
|
|||||||
"""
|
"""
|
||||||
package_base = self.request.match_info["package"]
|
package_base = self.request.match_info["package"]
|
||||||
|
|
||||||
|
try:
|
||||||
changes = self.service(package_base=package_base).package_changes_get(package_base)
|
changes = self.service(package_base=package_base).package_changes_get(package_base)
|
||||||
|
except UnknownPackageError:
|
||||||
|
raise HTTPNotFound(reason=f"Package {package_base} is unknown")
|
||||||
|
|
||||||
return json_response(changes.view())
|
return json_response(changes.view())
|
||||||
|
|
||||||
|
@ -19,8 +19,9 @@
|
|||||||
#
|
#
|
||||||
import aiohttp_apispec # type: ignore[import-untyped]
|
import aiohttp_apispec # type: ignore[import-untyped]
|
||||||
|
|
||||||
from aiohttp.web import HTTPBadRequest, HTTPNoContent, Response, json_response
|
from aiohttp.web import HTTPBadRequest, HTTPNoContent, HTTPNotFound, Response, json_response
|
||||||
|
|
||||||
|
from ahriman.core.exceptions import UnknownPackageError
|
||||||
from ahriman.models.dependencies import Dependencies
|
from ahriman.models.dependencies import Dependencies
|
||||||
from ahriman.models.user_access import UserAccess
|
from ahriman.models.user_access import UserAccess
|
||||||
from ahriman.web.schemas import AuthSchema, DependenciesSchema, ErrorSchema, PackageNameSchema, RepositoryIdSchema
|
from ahriman.web.schemas import AuthSchema, DependenciesSchema, ErrorSchema, PackageNameSchema, RepositoryIdSchema
|
||||||
@ -69,7 +70,10 @@ class DependenciesView(StatusViewGuard, BaseView):
|
|||||||
"""
|
"""
|
||||||
package_base = self.request.match_info["package"]
|
package_base = self.request.match_info["package"]
|
||||||
|
|
||||||
|
try:
|
||||||
dependencies = self.service(package_base=package_base).package_dependencies_get(package_base)
|
dependencies = self.service(package_base=package_base).package_dependencies_get(package_base)
|
||||||
|
except UnknownPackageError:
|
||||||
|
raise HTTPNotFound(reason=f"Package {package_base} is unknown")
|
||||||
|
|
||||||
return json_response(dependencies.view())
|
return json_response(dependencies.view())
|
||||||
|
|
||||||
@ -108,6 +112,9 @@ class DependenciesView(StatusViewGuard, BaseView):
|
|||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
raise HTTPBadRequest(reason=str(ex))
|
raise HTTPBadRequest(reason=str(ex))
|
||||||
|
|
||||||
|
try:
|
||||||
self.service(package_base=package_base).package_dependencies_update(package_base, dependencies)
|
self.service(package_base=package_base).package_dependencies_update(package_base, dependencies)
|
||||||
|
except UnknownPackageError:
|
||||||
|
raise HTTPNotFound(reason=f"Package {package_base} is unknown")
|
||||||
|
|
||||||
raise HTTPNoContent
|
raise HTTPNoContent
|
||||||
|
@ -153,9 +153,9 @@ class PackageView(StatusViewGuard, BaseView):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
if package is None:
|
if package is None:
|
||||||
self.service().package_status_update(package_base, status)
|
self.service().package_update(package_base, status)
|
||||||
else:
|
else:
|
||||||
self.service().package_update(package, status)
|
self.service().package_add(package, status)
|
||||||
except UnknownPackageError:
|
except UnknownPackageError:
|
||||||
raise HTTPBadRequest(reason=f"Package {package_base} is unknown, but no package body set")
|
raise HTTPBadRequest(reason=f"Package {package_base} is unknown, but no package body set")
|
||||||
|
|
||||||
|
@ -63,7 +63,6 @@ class PatchView(StatusViewGuard, BaseView):
|
|||||||
"""
|
"""
|
||||||
package_base = self.request.match_info["package"]
|
package_base = self.request.match_info["package"]
|
||||||
variable = self.request.match_info["patch"]
|
variable = self.request.match_info["patch"]
|
||||||
|
|
||||||
self.service().package_patches_remove(package_base, variable)
|
self.service().package_patches_remove(package_base, variable)
|
||||||
|
|
||||||
raise HTTPNoContent
|
raise HTTPNoContent
|
||||||
|
@ -19,8 +19,9 @@
|
|||||||
#
|
#
|
||||||
import aiohttp_apispec # type: ignore[import-untyped]
|
import aiohttp_apispec # type: ignore[import-untyped]
|
||||||
|
|
||||||
from aiohttp.web import Response, json_response
|
from aiohttp.web import HTTPNotFound, Response, json_response
|
||||||
|
|
||||||
|
from ahriman.core.exceptions import UnknownPackageError
|
||||||
from ahriman.models.user_access import UserAccess
|
from ahriman.models.user_access import UserAccess
|
||||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, LogSchema, PackageNameSchema, PaginationSchema
|
from ahriman.web.schemas import AuthSchema, ErrorSchema, LogSchema, PackageNameSchema, PaginationSchema
|
||||||
from ahriman.web.views.base import BaseView
|
from ahriman.web.views.base import BaseView
|
||||||
@ -67,8 +68,10 @@ class LogsView(StatusViewGuard, BaseView):
|
|||||||
"""
|
"""
|
||||||
package_base = self.request.match_info["package"]
|
package_base = self.request.match_info["package"]
|
||||||
limit, offset = self.page()
|
limit, offset = self.page()
|
||||||
|
try:
|
||||||
logs = self.service(package_base=package_base).package_logs_get(package_base, limit, offset)
|
logs = self.service(package_base=package_base).package_logs_get(package_base, limit, offset)
|
||||||
|
except UnknownPackageError:
|
||||||
|
raise HTTPNotFound(reason=f"Package {package_base} is unknown")
|
||||||
|
|
||||||
response = [
|
response = [
|
||||||
{
|
{
|
||||||
|
@ -7,6 +7,8 @@ from unittest.mock import call as MockCall
|
|||||||
from ahriman.core.database import SQLite
|
from ahriman.core.database import SQLite
|
||||||
from ahriman.models.build_status import BuildStatus
|
from ahriman.models.build_status import BuildStatus
|
||||||
from ahriman.models.package import Package
|
from ahriman.models.package import Package
|
||||||
|
from ahriman.models.package_source import PackageSource
|
||||||
|
from ahriman.models.remote_source import RemoteSource
|
||||||
|
|
||||||
|
|
||||||
def test_package_remove_package_base(database: SQLite, connection: Connection) -> None:
|
def test_package_remove_package_base(database: SQLite, connection: Connection) -> None:
|
||||||
@ -183,6 +185,26 @@ def test_package_update_update(database: SQLite, package_ahriman: Package) -> No
|
|||||||
if db_package.base == package_ahriman.base) == package_ahriman.version
|
if db_package.base == package_ahriman.base) == package_ahriman.version
|
||||||
|
|
||||||
|
|
||||||
|
def test_remote_update_get(database: SQLite, package_ahriman: Package) -> None:
|
||||||
|
"""
|
||||||
|
must insert and retrieve package remote
|
||||||
|
"""
|
||||||
|
database.package_base_update(package_ahriman)
|
||||||
|
assert database.remotes_get()[package_ahriman.base] == package_ahriman.remote
|
||||||
|
|
||||||
|
|
||||||
|
def test_remote_update_update(database: SQLite, package_ahriman: Package) -> None:
|
||||||
|
"""
|
||||||
|
must perform package remote update for existing package
|
||||||
|
"""
|
||||||
|
database.package_base_update(package_ahriman)
|
||||||
|
remote_source = RemoteSource(source=PackageSource.Repository)
|
||||||
|
package_ahriman.remote = remote_source
|
||||||
|
|
||||||
|
database.package_base_update(package_ahriman)
|
||||||
|
assert database.remotes_get()[package_ahriman.base] == remote_source
|
||||||
|
|
||||||
|
|
||||||
def test_status_update(database: SQLite, package_ahriman: Package) -> None:
|
def test_status_update(database: SQLite, package_ahriman: Package) -> None:
|
||||||
"""
|
"""
|
||||||
must insert single package status
|
must insert single package status
|
||||||
|
@ -94,6 +94,14 @@ def test_load_web_client_from_legacy_unix_socket(configuration: Configuration, d
|
|||||||
assert isinstance(Client.load(repository_id, configuration, database, report=True), WebClient)
|
assert isinstance(Client.load(repository_id, configuration, database, report=True), WebClient)
|
||||||
|
|
||||||
|
|
||||||
|
def test_package_add(client: Client, package_ahriman: Package) -> None:
|
||||||
|
"""
|
||||||
|
must raise not implemented on package addition
|
||||||
|
"""
|
||||||
|
with pytest.raises(NotImplementedError):
|
||||||
|
client.package_add(package_ahriman, BuildStatusEnum.Unknown)
|
||||||
|
|
||||||
|
|
||||||
def test_package_changes_get(client: Client, package_ahriman: Package) -> None:
|
def test_package_changes_get(client: Client, package_ahriman: Package) -> None:
|
||||||
"""
|
"""
|
||||||
must raise not implemented on package changes request
|
must raise not implemented on package changes request
|
||||||
@ -190,27 +198,19 @@ def test_package_remove(client: Client, package_ahriman: Package) -> None:
|
|||||||
client.package_remove(package_ahriman.base)
|
client.package_remove(package_ahriman.base)
|
||||||
|
|
||||||
|
|
||||||
def test_package_status_update(client: Client, package_ahriman: Package) -> None:
|
def test_package_update(client: Client, package_ahriman: Package) -> None:
|
||||||
"""
|
"""
|
||||||
must raise not implemented on package update
|
must raise not implemented on package update
|
||||||
"""
|
"""
|
||||||
with pytest.raises(NotImplementedError):
|
with pytest.raises(NotImplementedError):
|
||||||
client.package_status_update(package_ahriman.base, BuildStatusEnum.Unknown)
|
client.package_update(package_ahriman.base, BuildStatusEnum.Unknown)
|
||||||
|
|
||||||
|
|
||||||
def test_package_update(client: Client, package_ahriman: Package) -> None:
|
|
||||||
"""
|
|
||||||
must raise not implemented on package addition
|
|
||||||
"""
|
|
||||||
with pytest.raises(NotImplementedError):
|
|
||||||
client.package_update(package_ahriman, BuildStatusEnum.Unknown)
|
|
||||||
|
|
||||||
|
|
||||||
def test_set_building(client: Client, package_ahriman: Package, mocker: MockerFixture) -> None:
|
def test_set_building(client: Client, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must set building status to the package
|
must set building status to the package
|
||||||
"""
|
"""
|
||||||
update_mock = mocker.patch("ahriman.core.status.Client.package_status_update")
|
update_mock = mocker.patch("ahriman.core.status.Client.package_update")
|
||||||
client.set_building(package_ahriman.base)
|
client.set_building(package_ahriman.base)
|
||||||
|
|
||||||
update_mock.assert_called_once_with(package_ahriman.base, BuildStatusEnum.Building)
|
update_mock.assert_called_once_with(package_ahriman.base, BuildStatusEnum.Building)
|
||||||
@ -220,7 +220,7 @@ def test_set_failed(client: Client, package_ahriman: Package, mocker: MockerFixt
|
|||||||
"""
|
"""
|
||||||
must set failed status to the package
|
must set failed status to the package
|
||||||
"""
|
"""
|
||||||
update_mock = mocker.patch("ahriman.core.status.Client.package_status_update")
|
update_mock = mocker.patch("ahriman.core.status.Client.package_update")
|
||||||
client.set_failed(package_ahriman.base)
|
client.set_failed(package_ahriman.base)
|
||||||
|
|
||||||
update_mock.assert_called_once_with(package_ahriman.base, BuildStatusEnum.Failed)
|
update_mock.assert_called_once_with(package_ahriman.base, BuildStatusEnum.Failed)
|
||||||
@ -230,7 +230,7 @@ def test_set_pending(client: Client, package_ahriman: Package, mocker: MockerFix
|
|||||||
"""
|
"""
|
||||||
must set building status to the package
|
must set building status to the package
|
||||||
"""
|
"""
|
||||||
update_mock = mocker.patch("ahriman.core.status.Client.package_status_update")
|
update_mock = mocker.patch("ahriman.core.status.Client.package_update")
|
||||||
client.set_pending(package_ahriman.base)
|
client.set_pending(package_ahriman.base)
|
||||||
|
|
||||||
update_mock.assert_called_once_with(package_ahriman.base, BuildStatusEnum.Pending)
|
update_mock.assert_called_once_with(package_ahriman.base, BuildStatusEnum.Pending)
|
||||||
@ -240,32 +240,20 @@ def test_set_success(client: Client, package_ahriman: Package, mocker: MockerFix
|
|||||||
"""
|
"""
|
||||||
must set success status to the package
|
must set success status to the package
|
||||||
"""
|
"""
|
||||||
update_mock = mocker.patch("ahriman.core.status.Client.package_update")
|
add_mock = mocker.patch("ahriman.core.status.Client.package_add")
|
||||||
client.set_success(package_ahriman)
|
client.set_success(package_ahriman)
|
||||||
|
|
||||||
update_mock.assert_called_once_with(package_ahriman, BuildStatusEnum.Success)
|
add_mock.assert_called_once_with(package_ahriman, BuildStatusEnum.Success)
|
||||||
|
|
||||||
|
|
||||||
def test_set_unknown(client: Client, package_ahriman: Package, mocker: MockerFixture) -> None:
|
def test_set_unknown(client: Client, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must add new package with unknown status
|
must add new package with unknown status
|
||||||
"""
|
"""
|
||||||
mocker.patch("ahriman.core.status.Client.package_get", return_value=[])
|
add_mock = mocker.patch("ahriman.core.status.Client.package_add")
|
||||||
update_mock = mocker.patch("ahriman.core.status.Client.package_update")
|
|
||||||
client.set_unknown(package_ahriman)
|
client.set_unknown(package_ahriman)
|
||||||
|
|
||||||
update_mock.assert_called_once_with(package_ahriman, BuildStatusEnum.Unknown)
|
add_mock.assert_called_once_with(package_ahriman, BuildStatusEnum.Unknown)
|
||||||
|
|
||||||
|
|
||||||
def test_set_unknown_skip(client: Client, package_ahriman: Package, mocker: MockerFixture) -> None:
|
|
||||||
"""
|
|
||||||
must skip unknown status update in case if pacakge is already known
|
|
||||||
"""
|
|
||||||
mocker.patch("ahriman.core.status.Client.package_get", return_value=[(package_ahriman, None)])
|
|
||||||
update_mock = mocker.patch("ahriman.core.status.Client.package_update")
|
|
||||||
client.set_unknown(package_ahriman)
|
|
||||||
|
|
||||||
update_mock.assert_not_called()
|
|
||||||
|
|
||||||
|
|
||||||
def test_status_get(client: Client) -> None:
|
def test_status_get(client: Client) -> None:
|
||||||
|
@ -12,6 +12,18 @@ from ahriman.models.package import Package
|
|||||||
from ahriman.models.pkgbuild_patch import PkgbuildPatch
|
from ahriman.models.pkgbuild_patch import PkgbuildPatch
|
||||||
|
|
||||||
|
|
||||||
|
def test_package_add(local_client: LocalClient, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||||
|
"""
|
||||||
|
must process package addition
|
||||||
|
"""
|
||||||
|
package_mock = mocker.patch("ahriman.core.database.SQLite.package_update")
|
||||||
|
status_mock = mocker.patch("ahriman.core.database.SQLite.status_update")
|
||||||
|
|
||||||
|
local_client.package_add(package_ahriman, BuildStatusEnum.Success)
|
||||||
|
package_mock.assert_called_once_with(package_ahriman, local_client.repository_id)
|
||||||
|
status_mock.assert_called_once_with(package_ahriman.base, pytest.helpers.anyvar(int), local_client.repository_id)
|
||||||
|
|
||||||
|
|
||||||
def test_package_changes_get(local_client: LocalClient, package_ahriman: Package, mocker: MockerFixture) -> None:
|
def test_package_changes_get(local_client: LocalClient, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must retrieve package changes
|
must retrieve package changes
|
||||||
@ -161,22 +173,10 @@ def test_package_remove(local_client: LocalClient, package_ahriman: Package, moc
|
|||||||
package_mock.assert_called_once_with(package_ahriman.base)
|
package_mock.assert_called_once_with(package_ahriman.base)
|
||||||
|
|
||||||
|
|
||||||
def test_package_status_update(local_client: LocalClient, package_ahriman: Package, mocker: MockerFixture) -> None:
|
def test_package_update(local_client: LocalClient, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must update package status
|
must update package status
|
||||||
"""
|
"""
|
||||||
status_mock = mocker.patch("ahriman.core.database.SQLite.status_update")
|
status_mock = mocker.patch("ahriman.core.database.SQLite.status_update")
|
||||||
local_client.package_status_update(package_ahriman.base, BuildStatusEnum.Success)
|
local_client.package_update(package_ahriman.base, BuildStatusEnum.Success)
|
||||||
status_mock.assert_called_once_with(package_ahriman.base, pytest.helpers.anyvar(int), local_client.repository_id)
|
|
||||||
|
|
||||||
|
|
||||||
def test_package_update(local_client: LocalClient, package_ahriman: Package, mocker: MockerFixture) -> None:
|
|
||||||
"""
|
|
||||||
must process package addition
|
|
||||||
"""
|
|
||||||
package_mock = mocker.patch("ahriman.core.database.SQLite.package_update")
|
|
||||||
status_mock = mocker.patch("ahriman.core.database.SQLite.status_update")
|
|
||||||
|
|
||||||
local_client.package_update(package_ahriman, BuildStatusEnum.Success)
|
|
||||||
package_mock.assert_called_once_with(package_ahriman, local_client.repository_id)
|
|
||||||
status_mock.assert_called_once_with(package_ahriman.base, pytest.helpers.anyvar(int), local_client.repository_id)
|
status_mock.assert_called_once_with(package_ahriman.base, pytest.helpers.anyvar(int), local_client.repository_id)
|
||||||
|
@ -46,6 +46,17 @@ def test_load_known(watcher: Watcher, package_ahriman: Package, mocker: MockerFi
|
|||||||
assert status.status == BuildStatusEnum.Success
|
assert status.status == BuildStatusEnum.Success
|
||||||
|
|
||||||
|
|
||||||
|
def test_package_add(watcher: Watcher, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||||
|
"""
|
||||||
|
must add package to cache
|
||||||
|
"""
|
||||||
|
cache_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_add")
|
||||||
|
|
||||||
|
watcher.package_add(package_ahriman, BuildStatusEnum.Unknown)
|
||||||
|
assert watcher.packages
|
||||||
|
cache_mock.assert_called_once_with(package_ahriman, pytest.helpers.anyvar(int))
|
||||||
|
|
||||||
|
|
||||||
def test_package_get(watcher: Watcher, package_ahriman: Package) -> None:
|
def test_package_get(watcher: Watcher, package_ahriman: Package) -> None:
|
||||||
"""
|
"""
|
||||||
must return package status
|
must return package status
|
||||||
@ -119,37 +130,26 @@ def test_package_remove_unknown(watcher: Watcher, package_ahriman: Package, mock
|
|||||||
cache_mock.assert_called_once_with(package_ahriman.base)
|
cache_mock.assert_called_once_with(package_ahriman.base)
|
||||||
|
|
||||||
|
|
||||||
def test_package_status_update(watcher: Watcher, package_ahriman: Package, mocker: MockerFixture) -> None:
|
def test_package_update(watcher: Watcher, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must update package status only for known package
|
must update package status only for known package
|
||||||
"""
|
"""
|
||||||
cache_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_status_update")
|
cache_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_update")
|
||||||
watcher._known = {package_ahriman.base: (package_ahriman, BuildStatus())}
|
watcher._known = {package_ahriman.base: (package_ahriman, BuildStatus())}
|
||||||
|
|
||||||
watcher.package_status_update(package_ahriman.base, BuildStatusEnum.Success)
|
watcher.package_update(package_ahriman.base, BuildStatusEnum.Success)
|
||||||
cache_mock.assert_called_once_with(package_ahriman.base, pytest.helpers.anyvar(int))
|
cache_mock.assert_called_once_with(package_ahriman.base, pytest.helpers.anyvar(int))
|
||||||
package, status = watcher._known[package_ahriman.base]
|
package, status = watcher._known[package_ahriman.base]
|
||||||
assert package == package_ahriman
|
assert package == package_ahriman
|
||||||
assert status.status == BuildStatusEnum.Success
|
assert status.status == BuildStatusEnum.Success
|
||||||
|
|
||||||
|
|
||||||
def test_package_status_update_unknown(watcher: Watcher, package_ahriman: Package) -> None:
|
def test_package_update_unknown(watcher: Watcher, package_ahriman: Package) -> None:
|
||||||
"""
|
"""
|
||||||
must fail on unknown package status update only
|
must fail on unknown package status update only
|
||||||
"""
|
"""
|
||||||
with pytest.raises(UnknownPackageError):
|
with pytest.raises(UnknownPackageError):
|
||||||
watcher.package_status_update(package_ahriman.base, BuildStatusEnum.Unknown)
|
watcher.package_update(package_ahriman.base, BuildStatusEnum.Unknown)
|
||||||
|
|
||||||
|
|
||||||
def test_package_update(watcher: Watcher, package_ahriman: Package, mocker: MockerFixture) -> None:
|
|
||||||
"""
|
|
||||||
must add package to cache
|
|
||||||
"""
|
|
||||||
cache_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_update")
|
|
||||||
|
|
||||||
watcher.package_update(package_ahriman, BuildStatusEnum.Unknown)
|
|
||||||
assert watcher.packages
|
|
||||||
cache_mock.assert_called_once_with(package_ahriman, pytest.helpers.anyvar(int))
|
|
||||||
|
|
||||||
|
|
||||||
def test_status_update(watcher: Watcher) -> None:
|
def test_status_update(watcher: Watcher) -> None:
|
||||||
|
@ -97,6 +97,59 @@ def test_status_url(web_client: WebClient) -> None:
|
|||||||
assert web_client._status_url().endswith("/api/v1/status")
|
assert web_client._status_url().endswith("/api/v1/status")
|
||||||
|
|
||||||
|
|
||||||
|
def test_package_add(web_client: WebClient, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||||
|
"""
|
||||||
|
must process package addition
|
||||||
|
"""
|
||||||
|
requests_mock = mocker.patch("ahriman.core.status.web_client.WebClient.make_request")
|
||||||
|
payload = pytest.helpers.get_package_status(package_ahriman)
|
||||||
|
|
||||||
|
web_client.package_add(package_ahriman, BuildStatusEnum.Unknown)
|
||||||
|
requests_mock.assert_called_once_with("POST", pytest.helpers.anyvar(str, True),
|
||||||
|
params=web_client.repository_id.query(), json=payload)
|
||||||
|
|
||||||
|
|
||||||
|
def test_package_add_failed(web_client: WebClient, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||||
|
"""
|
||||||
|
must suppress any exception happened during addition
|
||||||
|
"""
|
||||||
|
mocker.patch("requests.Session.request", side_effect=Exception())
|
||||||
|
web_client.package_add(package_ahriman, BuildStatusEnum.Unknown)
|
||||||
|
|
||||||
|
|
||||||
|
def test_package_add_failed_http_error(web_client: WebClient, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||||
|
"""
|
||||||
|
must suppress HTTP exception happened during addition
|
||||||
|
"""
|
||||||
|
mocker.patch("requests.Session.request", side_effect=requests.HTTPError())
|
||||||
|
web_client.package_add(package_ahriman, BuildStatusEnum.Unknown)
|
||||||
|
|
||||||
|
|
||||||
|
def test_package_add_failed_suppress(web_client: WebClient, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||||
|
"""
|
||||||
|
must suppress any exception happened during addition and don't log
|
||||||
|
"""
|
||||||
|
web_client.suppress_errors = True
|
||||||
|
mocker.patch("requests.Session.request", side_effect=Exception())
|
||||||
|
logging_mock = mocker.patch("logging.exception")
|
||||||
|
|
||||||
|
web_client.package_add(package_ahriman, BuildStatusEnum.Unknown)
|
||||||
|
logging_mock.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
|
def test_package_add_failed_http_error_suppress(web_client: WebClient, package_ahriman: Package,
|
||||||
|
mocker: MockerFixture) -> None:
|
||||||
|
"""
|
||||||
|
must suppress HTTP exception happened during addition and don't log
|
||||||
|
"""
|
||||||
|
web_client.suppress_errors = True
|
||||||
|
mocker.patch("requests.Session.request", side_effect=requests.HTTPError())
|
||||||
|
logging_mock = mocker.patch("logging.exception")
|
||||||
|
|
||||||
|
web_client.package_add(package_ahriman, BuildStatusEnum.Unknown)
|
||||||
|
logging_mock.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
def test_package_changes_get(web_client: WebClient, package_ahriman: Package, mocker: MockerFixture) -> None:
|
def test_package_changes_get(web_client: WebClient, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must get changes
|
must get changes
|
||||||
@ -732,13 +785,13 @@ def test_package_remove_failed_http_error(web_client: WebClient, package_ahriman
|
|||||||
web_client.package_remove(package_ahriman.base)
|
web_client.package_remove(package_ahriman.base)
|
||||||
|
|
||||||
|
|
||||||
def test_package_status_update(web_client: WebClient, package_ahriman: Package, mocker: MockerFixture) -> None:
|
def test_package_update(web_client: WebClient, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must process package update
|
must process package update
|
||||||
"""
|
"""
|
||||||
requests_mock = mocker.patch("ahriman.core.status.web_client.WebClient.make_request")
|
requests_mock = mocker.patch("ahriman.core.status.web_client.WebClient.make_request")
|
||||||
|
|
||||||
web_client.package_status_update(package_ahriman.base, BuildStatusEnum.Unknown)
|
web_client.package_update(package_ahriman.base, BuildStatusEnum.Unknown)
|
||||||
requests_mock.assert_called_once_with("POST", pytest.helpers.anyvar(str, True),
|
requests_mock.assert_called_once_with("POST", pytest.helpers.anyvar(str, True),
|
||||||
params=web_client.repository_id.query(),
|
params=web_client.repository_id.query(),
|
||||||
json={
|
json={
|
||||||
@ -746,75 +799,21 @@ def test_package_status_update(web_client: WebClient, package_ahriman: Package,
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
def test_package_status_update_failed(web_client: WebClient, package_ahriman: Package, mocker: MockerFixture) -> None:
|
def test_package_update_failed(web_client: WebClient, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must suppress any exception happened during update
|
must suppress any exception happened during update
|
||||||
"""
|
"""
|
||||||
mocker.patch("requests.Session.request", side_effect=Exception())
|
mocker.patch("requests.Session.request", side_effect=Exception())
|
||||||
web_client.package_status_update(package_ahriman.base, BuildStatusEnum.Unknown)
|
web_client.package_update(package_ahriman.base, BuildStatusEnum.Unknown)
|
||||||
|
|
||||||
|
|
||||||
def test_package_status_update_failed_http_error(web_client: WebClient, package_ahriman: Package,
|
|
||||||
mocker: MockerFixture) -> None:
|
|
||||||
"""
|
|
||||||
must suppress HTTP exception happened during update
|
|
||||||
"""
|
|
||||||
mocker.patch("requests.Session.request", side_effect=requests.HTTPError())
|
|
||||||
web_client.package_status_update(package_ahriman.base, BuildStatusEnum.Unknown)
|
|
||||||
|
|
||||||
|
|
||||||
def test_package_update(web_client: WebClient, package_ahriman: Package, mocker: MockerFixture) -> None:
|
|
||||||
"""
|
|
||||||
must process package addition
|
|
||||||
"""
|
|
||||||
requests_mock = mocker.patch("ahriman.core.status.web_client.WebClient.make_request")
|
|
||||||
payload = pytest.helpers.get_package_status(package_ahriman)
|
|
||||||
|
|
||||||
web_client.package_update(package_ahriman, BuildStatusEnum.Unknown)
|
|
||||||
requests_mock.assert_called_once_with("POST", pytest.helpers.anyvar(str, True),
|
|
||||||
params=web_client.repository_id.query(), json=payload)
|
|
||||||
|
|
||||||
|
|
||||||
def test_package_update_failed(web_client: WebClient, package_ahriman: Package, mocker: MockerFixture) -> None:
|
|
||||||
"""
|
|
||||||
must suppress any exception happened during addition
|
|
||||||
"""
|
|
||||||
mocker.patch("requests.Session.request", side_effect=Exception())
|
|
||||||
web_client.package_update(package_ahriman, BuildStatusEnum.Unknown)
|
|
||||||
|
|
||||||
|
|
||||||
def test_package_update_failed_http_error(web_client: WebClient, package_ahriman: Package,
|
def test_package_update_failed_http_error(web_client: WebClient, package_ahriman: Package,
|
||||||
mocker: MockerFixture) -> None:
|
mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must suppress HTTP exception happened during addition
|
must suppress HTTP exception happened during update
|
||||||
"""
|
"""
|
||||||
mocker.patch("requests.Session.request", side_effect=requests.HTTPError())
|
mocker.patch("requests.Session.request", side_effect=requests.HTTPError())
|
||||||
web_client.package_update(package_ahriman, BuildStatusEnum.Unknown)
|
web_client.package_update(package_ahriman.base, BuildStatusEnum.Unknown)
|
||||||
|
|
||||||
|
|
||||||
def test_package_update_failed_suppress(web_client: WebClient, package_ahriman: Package, mocker: MockerFixture) -> None:
|
|
||||||
"""
|
|
||||||
must suppress any exception happened during addition and don't log
|
|
||||||
"""
|
|
||||||
web_client.suppress_errors = True
|
|
||||||
mocker.patch("requests.Session.request", side_effect=Exception())
|
|
||||||
logging_mock = mocker.patch("logging.exception")
|
|
||||||
|
|
||||||
web_client.package_update(package_ahriman, BuildStatusEnum.Unknown)
|
|
||||||
logging_mock.assert_not_called()
|
|
||||||
|
|
||||||
|
|
||||||
def test_package_update_failed_http_error_suppress(web_client: WebClient, package_ahriman: Package,
|
|
||||||
mocker: MockerFixture) -> None:
|
|
||||||
"""
|
|
||||||
must suppress HTTP exception happened during addition and don't log
|
|
||||||
"""
|
|
||||||
web_client.suppress_errors = True
|
|
||||||
mocker.patch("requests.Session.request", side_effect=requests.HTTPError())
|
|
||||||
logging_mock = mocker.patch("logging.exception")
|
|
||||||
|
|
||||||
web_client.package_update(package_ahriman, BuildStatusEnum.Unknown)
|
|
||||||
logging_mock.assert_not_called()
|
|
||||||
|
|
||||||
|
|
||||||
def test_status_get(web_client: WebClient, mocker: MockerFixture) -> None:
|
def test_status_get(web_client: WebClient, mocker: MockerFixture) -> None:
|
||||||
|
@ -7,6 +7,7 @@ from pytest_mock import MockerFixture
|
|||||||
from unittest.mock import AsyncMock
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
from ahriman.core.configuration import Configuration
|
from ahriman.core.configuration import Configuration
|
||||||
|
from ahriman.core.exceptions import UnknownPackageError
|
||||||
from ahriman.models.repository_id import RepositoryId
|
from ahriman.models.repository_id import RepositoryId
|
||||||
from ahriman.models.user_access import UserAccess
|
from ahriman.models.user_access import UserAccess
|
||||||
from ahriman.web.keys import WatcherKey
|
from ahriman.web.keys import WatcherKey
|
||||||
@ -209,7 +210,7 @@ def test_service_package(base: BaseView, repository_id: RepositoryId, mocker: Mo
|
|||||||
must validate that package exists
|
must validate that package exists
|
||||||
"""
|
"""
|
||||||
mocker.patch("ahriman.web.views.base.BaseView.repository_id", return_value=repository_id)
|
mocker.patch("ahriman.web.views.base.BaseView.repository_id", return_value=repository_id)
|
||||||
with pytest.raises(HTTPNotFound):
|
with pytest.raises(UnknownPackageError):
|
||||||
base.service(package_base="base")
|
base.service(package_base="base")
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user