test(docker): #5152's tests read rows with SQL and the clock they render against

- The status test imported the plugin's models after the app had mapped
  them ("already defined"); it reads docker_host_status with SQL.
- The swarm-expiry count awaited inside a generator expression.
- The page test's since came from the module's NOW, so |ago said "5m 4s";
  it is built at test time and the assertion checks the minutes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-06 18:45:57 -04:00
co-authored by Claude Opus 5.5
parent bcd0563f39
commit d8bacc7149
2 changed files with 19 additions and 10 deletions
+4 -3
View File
@@ -80,10 +80,11 @@ async def test_a_healthy_board_has_no_attention_card(app):
async def test_a_host_whose_docker_stopped_answering_says_so(app):
now = datetime.now(timezone.utc) # not the module's NOW: |ago reads the clock
down = [{"host_id": "h1", "host_name": "nas", "status": "unavailable",
"detail": "no Docker socket at /var/run/docker.sock", "since": NOW - timedelta(minutes=5)},
"detail": "no Docker socket at /var/run/docker.sock", "since": now - timedelta(minutes=5)},
{"host_id": "h2", "host_name": "web-1", "status": "error",
"detail": "permission denied on /var/run/docker.sock", "since": NOW - timedelta(minutes=1)}]
"detail": "permission denied on /var/run/docker.sock", "since": now - timedelta(minutes=1)}]
async with app.test_request_context("/plugins/docker/rows"):
page = await render_plugin_template(
app, "docker", "docker/rows.html", docker_down=down, attention=[], says=svc.PROBLEM_SAYS,
@@ -92,7 +93,7 @@ async def test_a_host_whose_docker_stopped_answering_says_so(app):
page = re.sub(r">\s+<", "><", " ".join(page.split()))
card = page[page.index("Docker not answering"):page.index("</section>")]
assert '<span class="badge badge-warn">No Docker</span><a href="/hosts/h1">nas</a>' in card
assert "no Docker socket at /var/run/docker.sock · since <time" in card and ">5m ago</time>" in card
assert "no Docker socket at /var/run/docker.sock · since <time" in card and ">5m " in card
assert '<span class="badge badge-crit">Error</span><a href="/hosts/h2">web-1</a>' in card