import unittest from starlette.routing import Match from module_business.controller.filling_controller import filling_controller from module_business.controller.inbound_controller import inbound_controller from module_business.controller.return_controller import return_controller from module_business.controller.shipment_controller import shipment_controller from module_business.controller.usage_controller import usage_controller class TestScanPathIdentity(unittest.TestCase): def test_scan_paths_preserve_printed_pallet_number_with_slashes(self) -> None: for router in ( inbound_controller, filling_controller, shipment_controller, usage_controller, return_controller, ): route = next(route for route in router.routes if '/scan/' in route.path) # ASGI path 已由HTTP层解码,查询和片段字符不能再被当成URL语法。 path = route.path.split('/scan/')[0] + '/scan/托盘/2026?批#1' with self.subTest(path=path): match, child = route.matches({'type': 'http', 'method': 'GET', 'path': path, 'root_path': ''}) self.assertEqual(match, Match.FULL) self.assertEqual(child['path_params']['qr_token'], '托盘/2026?批#1')