Dashboard cards: rebuild deployable dists

This commit is contained in:
2026-08-11 14:31:24 -04:00
parent 0ed8be75d9
commit 3b37603691
14 changed files with 507 additions and 62 deletions

View File

@@ -118,3 +118,81 @@ def test_the_widget_uses_the_new_contract(app):
assert widget['render'] == 'exceptions'
assert widget['permission'] == 'computers.view'
assert widget['empty'] == 'hide'
# =============================================================================
# Machine numbers claimed by two PCs - a fault, unless the devices are modelled
# =============================================================================
SHAREDURL = '/api/computers/dashboard/sharedmachines'
def _machine(db, assetnumber):
mt = AssetType.query.filter_by(assettype='machine').first()
if not mt:
mt = AssetType(assettype='machine')
db.session.add(mt)
db.session.flush()
asset = Asset(assetnumber=assetnumber, assettypeid=mt.assettypeid,
statusid=1)
db.session.add(asset)
db.session.commit()
return asset
def _controls(db, pchostname, machineasset, label='collector:machine'):
from shopdb.core.models import AssetRelationship, RelationshipType
controls = RelationshipType.query.filter_by(relationshiptype='controls').first()
if not controls:
controls = RelationshipType(relationshiptype='controls', isdirectional=True)
db.session.add(controls)
db.session.flush()
comp = _pc(db, pchostname)
db.session.add(AssetRelationship(
sourceassetid=comp.assetid, targetassetid=machineasset.assetid,
relationshiptypeid=controls.relationshiptypeid, label=label,
isactive=True))
db.session.commit()
return comp
def test_one_pc_per_machine_is_not_a_finding(client, db, auth_headers):
machine = _machine(db, '3015')
_controls(db, 'ONLYPC', machine)
assert client.get(SHAREDURL, headers=auth_headers).get_json()['data'] == []
def test_two_pcs_on_one_number_is_reported(client, db, auth_headers):
machine = _machine(db, '2026')
_controls(db, 'PCONE', machine)
_controls(db, 'PCTWO', machine)
[row] = client.get(SHAREDURL, headers=auth_headers).get_json()['data']
assert row['machinenumber'] == '2026'
assert row['pccount'] == 2
assert 'PCONE' in row['pcs'] and 'PCTWO' in row['pcs']
def test_a_modelled_shared_number_is_not_a_finding(client, db, auth_headers):
"""Part markers legitimately share an operation number. Modelled correctly,
each device is its own asset filed partof the operation - so the operation
has child assets, and that is what tells a real fault from correct data."""
from shopdb.core.models import AssetRelationship, RelationshipType
operation = _machine(db, '0615')
_controls(db, 'MARKERPCA', operation)
_controls(db, 'MARKERPCB', operation)
partof = RelationshipType(relationshiptype='partof', isdirectional=True)
db.session.add(partof)
db.session.flush()
marker = _machine(db, 'MARKERPCA-PARTMARKER')
db.session.add(AssetRelationship(
sourceassetid=marker.assetid, targetassetid=operation.assetid,
relationshiptypeid=partof.relationshiptypeid,
label='collector:partmarker', isactive=True))
db.session.commit()
assert client.get(SHAREDURL, headers=auth_headers).get_json()['data'] == []
def test_shared_machines_is_permission_gated(client, db, member_headers):
assert client.get(SHAREDURL, headers=member_headers).status_code == 403