|
1 | | -from unittest import mock |
2 | 1 | from unittest.mock import MagicMock |
3 | 2 |
|
4 | 3 | import pytest |
5 | 4 | from backports.entry_points_selectable import entry_points |
6 | 5 | from pytest_mock import MockerFixture |
7 | 6 |
|
8 | | -from murfey.server.feedback import feedback_callback |
9 | | - |
10 | 7 | feedback_callback_params_matrix = ( |
11 | 8 | # Murfey workflows currently present in pyproject.toml |
12 | 9 | ("atlas_update",), |
@@ -37,27 +34,27 @@ def test_feedback_callback( |
37 | 34 | # Unpack test params |
38 | 35 | (entry_point_name,) = test_params |
39 | 36 |
|
40 | | - # Mock the Murfey database creation in the main body of the module |
41 | | - mock_get_security_config = mocker.patch( |
42 | | - "murfey.server.feedback.get_security_config" |
43 | | - ) |
| 37 | + # Patch the functions used to generate the module-level variables |
| 38 | + mock_get_security_config = mocker.patch("murfey.util.config.get_security_config") |
44 | 39 | mock_get_security_config.return_value = MagicMock() |
45 | | - mock_url = mocker.patch("murfey.server.feedback.url") |
46 | | - mock_url.return_value = mock.sentinel |
47 | | - mock_create_engine = mocker.patch("murfey.server.feedback.create_engine") |
| 40 | + mock_url = mocker.patch("murfey.server.murfey_db.url") |
| 41 | + mock_url.return_value = MagicMock() |
| 42 | + mock_create_engine = mocker.patch("sqlmodel.create_engine") |
48 | 43 | mock_create_engine.return_value = MagicMock() |
49 | 44 | mock_murfey_db = MagicMock() |
50 | | - mock_sql_session = mocker.patch("murfey.server.feedback.Session") |
| 45 | + mock_sql_session = mocker.patch("sqlmodel.Session") |
51 | 46 | mock_sql_session.return_value = mock_murfey_db |
52 | 47 |
|
53 | 48 | # Load the entry point and patch the executable it calls |
54 | 49 | eps = list(entry_points().select(group="murfey.workflows", name=entry_point_name)) |
55 | 50 | assert len(eps) == 1 # Entry point should be present and unique |
56 | 51 | mock_function = mocker.patch(eps[0].value.replace(":", ".")) |
57 | 52 |
|
58 | | - header = {"dummy": "dummy"} |
59 | | - message = {"register": entry_point_name} |
| 53 | + # Initialise after mocking |
| 54 | + from murfey.server.feedback import feedback_callback |
60 | 55 |
|
61 | 56 | # Run the function and check that it calls the entry point correctly |
| 57 | + header = {"dummy": "dummy"} |
| 58 | + message = {"register": entry_point_name} |
62 | 59 | feedback_callback(header, message, mock_murfey_db) |
63 | 60 | mock_function.assert_called_once_with(message=message, murfey_db=mock_murfey_db) |
0 commit comments