am-freescan/scripts/verify_task_draft_materials.py

39 lines
3.3 KiB
Python
Raw Normal View History

"""HTTP regression for task registration and comparison-only documents. Never runs a device."""
import datetime,json,sys
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1]
sys.path.insert(0,str(ROOT/'scripts'))
from verify_cmvr_native import Client,TargetReadOnlyDb
def run():
prefix='SCANQA-TASK-DRAFT-'+datetime.datetime.now().strftime('%Y%m%d-%H%M%S')
c=Client().login();db=TargetReadOnlyDb(c)
baseline=db.select('SELECT owner_key,resource_key,status FROM lab_resource_occupation WHERE deleted=0 ORDER BY resource_key')
report={'prefix':prefix,'checks':[],'createdTasks':[],'deviceCommands':0}
path=ROOT/'.local/task-draft-materials-http.json'
def save():path.write_text(json.dumps(report,ensure_ascii=False,indent=2),encoding='utf-8')
def check(name,valid):
if not valid:raise AssertionError(name)
report['checks'].append(name);save()
task=c.request('POST','/admin-api/lab/dimension/create',body={'taskName':prefix,'externalTaskNo':prefix,'sampleCode':prefix,'sampleName':prefix+' Sample','quantity':2,'requirement':'QA: documents are required before comparison, not before scanning'})['data']
report['createdTasks'].append(str(task));save()
detail=c.request('GET','/admin-api/lab/dimension/get',query={'taskId':task})['data']
check('without a scan plan the task remains a pending scan draft',detail['task']['processType']=='SCAN_ONLY' and detail['task']['status']=='PENDING_CONFIRM')
check('requested quantity generates two independent units',len(detail['units'])==2 and len({str(u['id']) for u in detail['units']})==2)
check('no CAD, PDF or PLY is needed to create the task',not detail['files'])
scan=c.request('GET','/admin-api/lab/scan-task/get',query={'taskId':task})['data']
check('first scan plan is deferred until preparation',not scan['config']['selectedTestCaseId'] and not scan['config'].get('versionId') and not scan.get('flowData'))
check('physical confirmations are not fabricated',not scan['config']['sampleReceived'] and not scan['config']['fixtureConfirmed'])
precheck=c.request('POST','/admin-api/lab/scan-task/precheck',body={'taskId':task})['data']
codes={i['code'] for i in precheck['items']}
check('scan precheck has no CAD/PDF/comparison prerequisite',not codes.intersection({'MODEL','DRAWING','SCAN_CLOUD','COMPARISON_INPUTS'}))
check('unconfigured draft still cannot run',not precheck['passed'])
unit=detail['units'][0]['id']
sync=c.request('POST','/admin-api/lab/dimension/sync-scan',query={'taskId':task,'unitId':unit})['data']
check('unscanned units do not acquire fabricated cloud files',sync['status']=='WAITING_SCAN' and not sync['changed'])
prepare=c.request('POST','/admin-api/lab/dimension/prepare',body={'taskId':task,'unitId':unit,'revision':0},expected=None)
check('comparison continues to require actual input files',prepare.get('code') not in (0,200))
check('no physical executions created',not db.select('SELECT id FROM lab_execution WHERE task_id=%s AND deleted=0',(task,)))
check('resource occupations unchanged',baseline==db.select('SELECT owner_key,resource_key,status FROM lab_resource_occupation WHERE deleted=0 ORDER BY resource_key'))
db.close();report['success']=True;save();print(json.dumps({'prefix':prefix,'taskId':str(task),'passed':len(report['checks']),'deviceCommands':0}))
if __name__=='__main__':run()