完善扫描流式预览、成果归档与PLY/STL查看、补扫历史、执行步骤及日志展示,支持局域网访问和改名节点的原始组件识别。修复试运行终止后的占用释放及未采集时重复暂停SDK的问题,增加终止中交互与回归验证。 验证:后端1114项通过、18项既有跳过;前端109项通过,类型检查及构建通过;Python脚本54项通过;模拟扫描设备7组试运行/终止接口回归通过。
90 lines
4.9 KiB
Python
90 lines
4.9 KiB
Python
"""The scanner fixture must exercise the same live stream used by the UI."""
|
|
import unittest
|
|
import json
|
|
import tempfile
|
|
import time
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
import urllib.error
|
|
import urllib.request
|
|
from verify_scanner_workflow import Supplier,ScannerVerifier,ScanOnlyVerifier
|
|
|
|
|
|
class ScannerStreamFixtureTest(unittest.TestCase):
|
|
def setUp(self):
|
|
self.supplier=Supplier();self.supplier.start()
|
|
self.base='http://127.0.0.1:'+str(self.supplier.port)
|
|
|
|
def tearDown(self):
|
|
self.supplier.close()
|
|
|
|
def test_stream_rejects_missing_bearer(self):
|
|
with self.assertRaises(urllib.error.HTTPError) as failure:
|
|
urllib.request.urlopen(self.base+'/api/v1/preview/stream',timeout=3)
|
|
self.assertEqual(failure.exception.code,401)
|
|
|
|
def test_redundant_sdk_pause_can_fail_while_active_acquisition_stops_normally(self):
|
|
self.supplier.fail_redundant_stop=True
|
|
headers={'Authorization':'Bearer '+self.supplier.key,'Content-Type':'application/json'}
|
|
def stop():
|
|
request=urllib.request.Request(self.base+'/api/v1/scan/stop',data=b'{}',headers=headers)
|
|
with urllib.request.urlopen(request,timeout=3) as response:accepted=json.loads(response.read())
|
|
with urllib.request.urlopen(urllib.request.Request(self.base+accepted['statusUrl'],headers=headers),timeout=3) as response:return json.loads(response.read())
|
|
self.assertEqual(stop()['state'],'failed')
|
|
self.supplier.scanning=True
|
|
self.assertEqual(stop()['state'],'succeeded');self.assertFalse(self.supplier.scanning)
|
|
|
|
def test_project_creation_remains_busy_until_delayed_sdk_task_finishes(self):
|
|
self.supplier.project_delay_seconds=.2
|
|
headers={'Authorization':'Bearer '+self.supplier.key,'Content-Type':'application/json'}
|
|
request=urllib.request.Request(self.base+'/api/v1/projects',data=b'{"mode":"laser"}',headers=headers)
|
|
with urllib.request.urlopen(request,timeout=3) as response:
|
|
self.assertEqual(response.status,202);accepted=json.loads(response.read())
|
|
def get(path):
|
|
with urllib.request.urlopen(urllib.request.Request(self.base+path,headers=headers),timeout=3) as response:return json.loads(response.read())
|
|
self.assertTrue(get('/api/v1/status')['busy'])
|
|
self.assertEqual(get(accepted['statusUrl'])['state'],'running')
|
|
deadline=time.monotonic()+2
|
|
while time.monotonic()<deadline and get(accepted['statusUrl'])['state']=='running':time.sleep(.02)
|
|
result=get(accepted['statusUrl']);self.assertEqual(result['state'],'succeeded')
|
|
status=get('/api/v1/status');self.assertFalse(status['busy']);self.assertEqual(status['projectId'],result['result']['projectId'])
|
|
|
|
def test_stream_delivers_frames_without_holding_device_lock(self):
|
|
headers={'Authorization':'Bearer '+self.supplier.key}
|
|
with urllib.request.urlopen(urllib.request.Request(self.base+'/api/v1/preview/stream',headers=headers),timeout=3) as response:
|
|
self.assertIn('multipart/x-mixed-replace',response.headers['Content-Type'])
|
|
sequences=[]
|
|
for _ in range(2):
|
|
self.assertEqual(response.readline(),b'--frame\r\n')
|
|
fields={}
|
|
while True:
|
|
line=response.readline()
|
|
if line==b'\r\n':break
|
|
self.assertTrue(line)
|
|
key,value=line.decode().split(':',1);fields[key.lower()]=value.strip()
|
|
self.assertEqual(response.read(int(fields['content-length'])),self.supplier.jpeg)
|
|
self.assertEqual(response.read(2),b'\r\n')
|
|
sequences.append(int(fields['x-frame-sequence']))
|
|
self.assertLess(sequences[0],sequences[1])
|
|
with urllib.request.urlopen(urllib.request.Request(self.base+'/api/v1/status',headers=headers),timeout=3) as status:
|
|
self.assertEqual(status.status,200)
|
|
|
|
|
|
class ScannerReportIsolationTest(unittest.TestCase):
|
|
def test_explicit_report_path_does_not_overwrite_other_run(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
original=Path(directory)/'original.json'
|
|
original.write_text('retained previous verification',encoding='utf-8')
|
|
destination=Path(directory)/'supplement.json'
|
|
def initialize(verifier):verifier.report={'checks':[]}
|
|
with patch.object(ScanOnlyVerifier,'__init__',initialize):
|
|
verifier=ScannerVerifier('E2E-REPORT-ISOLATION',None,report_path=destination)
|
|
with patch('builtins.print'):
|
|
verifier.check('isolated progress')
|
|
self.assertEqual(original.read_text(encoding='utf-8'),'retained previous verification')
|
|
self.assertEqual(json.loads(destination.read_text(encoding='utf-8'))['checks'],
|
|
[{'name':'isolated progress','passed':True}])
|
|
|
|
|
|
if __name__=='__main__':unittest.main()
|