Declarative subordinate devices + shared-machine check

This commit is contained in:
2026-08-11 11:14:51 -04:00
parent 321d0a3799
commit 5c33b06688
5 changed files with 280 additions and 53 deletions

View File

@@ -1046,3 +1046,59 @@ def test_a_marker_is_never_filed_under_its_own_pc(
assert comp.assetid not in targets, 'marker filed under its own PC'
assert any("own asset number" in w
for w in r.get_json()['data']['warnings'])
# =============================================================================
# The subordinate-device map: adding a device type is configuration, not code
# =============================================================================
def test_a_site_can_add_a_device_type_without_a_code_change(
client, db, collector_key, computer_assettype, operation_0615):
"""The point of the map. A site with two marking lasers on one operation
number needs the same treatment part markers got; before this it needed an
edit to the plugin."""
import json
from shopdb.core.models import Setting, Asset
db.session.add(Setting(
key='subordinatedevice_site-laser',
value=json.dumps({'assettype': 'machine', 'typename': 'Marking Laser',
'description': 'Site laser', 'suffix': 'LASER',
'partof': True, 'label': 'collector:partmarker'}),
category='pctypemapping'))
db.session.commit()
client.post('/api/collector/computers',
json={'hostname': 'LASERPC1', 'machinenumber': '0615',
'pctype': 'site-laser'},
headers={'X-API-Key': collector_key})
device = Asset.query.filter_by(assetnumber='LASERPC1-LASER').first()
assert device is not None
assert device.machine.machinetype.machinetype == 'Marking Laser'
def test_a_malformed_override_does_not_break_the_collector(
client, db, collector_key, computer_assettype, operation_0615):
"""A bad setting must not stop a bay reporting its inventory."""
from shopdb.core.models import Setting
db.session.add(Setting(key='subordinatedevice_gea-shopfloor-partmarker',
value='{not json', category='pctypemapping'))
db.session.commit()
r = client.post('/api/collector/computers', json=_marker('MARKERPC9'),
headers={'X-API-Key': collector_key})
assert r.status_code == 200, r.get_json()
def test_the_metrology_map_still_answers_through_the_shim(app):
"""filters.py and the older tests read metrology_tool_for. Unifying the two
maps must not change what it returns."""
with app.app_context():
from plugins.computers.pctypemap import metrology_tool_for
assert metrology_tool_for('gea-shopfloor-cmm') == (
'CMM', 'Coordinate measuring machine')
# A machine-typed device is not a measuring tool.
assert metrology_tool_for('gea-shopfloor-partmarker') is None
assert metrology_tool_for('gea-shopfloor-collections') is None