66 lines
2.2 KiB
Python
66 lines
2.2 KiB
Python
"""Architectuurcontrole voor apps met expliciete platformmetadata."""
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "server-up"))
|
|
|
|
from conftest import login
|
|
|
|
|
|
def _arm_app(env):
|
|
from core import git
|
|
d = git.cache_dir("server-up") / "apps" / "alleen-arm64"
|
|
(d / "files").mkdir(parents=True, exist_ok=True)
|
|
(d / "template.json").write_text(json.dumps({
|
|
"kind": "compose",
|
|
"metadata": {
|
|
"name": "Alleen ARM64",
|
|
"description": "Testapp",
|
|
"tags": ["test"],
|
|
"architectures": ["arm64"],
|
|
"architecture_note": "Gebruik een 64-bits OS.",
|
|
},
|
|
"variables": [{"title": "Algemeen", "items": [{
|
|
"name": "service_name", "type": "str", "title": "Naam",
|
|
"default": "alleen-arm64", "required": True,
|
|
}]}],
|
|
}), encoding="utf-8")
|
|
(d / "files" / "compose.yaml").write_text(
|
|
"services:\n << service_name >>:\n image: nginx\n", encoding="utf-8")
|
|
return d
|
|
|
|
|
|
def test_preview_meldt_architectuur_mismatch(client, env, monkeypatch):
|
|
csrf = login(client)
|
|
_arm_app(env)
|
|
import app as app_module
|
|
monkeypatch.setattr(app_module.boilerplates.platform, "machine", lambda: "armv7l")
|
|
|
|
d = client.post("/api/store/preview", json={
|
|
"stack": "alleen-arm64", "repo_id": "server-up",
|
|
}, headers={"X-CSRF-Token": csrf}).get_json()
|
|
|
|
assert d["ok"] is True
|
|
assert d["compatibility"]["architecture"] == "arm/v7"
|
|
assert d["compatibility"]["supported"] is False
|
|
assert "64-bits OS" in d["compatibility"]["reason"]
|
|
|
|
|
|
def test_installatie_weigert_aantoonbaar_verkeerde_architectuur(
|
|
client, env, monkeypatch):
|
|
csrf = login(client)
|
|
_arm_app(env)
|
|
import app as app_module
|
|
monkeypatch.setattr(app_module.boilerplates.platform, "machine", lambda: "armv7l")
|
|
|
|
r = client.post("/api/store/install", json={
|
|
"stack": "alleen-arm64",
|
|
"repo_id": "server-up",
|
|
"instance": "past-niet",
|
|
"values": {"service_name": "past-niet"},
|
|
}, headers={"X-CSRF-Token": csrf})
|
|
|
|
assert r.status_code == 400
|
|
assert r.get_json()["compatibility"]["supported"] is False
|
|
assert not (env["lib"] / "past-niet").exists()
|