PUT /panels/ carries a version and refuses a stale one with 409
The Panels dialog re-reads the list on 409. A panels.json without a version reads as 0.
This commit is contained in:
@@ -11,7 +11,11 @@ DASHBOARDS = f"{settings.API_V1_STR}/dashboards"
|
||||
|
||||
|
||||
def _panels(client: TestClient, headers: dict[str, str], config: dict) -> None:
|
||||
response = client.put(f"{PREFIX}/", headers=headers, json=config)
|
||||
"""Replace the panels, based on whatever is stored now."""
|
||||
version = client.get(f"{PREFIX}/", headers=headers).json()["version"]
|
||||
response = client.put(
|
||||
f"{PREFIX}/", headers=headers, json={**config, "version": version}
|
||||
)
|
||||
assert response.status_code == 200, response.text
|
||||
|
||||
|
||||
@@ -130,6 +134,39 @@ def test_duplicate_panel_is_refused(
|
||||
assert response.status_code == 422
|
||||
|
||||
|
||||
def test_a_stale_save_is_refused(
|
||||
client: TestClient, superuser_token_headers: dict[str, str]
|
||||
) -> None:
|
||||
"""Two clients writing back the whole list must not drop each other's panels."""
|
||||
read = client.get(f"{PREFIX}/", headers=superuser_token_headers).json()
|
||||
base = read["version"]
|
||||
|
||||
saved = client.put(
|
||||
f"{PREFIX}/",
|
||||
headers=superuser_token_headers,
|
||||
json={"panels": [*read["panels"], {"id": "mine"}], "version": base},
|
||||
)
|
||||
assert saved.status_code == 200, saved.text
|
||||
assert saved.json()["version"] == base + 1
|
||||
|
||||
stale = client.put(
|
||||
f"{PREFIX}/",
|
||||
headers=superuser_token_headers,
|
||||
json={"panels": [*read["panels"], {"id": "theirs"}], "version": base},
|
||||
)
|
||||
assert stale.status_code == 409
|
||||
assert stale.json()["detail"]["current_version"] == base + 1
|
||||
|
||||
ids = [
|
||||
p["id"]
|
||||
for p in client.get(f"{PREFIX}/", headers=superuser_token_headers).json()[
|
||||
"panels"
|
||||
]
|
||||
]
|
||||
assert "mine" in ids
|
||||
assert "theirs" not in ids
|
||||
|
||||
|
||||
def test_polling_needs_the_secret(client: TestClient) -> None:
|
||||
started = client.post(f"{PREFIX}/pair").json()
|
||||
assert len(started["code"]) == 6
|
||||
|
||||
Reference in New Issue
Block a user