Skip to content

Commit

Permalink
do not update unknown status
Browse files Browse the repository at this point in the history
  • Loading branch information
arcan1s committed May 20, 2024
1 parent ccb6aae commit 89f1b6e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
15 changes: 9 additions & 6 deletions src/ahriman/core/status/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def set_building(self, package_base: str) -> None:
Args:
package_base(str): package base to update
"""
return self.package_status_update(package_base, BuildStatusEnum.Building)
self.package_status_update(package_base, BuildStatusEnum.Building)

def set_failed(self, package_base: str) -> None:
"""
Expand All @@ -287,7 +287,7 @@ def set_failed(self, package_base: str) -> None:
Args:
package_base(str): package base to update
"""
return self.package_status_update(package_base, BuildStatusEnum.Failed)
self.package_status_update(package_base, BuildStatusEnum.Failed)

def set_pending(self, package_base: str) -> None:
"""
Expand All @@ -296,7 +296,7 @@ def set_pending(self, package_base: str) -> None:
Args:
package_base(str): package base to update
"""
return self.package_status_update(package_base, BuildStatusEnum.Pending)
self.package_status_update(package_base, BuildStatusEnum.Pending)

def set_success(self, package: Package) -> None:
"""
Expand All @@ -305,16 +305,19 @@ def set_success(self, package: Package) -> None:
Args:
package(Package): current package properties
"""
return self.package_update(package, BuildStatusEnum.Success)
self.package_update(package, BuildStatusEnum.Success)

def set_unknown(self, package: Package) -> None:
"""
set package status to unknown
set package status to unknown. Unlike other methods, this method also checks if package is known,
and - in case if it is - it silently skips updatd
Args:
package(Package): current package properties
"""
return self.package_update(package, BuildStatusEnum.Unknown)
if self.package_get(package.base):
return # skip update in case if package is already known
self.package_update(package, BuildStatusEnum.Unknown)

def status_get(self) -> InternalStatus:
"""
Expand Down
20 changes: 16 additions & 4 deletions tests/ahriman/core/status/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,20 +240,32 @@ def test_set_success(client: Client, package_ahriman: Package, mocker: MockerFix
"""
must set success status to the package
"""
add_mock = mocker.patch("ahriman.core.status.Client.package_update")
update_mock = mocker.patch("ahriman.core.status.Client.package_update")
client.set_success(package_ahriman)

add_mock.assert_called_once_with(package_ahriman, BuildStatusEnum.Success)
update_mock.assert_called_once_with(package_ahriman, BuildStatusEnum.Success)


def test_set_unknown(client: Client, package_ahriman: Package, mocker: MockerFixture) -> None:
"""
must add new package with unknown status
"""
add_mock = mocker.patch("ahriman.core.status.Client.package_update")
mocker.patch("ahriman.core.status.Client.package_get", return_value=[])
update_mock = mocker.patch("ahriman.core.status.Client.package_update")
client.set_unknown(package_ahriman)

add_mock.assert_called_once_with(package_ahriman, BuildStatusEnum.Unknown)
update_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:
Expand Down

0 comments on commit 89f1b6e

Please sign in to comment.