CLI: --plugin-path (-P)
(mock_request, tmpdir)
| 2181 | |
| 2182 | @mock.patch("requests.request") |
| 2183 | def test_apprise_cli_plugin_loading(mock_request, tmpdir): |
| 2184 | """ |
| 2185 | CLI: --plugin-path (-P) |
| 2186 | |
| 2187 | """ |
| 2188 | # Prepare Mock |
| 2189 | mock_request.return_value = requests.Request() |
| 2190 | mock_request.return_value.status_code = requests.codes.ok |
| 2191 | |
| 2192 | runner = CliRunner() |
| 2193 | |
| 2194 | # Clear our working variables so they don't obstruct the next test |
| 2195 | # This simulates an actual call from the CLI. Unfortunately through |
| 2196 | # testing were occupying the same memory space so our singleton's |
| 2197 | # have already been populated |
| 2198 | N_MGR._paths_previously_scanned.clear() |
| 2199 | N_MGR._custom_module_map.clear() |
| 2200 | |
| 2201 | # Test a path that has no files to load in it |
| 2202 | result = runner.invoke( |
| 2203 | cli.main, |
| 2204 | [ |
| 2205 | "--plugin-path", |
| 2206 | join(str(tmpdir), "invalid_path"), |
| 2207 | "-b", |
| 2208 | "test\nbody", |
| 2209 | "json://localhost", |
| 2210 | ], |
| 2211 | ) |
| 2212 | # The path is silently loaded but fails... it's okay because the |
| 2213 | # notification we're choosing to notify does exist |
| 2214 | assert result.exit_code == 0 |
| 2215 | |
| 2216 | # Directories that don't exist passed in by the CLI aren't even scanned |
| 2217 | assert len(N_MGR._paths_previously_scanned) == 0 |
| 2218 | assert len(N_MGR._custom_module_map) == 0 |
| 2219 | |
| 2220 | # Test our current existing path that has no entries in it |
| 2221 | result = runner.invoke( |
| 2222 | cli.main, |
| 2223 | [ |
| 2224 | "--plugin-path", |
| 2225 | str(tmpdir.mkdir("empty")), |
| 2226 | "-b", |
| 2227 | "test\nbody", |
| 2228 | "json://localhost", |
| 2229 | ], |
| 2230 | ) |
| 2231 | # The path is silently loaded but fails... it's okay because the |
| 2232 | # notification we're choosing to notify does exist |
| 2233 | assert result.exit_code == 0 |
| 2234 | assert len(N_MGR._paths_previously_scanned) == 1 |
| 2235 | assert join(str(tmpdir), "empty") in N_MGR._paths_previously_scanned |
| 2236 | |
| 2237 | # However there was nothing to load |
| 2238 | assert len(N_MGR._custom_module_map) == 0 |
| 2239 | |
| 2240 | # Clear our working variables so they don't obstruct the next test |