printers: resolve installer vendor via the model + fix batch download base URL
Two fixes for the printer install-batch on prod data: 1. Vendor was read only from the printer's direct vendorid, which the legacy import never sets (it sets the model; legacy resolved vendor through the model). Every prod printer came back vendor "unknown", so all fell into the manual group and the universal PrinterInstaller.exe block never emitted. Now resolve vendor via the model's vendor when the printer has no direct one, as the classic installprinter.asp did. 2. Harden the download base URL. Behind IIS the app sees http on a loopback port and url_root drops the /shopdb mount, giving a broken download URL when site_base_url is unset. Fall back to https + the forwarded Host + script_root. Test: a printer with no vendorid but an HP/Xerox model now groups universal.
This commit is contained in:
@@ -72,6 +72,33 @@ def test_install_batch_groups_universal_specific_and_manual(
|
||||
assert 'c350navi.zip' not in bat # never handed to the runner
|
||||
|
||||
|
||||
def test_install_batch_resolves_vendor_via_model(
|
||||
client, db, auth_headers, printer_assettype):
|
||||
"""A printer with no direct vendorid still groups as universal when its
|
||||
MODEL's vendor is HP/Xerox (the import sets the model, not the printer's
|
||||
vendorid) - the bug that dumped every prod printer into 'manual (unknown)'."""
|
||||
from shopdb.core.models import Vendor, Model
|
||||
|
||||
xerox = Vendor(vendor='Xerox')
|
||||
db.session.add(xerox)
|
||||
db.session.commit()
|
||||
model = Model(modelnumber='VersaLink C7125', vendorid=xerox.vendorid)
|
||||
db.session.add(model)
|
||||
db.session.commit()
|
||||
|
||||
# No vendorid on the printer - only the model ties it to Xerox.
|
||||
pid = _make_printer(client, auth_headers, assetnumber='SpoolsInspection-Xerox',
|
||||
hostname='wjprn07', modelnumberid=model.modelnumberid)
|
||||
|
||||
resp = client.get('/api/printers/install-batch?printerids=%d' % pid,
|
||||
headers=auth_headers)
|
||||
assert resp.status_code == 200
|
||||
bat = resp.get_data(as_text=True)
|
||||
assert 'PrinterInstaller.exe' in bat
|
||||
assert '/PRINTER="SpoolsInspection-Xerox"' in bat
|
||||
assert 'MANUAL' not in bat
|
||||
|
||||
|
||||
def test_install_batch_requires_ids(client, db, auth_headers, printer_assettype):
|
||||
resp = client.get('/api/printers/install-batch', headers=auth_headers)
|
||||
assert resp.status_code == 400
|
||||
|
||||
Reference in New Issue
Block a user