mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-22 12:11:26 +00:00
fix: frem review
This commit is contained in:
parent
29596a4f47
commit
567f094336
|
@ -6,9 +6,11 @@ from selfprivacy_api.utils.huey import huey
|
||||||
|
|
||||||
from selfprivacy_api.jobs import JobStatus, Jobs, Job
|
from selfprivacy_api.jobs import JobStatus, Jobs, Job
|
||||||
|
|
||||||
|
|
||||||
class ShellException(Exception):
|
class ShellException(Exception):
|
||||||
"""Shell-related errors"""
|
"""Shell-related errors"""
|
||||||
|
|
||||||
|
|
||||||
COMPLETED_WITH_ERROR = (
|
COMPLETED_WITH_ERROR = (
|
||||||
"Error occurred, please report this to the support chat."
|
"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)
|
percent = int((completed_packages / total_dead_packages) * 100)
|
||||||
|
|
||||||
if percent - prev_progress >= 5:
|
if percent - prev_progress >= 5:
|
||||||
|
|
||||||
Jobs.update(
|
Jobs.update(
|
||||||
job=job,
|
job=job,
|
||||||
status=JobStatus.RUNNING,
|
status=JobStatus.RUNNING,
|
||||||
|
@ -140,7 +143,7 @@ def start_nix_collect_garbage() -> Job:
|
||||||
name="Collect garbage",
|
name="Collect garbage",
|
||||||
description="Cleaning up unused packages",
|
description="Cleaning up unused packages",
|
||||||
)
|
)
|
||||||
task_handle = calculate_and_clear_dead_paths(job=job)
|
|
||||||
result = task_handle(blocking=True)
|
calculate_and_clear_dead_paths(job=job)
|
||||||
assert result
|
|
||||||
return job
|
return job
|
||||||
|
|
|
@ -3,9 +3,10 @@
|
||||||
# pylint: disable=missing-function-docstring
|
# pylint: disable=missing-function-docstring
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from selfprivacy_api.utils.huey import huey
|
||||||
|
|
||||||
from selfprivacy_api.jobs import JobStatus, Jobs, Job
|
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 (
|
from selfprivacy_api.jobs.nix_collect_garbage import (
|
||||||
get_dead_packages,
|
get_dead_packages,
|
||||||
|
@ -60,12 +61,6 @@ def mock_delete_old_gens_and_return_dead_report(mocker):
|
||||||
return mock
|
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):
|
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(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
|
@ -143,17 +139,17 @@ def test_graphql_nix_collect_garbage(authorized_client, mock_delete_old_gens_and
|
||||||
output = get_data(response)["system"]["nixCollectGarbage"]
|
output = get_data(response)["system"]["nixCollectGarbage"]
|
||||||
assert_ok(output)
|
assert_ok(output)
|
||||||
assert output["job"] is not None
|
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):
|
def test_graphql_nix_collect_garbage_not_authorized_client(client, mock_delete_old_gens_and_return_dead_report):
|
||||||
response = authorized_client.post(
|
assert huey.immediate is True
|
||||||
|
response = client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": RUN_NIX_COLLECT_GARBAGE_MUTATION,
|
"query": RUN_NIX_COLLECT_GARBAGE_MUTATION,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
output = get_data(response)["system"]["nixCollectGarbage"]
|
assert_empty(response)
|
||||||
assert_ok(output)
|
|
||||||
assert output["job"] is not None
|
|
||||||
assert output["job"]["status"] == "ERROR"
|
|
||||||
|
|
Loading…
Reference in a new issue