|
15 | 15 | choose_filename, |
16 | 16 | extract_download, |
17 | 17 | filename_from_url, |
| 18 | + is_empty_bambustudioopen_uri, |
18 | 19 | normalize_host, |
| 20 | + main, |
19 | 21 | read_protocol_uri, |
20 | 22 | has_executable_bits, |
21 | 23 | launch_bambu, |
@@ -69,6 +71,69 @@ def test_download_url_rejects_control_characters(self) -> None: |
69 | 71 | ) |
70 | 72 |
|
71 | 73 |
|
| 74 | +class BambuEmptyUriTests(unittest.TestCase): |
| 75 | + def test_detects_empty_bambustudioopen_uri(self) -> None: |
| 76 | + self.assertTrue(is_empty_bambustudioopen_uri("bambustudioopen:///")) |
| 77 | + self.assertTrue(is_empty_bambustudioopen_uri("bambustudioopen://%20%20")) |
| 78 | + self.assertFalse( |
| 79 | + is_empty_bambustudioopen_uri( |
| 80 | + "bambustudioopen://https%3A%2F%2Ffiles.example%2Fmodels%2Fbenchy.3mf" |
| 81 | + ) |
| 82 | + ) |
| 83 | + self.assertFalse(is_empty_bambustudioopen_uri("prusaslicer://open?file=")) |
| 84 | + |
| 85 | + def test_main_ignores_empty_bambustudioopen_uri(self) -> None: |
| 86 | + config = { |
| 87 | + "security": { |
| 88 | + "allowed_extensions": {".3mf"}, |
| 89 | + "allow_plain_http": False, |
| 90 | + "allowed_hosts": [], |
| 91 | + "allow_any_original_host": True, |
| 92 | + }, |
| 93 | + "bambu_studio": {}, |
| 94 | + } |
| 95 | + |
| 96 | + with ( |
| 97 | + patch("slicer_uri_bridge.handler.load_config", return_value=config), |
| 98 | + patch("slicer_uri_bridge.handler.resolve_bambu_command") as resolve_command, |
| 99 | + patch("slicer_uri_bridge.handler.extract_download") as extract, |
| 100 | + patch("slicer_uri_bridge.handler.launch_bambu") as launch, |
| 101 | + ): |
| 102 | + exit_code = main(["bambustudioopen:///"]) |
| 103 | + |
| 104 | + self.assertEqual(exit_code, 0) |
| 105 | + resolve_command.assert_not_called() |
| 106 | + extract.assert_not_called() |
| 107 | + launch.assert_not_called() |
| 108 | + |
| 109 | + |
| 110 | +class MainLoggingTests(unittest.TestCase): |
| 111 | + def test_logs_input_uri_when_download_extraction_fails(self) -> None: |
| 112 | + config = { |
| 113 | + "security": { |
| 114 | + "allowed_extensions": {".3mf"}, |
| 115 | + "allow_plain_http": False, |
| 116 | + "allowed_hosts": [], |
| 117 | + "allow_any_original_host": True, |
| 118 | + } |
| 119 | + } |
| 120 | + |
| 121 | + with ( |
| 122 | + patch("slicer_uri_bridge.handler.load_config", return_value=config), |
| 123 | + patch("slicer_uri_bridge.handler.show_error"), |
| 124 | + self.assertLogs("slicer_uri_bridge", level="ERROR") as captured, |
| 125 | + ): |
| 126 | + exit_code = main(["prusaslicer://open?file=%20%20"]) |
| 127 | + |
| 128 | + self.assertEqual(exit_code, 1) |
| 129 | + self.assertTrue( |
| 130 | + any("Input URI: 'prusaslicer://open?file=%20%20'" in line for line in captured.output) |
| 131 | + ) |
| 132 | + self.assertTrue( |
| 133 | + any("Failed: Invalid prusaslicer URI." in line for line in captured.output) |
| 134 | + ) |
| 135 | + |
| 136 | + |
72 | 137 | class FilenameTests(unittest.TestCase): |
73 | 138 | def test_filename_from_url_prefers_query_name_basename(self) -> None: |
74 | 139 | self.assertEqual( |
|
0 commit comments