"""Authenticated scanner parameter boundaries; never submits a device command.""" import json from pathlib import Path from verify_cmvr_native import Client, TargetReadOnlyDb, require def run(): client = Client().login() db = TargetReadOnlyDb(client) cases = [ ('defaults', {'pointDistance': .7, 'brightness': 17}, 200), ('lower bounds', {'pointDistance': .05, 'brightness': 0}, 200), ('upper bounds', {'pointDistance': 10, 'brightness': 17}, 200), ('brightness only', {'brightness': 8}, 200), ('distance only', {'pointDistance': .2}, 200), ('distance too small', {'pointDistance': .049}, 400), ('distance too large', {'pointDistance': 10.001}, 400), ('distance string', {'pointDistance': '0.2'}, 400), ('brightness zero', {'brightness': 0}, 200), ('brightness negative', {'brightness': -1}, 400), ('brightness too large', {'brightness': 18}, 400), ('fractional brightness', {'brightness': 8.5}, 400), ('brightness string', {'brightness': '8'}, 400), ('empty object', {}, 400) ] before = db.select('SELECT COUNT(*) n FROM lab_scanner_command')[0]['n'] results = [] try: for name, body, expected in cases: response = client.native('POST', '/scanner/validate', { 'operation': 'PARAMETERS', 'requestJson': json.dumps(body) }, expected=None) require(response.get('code') == expected, name + ': unexpected validation code ' + str(response.get('code'))) results.append({'name': name, 'code': expected, 'passed': True}) require(db.select('SELECT COUNT(*) n FROM lab_scanner_command')[0]['n'] == before, 'Validation created a scanner command') finally: db.close() return {'passed': True, 'checks': results, 'deviceCommands': 0} if __name__ == '__main__': result = run() path = Path(__file__).resolve().parents[1] / '.local/optimization-audit-parameters.json' path.write_text(json.dumps(result, indent=2), encoding='utf-8') print(json.dumps({'passed': True, 'checks': len(result['checks']), 'deviceCommands': 0}))