"""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()