|
2 | 2 | import uuid |
3 | 3 |
|
4 | 4 | import pytest |
| 5 | +from azure.servicebus.exceptions import ServiceBusQuotaExceededError |
5 | 6 |
|
6 | 7 | from bulk_data_service.checker import checker_run |
7 | 8 | from helpers.data_helpers import ( |
@@ -199,6 +200,47 @@ def test_update_dataset_registration_details(get_and_clear_up_context, field, or |
199 | 200 | assert datasets_in_bds[dataset_id][field] == expected |
200 | 201 |
|
201 | 202 |
|
| 203 | +def test_update_dataset_mq_message_send_doesnt_crash_on_error(monkeypatch, get_and_clear_up_context): # noqa: F811 |
| 204 | + |
| 205 | + context = get_and_clear_up_context |
| 206 | + |
| 207 | + class FailingTopicSender: |
| 208 | + def send_messages(self, *args, **kwargs): |
| 209 | + raise ServiceBusQuotaExceededError( |
| 210 | + message="Test simulated service bus send failure", |
| 211 | + ) |
| 212 | + |
| 213 | + def close(self): |
| 214 | + return None |
| 215 | + |
| 216 | + class FakeServiceBusClient: |
| 217 | + def get_topic_sender(self, *args, **kwargs): |
| 218 | + return FailingTopicSender() |
| 219 | + |
| 220 | + def close(self): |
| 221 | + return None |
| 222 | + |
| 223 | + class FakeServiceFactory: |
| 224 | + def get_service_bus_client(self, *args, **kwargs): |
| 225 | + return FakeServiceBusClient() |
| 226 | + |
| 227 | + def get_suitecrm_client(self): |
| 228 | + raise NotImplementedError |
| 229 | + |
| 230 | + monkeypatch.setattr(context, "_service_factory", FakeServiceFactory()) |
| 231 | + |
| 232 | + dataset_id = uuid.UUID("c8a40aa5-9f31-4bcf-a36f-51c1fc2cc159") |
| 233 | + |
| 234 | + context["DATA_REGISTRY_BASE_URL"] = "http://localhost:3000/ckan-registration/datasets-01-1-dataset" |
| 235 | + datasets_in_bds = {} |
| 236 | + checker_run(context, datasets_in_bds) |
| 237 | + |
| 238 | + context.logger.error.assert_called_once() |
| 239 | + assert context.logger.error.call_args.args[0].startswith( |
| 240 | + "Dataset check result message could not be sent to the IATI MQ" |
| 241 | + ) |
| 242 | + |
| 243 | + |
202 | 244 | def test_dataset_download_404s_then_successful(get_and_clear_up_context): # noqa: F811 |
203 | 245 |
|
204 | 246 | context = get_and_clear_up_context |
|
0 commit comments