mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-03-13 10:14:13 +00:00
test(service): test moving with rebuilding via fp
This commit is contained in:
parent
12b2153b7c
commit
6e29da4a4f
2 changed files with 36 additions and 16 deletions
tests/test_graphql
|
@ -13,8 +13,7 @@ from selfprivacy_api.services.test_service import DummyService
|
||||||
|
|
||||||
from tests.common import generate_service_query
|
from tests.common import generate_service_query
|
||||||
from tests.test_graphql.common import assert_empty, assert_ok, get_data
|
from tests.test_graphql.common import assert_empty, assert_ok, get_data
|
||||||
from tests.test_block_device_utils import lsblk_singular_mock
|
from tests.test_graphql.test_system_nixos_tasks import prepare_nixos_rebuild_calls
|
||||||
|
|
||||||
|
|
||||||
LSBLK_BLOCKDEVICES_DICTS = [
|
LSBLK_BLOCKDEVICES_DICTS = [
|
||||||
{
|
{
|
||||||
|
@ -618,10 +617,7 @@ def test_graphql_move_service_without_folders_on_old_volume(
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_move_service(
|
def test_graphql_move_service(
|
||||||
authorized_client,
|
authorized_client, generic_userdata, mock_check_volume, dummy_service_with_binds, fp
|
||||||
generic_userdata,
|
|
||||||
mock_check_volume,
|
|
||||||
dummy_service_with_binds,
|
|
||||||
):
|
):
|
||||||
dummy_service = dummy_service_with_binds
|
dummy_service = dummy_service_with_binds
|
||||||
|
|
||||||
|
@ -633,10 +629,30 @@ def test_graphql_move_service(
|
||||||
dummy_service.set_drive(origin)
|
dummy_service.set_drive(origin)
|
||||||
dummy_service.set_simulated_moves(False)
|
dummy_service.set_simulated_moves(False)
|
||||||
|
|
||||||
|
unit_name = "sp-nixos-rebuild.service"
|
||||||
|
rebuild_command = ["systemctl", "start", unit_name]
|
||||||
|
prepare_nixos_rebuild_calls(fp, unit_name)
|
||||||
|
|
||||||
|
# We will be mounting and remounting folders
|
||||||
|
mount_command = ["mount", fp.any()]
|
||||||
|
unmount_command = ["umount", fp.any()]
|
||||||
|
fp.pass_command(mount_command, 2)
|
||||||
|
fp.pass_command(unmount_command, 2)
|
||||||
|
|
||||||
|
# We will be changing ownership
|
||||||
|
chown_command = ["chown", fp.any()]
|
||||||
|
fp.pass_command(chown_command, 2)
|
||||||
|
|
||||||
mutation_response = api_move(authorized_client, dummy_service, target)
|
mutation_response = api_move(authorized_client, dummy_service, target)
|
||||||
|
|
||||||
data = get_data(mutation_response)["services"]["moveService"]
|
data = get_data(mutation_response)["services"]["moveService"]
|
||||||
assert_ok(data)
|
assert_ok(data)
|
||||||
|
assert data["service"] is not None
|
||||||
|
|
||||||
|
assert fp.call_count(rebuild_command) == 1
|
||||||
|
assert fp.call_count(mount_command) == 2
|
||||||
|
assert fp.call_count(unmount_command) == 2
|
||||||
|
assert fp.call_count(chown_command) == 2
|
||||||
|
|
||||||
|
|
||||||
def test_mailservice_cannot_enable_disable(authorized_client):
|
def test_mailservice_cannot_enable_disable(authorized_client):
|
||||||
|
|
|
@ -97,16 +97,7 @@ def test_graphql_system_rebuild_unauthorized(client, fp, action):
|
||||||
assert fp.call_count([fp.any()]) == 0
|
assert fp.call_count([fp.any()]) == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("action", ["rebuild", "upgrade"])
|
def prepare_nixos_rebuild_calls(fp, unit_name):
|
||||||
def test_graphql_system_rebuild(authorized_client, fp, action, mock_sleep_intervals):
|
|
||||||
"""Test system rebuild"""
|
|
||||||
unit_name = f"sp-nixos-{action}.service"
|
|
||||||
query = (
|
|
||||||
API_REBUILD_SYSTEM_MUTATION
|
|
||||||
if action == "rebuild"
|
|
||||||
else API_UPGRADE_SYSTEM_MUTATION
|
|
||||||
)
|
|
||||||
|
|
||||||
# Start the unit
|
# Start the unit
|
||||||
fp.register(["systemctl", "start", unit_name])
|
fp.register(["systemctl", "start", unit_name])
|
||||||
|
|
||||||
|
@ -129,6 +120,19 @@ def test_graphql_system_rebuild(authorized_client, fp, action, mock_sleep_interv
|
||||||
|
|
||||||
fp.register(["systemctl", "show", unit_name], stdout="ActiveState=inactive")
|
fp.register(["systemctl", "show", unit_name], stdout="ActiveState=inactive")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("action", ["rebuild", "upgrade"])
|
||||||
|
def test_graphql_system_rebuild(authorized_client, fp, action, mock_sleep_intervals):
|
||||||
|
"""Test system rebuild"""
|
||||||
|
unit_name = f"sp-nixos-{action}.service"
|
||||||
|
query = (
|
||||||
|
API_REBUILD_SYSTEM_MUTATION
|
||||||
|
if action == "rebuild"
|
||||||
|
else API_UPGRADE_SYSTEM_MUTATION
|
||||||
|
)
|
||||||
|
|
||||||
|
prepare_nixos_rebuild_calls(fp, unit_name)
|
||||||
|
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
|
|
Loading…
Add table
Reference in a new issue