|
2 | 2 | from django.db import connection
|
3 | 3 | from django.test import override_settings
|
4 | 4 |
|
| 5 | +import simplejson |
5 | 6 | from mock import patch
|
6 | 7 | from rest_framework import status
|
7 | 8 |
|
@@ -280,6 +281,60 @@ def test_tenant_switch_missing_but_api_not_configured(self, add_mock):
|
280 | 281 | self._test_update(self.fm_user, activity, {'status': 'assigned'})
|
281 | 282 | add_mock.assert_not_called()
|
282 | 283 |
|
| 284 | + @override_settings(ETOOLS_OFFLINE_API='http://example.com/b/api/remote/blueprint/', SENTRY_DSN='https://test.dns') |
| 285 | + @patch('sentry_sdk.api.Hub.current.capture_exception') |
| 286 | + @patch('etools.applications.field_monitoring.data_collection.offline.synchronizer.OfflineCollect.add') |
| 287 | + def test_add_offline_backend_unavailable(self, add_mock, capture_event_mock): |
| 288 | + def communication_failure(*args, **kwargs): |
| 289 | + return 502, simplejson.loads( |
| 290 | + '<html>\r\n<head><title>502 Bad Gateway</title></head>\r\n<body bgcolor="white">\r\n<center>' |
| 291 | + '<h1>502 Bad Gateway</h1></center>\r\n<hr><center>nginx/1.13.12</center>\r\n</body>\r\n</html>\r\n' |
| 292 | + ) |
| 293 | + |
| 294 | + add_mock.side_effect = communication_failure |
| 295 | + |
| 296 | + activity = MonitoringActivityFactory(status='pre_assigned', partners=[PartnerFactory()]) |
| 297 | + ActivityQuestionFactory(monitoring_activity=activity, is_enabled=True, question__methods=[MethodFactory()]) |
| 298 | + |
| 299 | + self._test_update(self.fm_user, activity, {'status': 'assigned'}) |
| 300 | + capture_event_mock.assert_called() |
| 301 | + |
| 302 | + @override_settings(ETOOLS_OFFLINE_API='http://example.com/b/api/remote/blueprint/', SENTRY_DSN='https://test.dns') |
| 303 | + @patch('sentry_sdk.api.Hub.current.capture_exception') |
| 304 | + @patch('etools.applications.field_monitoring.data_collection.offline.synchronizer.OfflineCollect.update') |
| 305 | + def test_update_offline_backend_unavailable(self, update_mock, capture_event_mock): |
| 306 | + def communication_failure(*args, **kwargs): |
| 307 | + return 502, simplejson.loads( |
| 308 | + '<html>\r\n<head><title>502 Bad Gateway</title></head>\r\n<body bgcolor="white">\r\n<center>' |
| 309 | + '<h1>502 Bad Gateway</h1></center>\r\n<hr><center>nginx/1.13.12</center>\r\n</body>\r\n</html>\r\n' |
| 310 | + ) |
| 311 | + |
| 312 | + update_mock.side_effect = communication_failure |
| 313 | + |
| 314 | + activity = MonitoringActivityFactory(status='data_collection', partners=[PartnerFactory()]) |
| 315 | + ActivityQuestionFactory(monitoring_activity=activity, is_enabled=True, question__methods=[MethodFactory()]) |
| 316 | + |
| 317 | + activity.team_members.remove(activity.team_members.first()) |
| 318 | + capture_event_mock.assert_called() |
| 319 | + |
| 320 | + @override_settings(ETOOLS_OFFLINE_API='http://example.com/b/api/remote/blueprint/', SENTRY_DSN='https://test.dns') |
| 321 | + @patch('sentry_sdk.api.Hub.current.capture_exception') |
| 322 | + @patch('etools.applications.field_monitoring.data_collection.offline.synchronizer.OfflineCollect.delete') |
| 323 | + def test_delete_offline_backend_unavailable(self, delete_mock, capture_event_mock): |
| 324 | + def communication_failure(*args, **kwargs): |
| 325 | + return 502, simplejson.loads( |
| 326 | + '<html>\r\n<head><title>502 Bad Gateway</title></head>\r\n<body bgcolor="white">\r\n<center>' |
| 327 | + '<h1>502 Bad Gateway</h1></center>\r\n<hr><center>nginx/1.13.12</center>\r\n</body>\r\n</html>\r\n' |
| 328 | + ) |
| 329 | + |
| 330 | + delete_mock.side_effect = communication_failure |
| 331 | + |
| 332 | + activity = MonitoringActivityFactory(status='data_collection', partners=[PartnerFactory()]) |
| 333 | + ActivityQuestionFactory(monitoring_activity=activity, is_enabled=True, question__methods=[MethodFactory()]) |
| 334 | + |
| 335 | + self._test_update(self.fm_user, activity, {'status': 'cancelled', 'cancel_reason': 'For testing purposes'}) |
| 336 | + capture_event_mock.assert_called() |
| 337 | + |
283 | 338 |
|
284 | 339 | class MonitoringActivityOfflineValuesTestCase(APIViewSetTestCase, BaseTenantTestCase):
|
285 | 340 | base_view = 'field_monitoring_data_collection:activities'
|
|
0 commit comments