mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-24 04:51:27 +00:00
tests: add real file check
This commit is contained in:
parent
0593c8cc8e
commit
086ec0efc5
|
@ -1,26 +1,74 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from selfprivacy_api.services.flake_service_manager import FlakeServiceManager
|
from selfprivacy_api.services.flake_service_manager import (
|
||||||
|
FlakeServiceManager,
|
||||||
|
FLAKE_CONFIG_PATH,
|
||||||
|
)
|
||||||
|
|
||||||
|
all_services_file = """
|
||||||
|
{
|
||||||
|
description = "SelfPrivacy NixOS PoC modules/extensions/bundles/packages/etc";
|
||||||
|
|
||||||
|
|
||||||
|
inputs.bitwarden.url = git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/bitwarden;
|
||||||
|
|
||||||
|
inputs.gitea.url = git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/gitea;
|
||||||
|
|
||||||
|
inputs.jitsi-meet.url = git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/jitsi-meet;
|
||||||
|
|
||||||
|
inputs.nextcloud.url = git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/nextcloud;
|
||||||
|
|
||||||
|
inputs.ocserv.url = git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/ocserv;
|
||||||
|
|
||||||
|
inputs.pleroma.url = git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/pleroma;
|
||||||
|
|
||||||
|
inputs.simple-nixos-mailserver.url = git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/simple-nixos-mailserver;
|
||||||
|
|
||||||
|
outputs = _: { };
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
some_services_file = """
|
||||||
|
{
|
||||||
|
description = "SelfPrivacy NixOS PoC modules/extensions/bundles/packages/etc";
|
||||||
|
|
||||||
|
|
||||||
|
inputs.bitwarden.url = git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/bitwarden;
|
||||||
|
|
||||||
|
inputs.gitea.url = git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/gitea;
|
||||||
|
|
||||||
|
inputs.jitsi-meet.url = git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/jitsi-meet;
|
||||||
|
|
||||||
|
outputs = _: { };
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def some_services_flake_mock(mocker, datadir):
|
def some_services_flake_mock(mocker, datadir):
|
||||||
|
flake_config_path = datadir / "some_services.nix"
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
"selfprivacy_api.services.flake_service_manager.FLAKE_CONFIG_PATH",
|
"selfprivacy_api.services.flake_service_manager.FLAKE_CONFIG_PATH",
|
||||||
new=datadir / "some_services.nix",
|
new=flake_config_path,
|
||||||
)
|
)
|
||||||
|
return flake_config_path
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def no_services_flake_mock(mocker, datadir):
|
def no_services_flake_mock(mocker, datadir):
|
||||||
|
flake_config_path = datadir / "no_services.nix"
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
"selfprivacy_api.services.flake_service_manager.FLAKE_CONFIG_PATH",
|
"selfprivacy_api.services.flake_service_manager.FLAKE_CONFIG_PATH",
|
||||||
new=datadir / "no_services.nix",
|
new=flake_config_path,
|
||||||
)
|
)
|
||||||
|
return flake_config_path
|
||||||
|
|
||||||
|
|
||||||
|
# ---
|
||||||
|
|
||||||
|
|
||||||
def test_read_services_list(some_services_flake_mock):
|
def test_read_services_list(some_services_flake_mock):
|
||||||
|
|
||||||
with FlakeServiceManager() as manager:
|
with FlakeServiceManager() as manager:
|
||||||
services = {
|
services = {
|
||||||
"bitwarden": "git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/bitwarden",
|
"bitwarden": "git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/bitwarden",
|
||||||
|
@ -47,6 +95,11 @@ def test_change_services_list(some_services_flake_mock):
|
||||||
with FlakeServiceManager() as manager:
|
with FlakeServiceManager() as manager:
|
||||||
assert manager.services == services
|
assert manager.services == services
|
||||||
|
|
||||||
|
with open(some_services_flake_mock, "r", encoding="utf-8") as file:
|
||||||
|
file_content = file.read().strip()
|
||||||
|
|
||||||
|
assert all_services_file.strip() == file_content
|
||||||
|
|
||||||
|
|
||||||
def test_read_empty_services_list(no_services_flake_mock):
|
def test_read_empty_services_list(no_services_flake_mock):
|
||||||
with FlakeServiceManager() as manager:
|
with FlakeServiceManager() as manager:
|
||||||
|
@ -70,3 +123,8 @@ def test_change_empty_services_list(no_services_flake_mock):
|
||||||
|
|
||||||
with FlakeServiceManager() as manager:
|
with FlakeServiceManager() as manager:
|
||||||
assert manager.services == services
|
assert manager.services == services
|
||||||
|
|
||||||
|
with open(no_services_flake_mock, "r", encoding="utf-8") as file:
|
||||||
|
file_content = file.read().strip()
|
||||||
|
|
||||||
|
assert all_services_file.strip() == file_content
|
||||||
|
|
Loading…
Reference in a new issue