fix: frem review

This commit is contained in:
dettlaff 2024-02-08 18:40:12 +04:00
parent 29596a4f47
commit 567f094336
2 changed files with 15 additions and 16 deletions

View file

@ -6,9 +6,11 @@ from selfprivacy_api.utils.huey import huey
from selfprivacy_api.jobs import JobStatus, Jobs, Job
class ShellException(Exception):
"""Shell-related errors"""
COMPLETED_WITH_ERROR = (
"Error occurred, please report this to the support chat."
)
@ -72,6 +74,7 @@ def process_stream(job: Job, stream: Iterable[bytes], total_dead_packages: int)
percent = int((completed_packages / total_dead_packages) * 100)
if percent - prev_progress >= 5:
Jobs.update(
job=job,
status=JobStatus.RUNNING,
@ -140,7 +143,7 @@ def start_nix_collect_garbage() -> Job:
name="Collect garbage",
description="Cleaning up unused packages",
)
task_handle = calculate_and_clear_dead_paths(job=job)
result = task_handle(blocking=True)
assert result
calculate_and_clear_dead_paths(job=job)
return job

View file

@ -3,9 +3,10 @@
# pylint: disable=missing-function-docstring
import pytest
from selfprivacy_api.utils.huey import huey
from selfprivacy_api.jobs import JobStatus, Jobs, Job
from tests.test_graphql.common import get_data, assert_errorcode, assert_ok
from tests.test_graphql.common import get_data, assert_errorcode, assert_ok, assert_empty
from selfprivacy_api.jobs.nix_collect_garbage import (
get_dead_packages,
@ -60,12 +61,6 @@ def mock_delete_old_gens_and_return_dead_report(mocker):
return mock
@pytest.fixture
def mock_run_nix_collect_garbage_returns_gibberish(mocker):
mock = mocker.patch("selfprivacy_api.jobs.nix_collect_garbage.run_nix_collect_garbage", autospec=True, return_value=b" oiuojkhjkhjkhjkhkjh")
return mock
# ---
@ -133,6 +128,7 @@ mutation CollectGarbage {
def test_graphql_nix_collect_garbage(authorized_client, mock_delete_old_gens_and_return_dead_report):
assert huey.immediate is True
response = authorized_client.post(
"/graphql",
json={
@ -143,17 +139,17 @@ def test_graphql_nix_collect_garbage(authorized_client, mock_delete_old_gens_and
output = get_data(response)["system"]["nixCollectGarbage"]
assert_ok(output)
assert output["job"] is not None
assert output["job"]["status"] == "FINISHED"
assert output["job"]["error"] is None
def test_graphql_nix_collect_garbage_with_problems(authorized_client, mock_run_nix_collect_garbage_returns_gibberish):
response = authorized_client.post(
def test_graphql_nix_collect_garbage_not_authorized_client(client, mock_delete_old_gens_and_return_dead_report):
assert huey.immediate is True
response = client.post(
"/graphql",
json={
"query": RUN_NIX_COLLECT_GARBAGE_MUTATION,
},
)
output = get_data(response)["system"]["nixCollectGarbage"]
assert_ok(output)
assert output["job"] is not None
assert output["job"]["status"] == "ERROR"
assert_empty(response)