|
5 | 5 | import pytest |
6 | 6 | from azure.core.credentials import AccessToken |
7 | 7 | from starlette.testclient import TestClient |
8 | | - |
| 8 | +from allen_powerplatform_client.exceptions import NotFoundException |
9 | 9 | from aind_dataverse_service_server.route import get_access_token |
10 | 10 |
|
11 | 11 |
|
@@ -69,6 +69,51 @@ def test_get_table_200_response( |
69 | 69 | assert isinstance(response.json(), list) |
70 | 70 | assert len(response.json()) == 2 |
71 | 71 |
|
| 72 | + @patch( |
| 73 | + "aind_dataverse_service_server.route." |
| 74 | + "allen_powerplatform_client.DefaultApi" |
| 75 | + ) |
| 76 | + @patch( |
| 77 | + "aind_dataverse_service_server.route." |
| 78 | + "allen_powerplatform_client.ApiClient" |
| 79 | + ) |
| 80 | + @patch("aind_dataverse_service_server.route.get_access_token") |
| 81 | + def test_get_table_exception_response( |
| 82 | + self, |
| 83 | + mock_get_token: MagicMock, |
| 84 | + mock_api_client: MagicMock, |
| 85 | + mock_default_api: MagicMock, |
| 86 | + client: TestClient, |
| 87 | + mock_table_data, |
| 88 | + ): |
| 89 | + """Tests error is properly handled during table data retrieval""" |
| 90 | + |
| 91 | + mock_get_token.return_value = "mock_token" |
| 92 | + mock_instance = MagicMock() |
| 93 | + |
| 94 | + # Create a proper NotFoundException instance with required attributes |
| 95 | + mock_http_resp = MagicMock() |
| 96 | + mock_http_resp.status = 404 |
| 97 | + mock_http_resp.reason = "Not Found" |
| 98 | + not_found_exception = NotFoundException( |
| 99 | + http_resp=mock_http_resp, |
| 100 | + body="", |
| 101 | + data=None, |
| 102 | + ) |
| 103 | + not_found_exception.status = 404 |
| 104 | + not_found_exception.reason = "Not Found" |
| 105 | + |
| 106 | + mock_instance.get_table.side_effect = not_found_exception |
| 107 | + mock_default_api.return_value = mock_instance |
| 108 | + mock_api_client.return_value.__enter__.return_value = MagicMock() |
| 109 | + |
| 110 | + response = client.get("/tables/non_existent_table") |
| 111 | + assert 404 == response.status_code |
| 112 | + assert ( |
| 113 | + "Error fetching non_existent_table" |
| 114 | + in response.json()["detail"] |
| 115 | + ) |
| 116 | + |
72 | 117 | @patch( |
73 | 118 | "aind_dataverse_service_server.route." |
74 | 119 | "allen_powerplatform_client.DefaultApi" |
|
0 commit comments