api/schema: get schema without having a machine
Also done: - add @pytest.mark.with_core indicating that a test depends on clan-core and cannot be cached - separate unit tests into two derivations, ones that can be cached and ones that cannot. - fix frontend typescript code
This commit is contained in:
@@ -3,7 +3,7 @@ from api import TestClient
|
||||
from fixtures_flakes import FlakeForTest
|
||||
|
||||
|
||||
@pytest.mark.impure()
|
||||
@pytest.mark.with_core
|
||||
def test_configure_machine(api: TestClient, test_flake_with_core: FlakeForTest) -> None:
|
||||
# retrieve the list of available clanModules
|
||||
response = api.get(f"/api/{test_flake_with_core.name}/clan_modules")
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import pytest
|
||||
from api import TestClient
|
||||
from fixtures_flakes import FlakeForTest
|
||||
|
||||
@@ -21,37 +22,46 @@ def test_machines(api: TestClient, test_flake: FlakeForTest) -> None:
|
||||
assert response.json() == {"machines": [{"name": "test", "status": "unknown"}]}
|
||||
|
||||
|
||||
def test_configure_machine(api: TestClient, test_flake: FlakeForTest) -> None:
|
||||
@pytest.mark.with_core
|
||||
def test_configure_machine(api: TestClient, test_flake_with_core: FlakeForTest) -> None:
|
||||
# ensure error 404 if machine does not exist when accessing the config
|
||||
response = api.get(f"/api/{test_flake.name}/machines/machine1/config")
|
||||
response = api.get(f"/api/{test_flake_with_core.name}/machines/machine1/config")
|
||||
assert response.status_code == 404
|
||||
|
||||
# ensure error 404 if machine does not exist when writing to the config
|
||||
response = api.put(f"/api/{test_flake.name}/machines/machine1/config", json={})
|
||||
response = api.put(
|
||||
f"/api/{test_flake_with_core.name}/machines/machine1/config", json={}
|
||||
)
|
||||
assert response.status_code == 404
|
||||
|
||||
# create the machine
|
||||
response = api.post(f"/api/{test_flake.name}/machines", json={"name": "machine1"})
|
||||
response = api.post(
|
||||
f"/api/{test_flake_with_core.name}/machines", json={"name": "machine1"}
|
||||
)
|
||||
assert response.status_code == 201
|
||||
|
||||
# ensure an empty config is returned by default for a new machine
|
||||
response = api.get(f"/api/{test_flake.name}/machines/machine1/config")
|
||||
response = api.get(f"/api/{test_flake_with_core.name}/machines/machine1/config")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {
|
||||
"clanImports": [],
|
||||
"clan": {},
|
||||
}
|
||||
|
||||
# get jsonschema for machine
|
||||
response = api.get(f"/api/{test_flake.name}/machines/machine1/schema")
|
||||
# get jsonschema for without imports
|
||||
response = api.put(
|
||||
f"/api/{test_flake_with_core.name}/schema",
|
||||
json={"clanImports": []},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
json_response = response.json()
|
||||
assert "schema" in json_response and "properties" in json_response["schema"]
|
||||
|
||||
# an invalid config missing the fileSystems
|
||||
invalid_config = dict(
|
||||
clan=dict(
|
||||
jitsi=dict(
|
||||
clan=dict(),
|
||||
services=dict(
|
||||
nginx=dict(
|
||||
enable=True,
|
||||
),
|
||||
),
|
||||
@@ -59,7 +69,7 @@ def test_configure_machine(api: TestClient, test_flake: FlakeForTest) -> None:
|
||||
|
||||
# verify an invalid config (fileSystems missing) fails
|
||||
response = api.put(
|
||||
f"/api/{test_flake.name}/machines/machine1/verify",
|
||||
f"/api/{test_flake_with_core.name}/machines/machine1/verify",
|
||||
json=invalid_config,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
@@ -70,13 +80,13 @@ def test_configure_machine(api: TestClient, test_flake: FlakeForTest) -> None:
|
||||
|
||||
# set come invalid config (fileSystems missing)
|
||||
response = api.put(
|
||||
f"/api/{test_flake.name}/machines/machine1/config",
|
||||
f"/api/{test_flake_with_core.name}/machines/machine1/config",
|
||||
json=invalid_config,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
|
||||
# ensure the config has actually been updated
|
||||
response = api.get(f"/api/{test_flake.name}/machines/machine1/config")
|
||||
response = api.get(f"/api/{test_flake_with_core.name}/machines/machine1/config")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == dict(clanImports=[], **invalid_config)
|
||||
|
||||
@@ -99,8 +109,9 @@ def test_configure_machine(api: TestClient, test_flake: FlakeForTest) -> None:
|
||||
|
||||
# set some valid config
|
||||
config2 = dict(
|
||||
clan=dict(
|
||||
jitsi=dict(
|
||||
clan=dict(),
|
||||
services=dict(
|
||||
nginx=dict(
|
||||
enable=True,
|
||||
),
|
||||
),
|
||||
@@ -108,20 +119,20 @@ def test_configure_machine(api: TestClient, test_flake: FlakeForTest) -> None:
|
||||
)
|
||||
|
||||
response = api.put(
|
||||
f"/api/{test_flake.name}/machines/machine1/config",
|
||||
f"/api/{test_flake_with_core.name}/machines/machine1/config",
|
||||
json=config2,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
|
||||
# ensure the config has been applied
|
||||
response = api.get(
|
||||
f"/api/{test_flake.name}/machines/machine1/config",
|
||||
f"/api/{test_flake_with_core.name}/machines/machine1/config",
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert response.json() == dict(clanImports=[], **config2)
|
||||
|
||||
# get the config again
|
||||
response = api.get(f"/api/{test_flake.name}/machines/machine1/config")
|
||||
response = api.get(f"/api/{test_flake_with_core.name}/machines/machine1/config")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"clanImports": [], **config2}
|
||||
|
||||
@@ -129,36 +140,36 @@ def test_configure_machine(api: TestClient, test_flake: FlakeForTest) -> None:
|
||||
# For example, this should not result in the boot.loader.grub.devices being
|
||||
# set twice (eg. merged)
|
||||
response = api.put(
|
||||
f"/api/{test_flake.name}/machines/machine1/config",
|
||||
f"/api/{test_flake_with_core.name}/machines/machine1/config",
|
||||
json=config2,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
|
||||
# ensure the config has been applied
|
||||
response = api.get(
|
||||
f"/api/{test_flake.name}/machines/machine1/config",
|
||||
f"/api/{test_flake_with_core.name}/machines/machine1/config",
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert response.json() == dict(clanImports=[], **config2)
|
||||
|
||||
# verify the machine config evaluates
|
||||
response = api.get(f"/api/{test_flake.name}/machines/machine1/verify")
|
||||
response = api.get(f"/api/{test_flake_with_core.name}/machines/machine1/verify")
|
||||
assert response.status_code == 200
|
||||
|
||||
assert response.json() == {"success": True, "error": None}
|
||||
|
||||
# get the schema with an extra module imported
|
||||
response = api.put(
|
||||
f"/api/{test_flake.name}/machines/machine1/schema",
|
||||
json={"clanImports": ["fake-module"]},
|
||||
f"/api/{test_flake_with_core.name}/schema",
|
||||
json={"clanImports": ["diskLayouts"]},
|
||||
)
|
||||
# expect the result schema to contain the fake-module.fake-flag option
|
||||
# expect the result schema to contain the deltachat option
|
||||
assert response.status_code == 200
|
||||
assert (
|
||||
response.json()["schema"]["properties"]["fake-module"]["properties"][
|
||||
"fake-flag"
|
||||
]["type"]
|
||||
== "boolean"
|
||||
response.json()["schema"]["properties"]["diskLayouts"]["properties"][
|
||||
"singleDiskExt4"
|
||||
]["properties"]["device"]["type"]
|
||||
== "string"
|
||||
)
|
||||
|
||||
# new config importing an extra clanModule (clanModules.fake-module)
|
||||
@@ -174,14 +185,14 @@ def test_configure_machine(api: TestClient, test_flake: FlakeForTest) -> None:
|
||||
|
||||
# set the fake-module.fake-flag option to true
|
||||
response = api.put(
|
||||
f"/api/{test_flake.name}/machines/machine1/config",
|
||||
f"/api/{test_flake_with_core.name}/machines/machine1/config",
|
||||
json=config_with_imports,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
|
||||
# ensure the config has been applied
|
||||
response = api.get(
|
||||
f"/api/{test_flake.name}/machines/machine1/config",
|
||||
f"/api/{test_flake_with_core.name}/machines/machine1/config",
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {
|
||||
@@ -200,14 +211,14 @@ def test_configure_machine(api: TestClient, test_flake: FlakeForTest) -> None:
|
||||
**fs_config,
|
||||
)
|
||||
response = api.put(
|
||||
f"/api/{test_flake.name}/machines/machine1/config",
|
||||
f"/api/{test_flake_with_core.name}/machines/machine1/config",
|
||||
json=config_with_empty_imports,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
|
||||
# ensure the config has been applied
|
||||
response = api.get(
|
||||
f"/api/{test_flake.name}/machines/machine1/config",
|
||||
f"/api/{test_flake_with_core.name}/machines/machine1/config",
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import pytest
|
||||
from fixtures_flakes import FlakeForTest
|
||||
|
||||
from clan_cli.config import machine
|
||||
from clan_cli.config.schema import machine_schema
|
||||
|
||||
|
||||
def test_schema_for_machine(test_flake: FlakeForTest) -> None:
|
||||
schema = machine.schema_for_machine(test_flake.name, "machine1")
|
||||
@pytest.mark.with_core
|
||||
def test_schema_for_machine(test_flake_with_core: FlakeForTest) -> None:
|
||||
schema = machine_schema(test_flake_with_core.name, config={})
|
||||
assert "properties" in schema
|
||||
|
||||
Reference in New Issue
Block a user