|
| 1 | +import pytest |
| 2 | + |
| 3 | +from murfey.util.api import url_path_for |
| 4 | + |
| 5 | +url_path_test_matrix: tuple[tuple[str, str, dict[str, str | int], str], ...] = ( |
| 6 | + # Router name | Function name | kwargs | Expected URL |
| 7 | + ( |
| 8 | + "instrument_server.api.router", |
| 9 | + "health", |
| 10 | + {}, |
| 11 | + "/health", |
| 12 | + ), |
| 13 | + ( |
| 14 | + "instrument_server.api.router", |
| 15 | + "stop_multigrid_watcher", |
| 16 | + {"session_id": 0, "label": "some_label"}, |
| 17 | + "/sessions/0/multigrid_watcher/some_label", |
| 18 | + ), |
| 19 | + ( |
| 20 | + "api.hub.router", |
| 21 | + "get_instrument_image", |
| 22 | + {"instrument_name": "test"}, |
| 23 | + "/instrument/test/image", |
| 24 | + ), |
| 25 | + ( |
| 26 | + "api.instrument.router", |
| 27 | + "check_if_session_is_active", |
| 28 | + { |
| 29 | + "instrument_name": "test", |
| 30 | + "session_id": 0, |
| 31 | + }, |
| 32 | + "/instrument_server/instruments/test/sessions/0/active", |
| 33 | + ), |
| 34 | +) |
| 35 | + |
| 36 | + |
| 37 | +@pytest.mark.parametrize("test_params", url_path_test_matrix) |
| 38 | +def test_url_path_for(test_params: tuple[str, str, dict[str, str | int], str]): |
| 39 | + # Unpack test params |
| 40 | + router_name, function_name, kwargs, expected_url_path = test_params |
| 41 | + assert ( |
| 42 | + url_path_for(router_name=router_name, function_name=function_name, **kwargs) |
| 43 | + == expected_url_path |
| 44 | + ) |
0 commit comments