Files
security-alert-center/backend/tests/test_hosts.py
T

27 lines
727 B
Python

"""Hosts list API."""
from datetime import datetime, timezone
from app.models import Host
def test_hosts_search_by_display_name(client, db_session, jwt_headers):
h = Host(
hostname="pc-01",
display_name="UNMS Kalina",
os_family="linux",
product="ssh-monitor",
last_seen_at=datetime.now(timezone.utc),
)
db_session.add(h)
db_session.commit()
r = client.get("/api/v1/hosts?hostname=UNMS", headers=jwt_headers)
assert r.status_code == 200
body = r.json()
assert body["total"] == 1
assert body["items"][0]["display_name"] == "UNMS Kalina"
r2 = client.get("/api/v1/hosts?hostname=nomatch", headers=jwt_headers)
assert r2.json()["total"] == 0