test: port the v1 endpoint and browser tests to v2
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>
This commit is contained in:
1 parent
9d628aa3c8
commit
4b42391a46
15 files changed
+2055
-1
No files matched your search
@@ -0,0 +1,136 @@
|
||||
import pytest
|
||||
|
||||
from helpers import missing
|
||||
|
||||
# Test MACs from v1; no real driver has them
|
||||
ESPNOW_MAC = "aabbccddeeff"
|
||||
WIFI_MAC = "102030405060"
|
||||
WIFI_MAC2 = "102030405061"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def espnow_dev(c):
|
||||
c.delete(f"/devices/{ESPNOW_MAC}")
|
||||
resp = c.post("/devices", json={"name": "pytest-dev", "address": "aa:bb:cc:dd:ee:ff"})
|
||||
assert resp.status_code == 201, resp.text
|
||||
yield resp
|
||||
c.delete(f"/devices/{ESPNOW_MAC}")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def wifi_dev(c):
|
||||
c.delete(f"/devices/{WIFI_MAC}")
|
||||
resp = c.post("/devices", json={"name": "pytest-wifi", "type": "led", "transport": "wifi",
|
||||
"address": "192.168.50.10", "mac": WIFI_MAC})
|
||||
assert resp.status_code == 201, resp.text
|
||||
yield resp
|
||||
c.delete(f"/devices/{WIFI_MAC}")
|
||||
|
||||
|
||||
def test_list(c):
|
||||
resp = c.get("/devices")
|
||||
assert resp.status_code == 200
|
||||
assert isinstance(resp.json(), dict)
|
||||
|
||||
|
||||
@missing("v1 device registry (MAC keys, validation)")
|
||||
def test_create_requires_name(c):
|
||||
assert c.post("/devices", json={}).status_code == 400
|
||||
|
||||
|
||||
@missing("v1 device registry (MAC keys, validation)")
|
||||
def test_create_espnow_keyed_by_mac(espnow_dev):
|
||||
dev = espnow_dev.json()
|
||||
assert list(dev) == [ESPNOW_MAC]
|
||||
rec = dev[ESPNOW_MAC]
|
||||
assert rec["name"] == "pytest-dev"
|
||||
assert rec["id"] == ESPNOW_MAC
|
||||
assert rec["type"] == "led"
|
||||
assert rec["transport"] == "espnow"
|
||||
assert rec["address"] == ESPNOW_MAC
|
||||
|
||||
|
||||
@missing("v1 device registry (MAC keys, validation)")
|
||||
def test_get_espnow_has_no_connection_state(c, espnow_dev):
|
||||
resp = c.get(f"/devices/{ESPNOW_MAC}")
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()["name"] == "pytest-dev"
|
||||
assert resp.json().get("connected") is None
|
||||
assert c.get("/devices").json()[ESPNOW_MAC].get("connected") is None
|
||||
|
||||
|
||||
@missing("v1 device registry (MAC keys, validation)")
|
||||
def test_create_wifi(c, wifi_dev):
|
||||
rec = wifi_dev.json()[WIFI_MAC]
|
||||
assert rec["transport"] == "wifi"
|
||||
assert rec["address"] == "192.168.50.10"
|
||||
assert c.get(f"/devices/{WIFI_MAC}").json().get("connected") is False
|
||||
|
||||
|
||||
@missing("v1 device registry (MAC keys, validation)")
|
||||
def test_create_second_wifi_same_name(c, wifi_dev):
|
||||
resp = c.post("/devices", json={"name": "pytest-wifi", "transport": "wifi",
|
||||
"address": "192.168.50.11", "mac": WIFI_MAC2})
|
||||
assert resp.status_code == 201
|
||||
assert resp.json()[WIFI_MAC2]["name"] == "pytest-wifi"
|
||||
assert c.delete(f"/devices/{WIFI_MAC2}").status_code == 200
|
||||
|
||||
|
||||
@missing("v1 device registry (MAC keys, validation)")
|
||||
def test_create_duplicate_mac(c, wifi_dev):
|
||||
resp = c.post("/devices", json={"name": "pytest-wifi-dupmac", "transport": "wifi",
|
||||
"address": "192.168.50.99", "mac": WIFI_MAC})
|
||||
assert resp.status_code == 409
|
||||
|
||||
|
||||
@missing("v1 device registry (MAC keys, validation)")
|
||||
def test_create_wifi_requires_mac(c):
|
||||
resp = c.post("/devices", json={"name": "no-mac-wifi", "transport": "wifi", "address": "192.168.50.12"})
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
@missing("v1 device registry (MAC keys, validation)")
|
||||
def test_create_rejects_unknown_transport(c):
|
||||
assert c.post("/devices", json={"name": "bad-tr", "transport": "serial"}).status_code == 400
|
||||
|
||||
|
||||
@missing("v1 device registry (MAC keys, validation)")
|
||||
def test_rename_blank(c, espnow_dev):
|
||||
assert c.put(f"/devices/{ESPNOW_MAC}", json={"name": " "}).status_code == 400
|
||||
|
||||
|
||||
@missing("v1 device registry (MAC keys, validation)")
|
||||
def test_rename(c, espnow_dev, wifi_dev):
|
||||
for mac in (ESPNOW_MAC, WIFI_MAC):
|
||||
resp = c.put(f"/devices/{mac}", json={"name": "renamed"})
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()["name"] == "renamed"
|
||||
|
||||
|
||||
@missing("v1 device registry (MAC keys, validation)")
|
||||
def test_cannot_change_mac(c, espnow_dev):
|
||||
assert c.put(f"/devices/{ESPNOW_MAC}", json={"mac": "001122334455"}).status_code == 400
|
||||
|
||||
|
||||
@missing("device identify")
|
||||
def test_identify(c, espnow_dev):
|
||||
resp = c.post(f"/devices/{ESPNOW_MAC}/identify")
|
||||
assert resp.status_code == 200
|
||||
assert resp.json().get("message")
|
||||
|
||||
|
||||
@missing("device identify")
|
||||
def test_identify_unknown(c):
|
||||
assert c.post("/devices/000000000000/identify").status_code == 404
|
||||
|
||||
|
||||
def test_status(c):
|
||||
resp = c.get("/devices/status")
|
||||
assert resp.status_code == 200
|
||||
assert isinstance(resp.json(), dict)
|
||||
|
||||
|
||||
@missing("v1 device registry (MAC keys, validation)")
|
||||
def test_delete(c, espnow_dev):
|
||||
assert c.delete(f"/devices/{ESPNOW_MAC}").status_code == 200
|
||||
assert c.get(f"/devices/{ESPNOW_MAC}").status_code == 404
|
||||
Reference in new issue
Block a user