Search results open the record they found; plugin scaffolder emits a prunable frontend

This commit is contained in:
2026-08-24 14:06:14 -04:00
parent 0398c55fb5
commit ead9fd6b56
9 changed files with 312 additions and 203 deletions

View File

@@ -199,3 +199,70 @@ def test_a_machine_is_found_by_its_maintenance_reference(client, taggedmachine):
type - a field the UI collects and search could not find."""
rows = [r for r in search(client, 'ZZMAINT888') if r['title'] == 'ZZMACH01']
assert rows, 'a maintenance reference matched nothing'
# --- a search result must land on the record, not its list -------------------
#
# A result carries an id, so sending the reader to the plugin's list page makes
# them find by hand the row search had already identified. Both cases below
# shipped that way: the id was in the payload and the URL ignored it.
@pytest.fixture
def noticerow(db):
"""One notification with a distinctive body and its own type."""
from plugins.notifications.models import Notification, NotificationType
notice = NotificationType(typename='Notice', typecolor='#17a2b8',
isactive=True)
db.session.add(notice)
db.session.flush()
row = Notification(
notificationtypeid=notice.notificationtypeid,
notification='ZZNOTICE7788 press brake down for repair',
ticketnumber='INC7788',
isactive=True,
)
db.session.add(row)
db.session.commit()
return row.notificationid
def test_a_notice_result_links_to_the_notice(client, noticerow):
"""Clicking a NOTICE opens that notification, not /notifications.
`/notifications/<id>` is the `notification-detail` route; the list page
cannot show which of its rows the search matched.
"""
rows = [r for r in search(client, 'ZZNOTICE7788')
if r['type'] == 'notification']
assert len(rows) == 1
assert rows[0]['id'] == noticerow
assert rows[0]['url'] == f'/notifications/{noticerow}'
def test_a_notice_found_by_ticket_number_links_the_same_way(client, noticerow):
"""The ticket number is the strongest match and must land as precisely."""
rows = [r for r in search(client, 'INC7788')
if r['type'] == 'notification']
assert len(rows) == 1
assert rows[0]['url'] == f'/notifications/{noticerow}'
@pytest.fixture
def subnetrow(db):
"""A subnet an IP search can fall inside."""
from plugins.network.models import Subnet
row = Subnet(cidr='10.77.88.0/24', name='ZZ Test subnet', isactive=True)
db.session.add(row)
db.session.commit()
return row.subnetid
def test_an_ip_search_links_to_the_matched_subnet(client, subnetrow):
"""Searching an IP already picked WHICH subnet; land on it.
The detail route is `/networks/<id>` (plural) - `/network` is the hub.
"""
rows = [r for r in search(client, '10.77.88.42') if r['type'] == 'subnet']
assert len(rows) == 1
assert rows[0]['id'] == subnetrow
assert rows[0]['url'] == f'/networks/{subnetrow}'