HTTP tests against a running controller (make test-api HOST=ip). They snapshot every collection through /db and restore it afterwards. v1 behaviour v2 does not have yet is marked as a strict xfail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
74 lines
2.3 KiB
Python
74 lines
2.3 KiB
Python
from helpers import missing, unique
|
|
|
|
|
|
@missing("/patterns/definitions")
|
|
def test_definitions(c):
|
|
resp = c.get("/patterns/definitions")
|
|
assert resp.status_code == 200
|
|
assert isinstance(resp.json(), dict)
|
|
|
|
|
|
@missing("driver pattern files in /patterns")
|
|
def test_list_includes_driver_patterns(c):
|
|
resp = c.get("/patterns")
|
|
assert resp.status_code == 200
|
|
assert "blink" in resp.json()
|
|
|
|
|
|
@missing("v1 pattern create ({name, data})")
|
|
def test_crud(c):
|
|
pid = unique("pytest_pattern").replace("-", "_")
|
|
resp = c.post("/patterns", json={"name": pid, "data": {"foo": "bar"}})
|
|
assert resp.status_code == 201
|
|
assert resp.json()["foo"] == "bar"
|
|
resp = c.get(f"/patterns/{pid}")
|
|
assert resp.status_code == 200
|
|
assert resp.json()["foo"] == "bar"
|
|
resp = c.put(f"/patterns/{pid}", json={"baz": 1})
|
|
assert resp.status_code == 200
|
|
assert resp.json()["baz"] == 1
|
|
assert c.delete(f"/patterns/{pid}").status_code == 200
|
|
|
|
|
|
@missing("/patterns/ota/file")
|
|
def test_ota_file(c):
|
|
resp = c.get("/patterns/ota/file/blink.py")
|
|
assert resp.status_code == 200
|
|
assert resp.headers["Content-Type"].startswith("text/plain")
|
|
assert "class" in resp.text
|
|
|
|
|
|
@missing("/patterns/ota/file")
|
|
def test_ota_file_rejects_builtin(c):
|
|
# on/off are built into the driver firmware, not OTA files
|
|
resp = c.get("/patterns/ota/file/on.py")
|
|
assert resp.status_code == 400
|
|
assert "error" in resp.json()
|
|
|
|
|
|
@missing("/patterns/ota/manifest")
|
|
def test_ota_manifest(c):
|
|
resp = c.get("/patterns/ota/manifest")
|
|
assert resp.status_code == 200
|
|
names = [f["name"] for f in resp.json()["files"]]
|
|
assert "blink.py" in names
|
|
|
|
|
|
@missing("/patterns/<name>/send")
|
|
def test_send_rejects_builtin(c):
|
|
resp = c.post("/patterns/off/send", json={})
|
|
assert resp.status_code == 400
|
|
assert "error" in resp.json()
|
|
|
|
|
|
@missing("/patterns/upload")
|
|
def test_upload_rejects_builtin(c):
|
|
resp = c.post("/patterns/upload", json={"name": "on.py", "code": "class On:\n def run(self, p):\n yield\n"})
|
|
assert resp.status_code == 400
|
|
|
|
|
|
@missing("/patterns/driver")
|
|
def test_driver_rejects_builtin(c):
|
|
resp = c.post("/patterns/driver", json={"name": "off", "code": "class Off:\n def run(self, p):\n yield\n"})
|
|
assert resp.status_code == 400
|