def test_database_status_fail(self): """test that fetching database handles errors.""" expected = 'WARNING:masu.api.status:Unable to connect to DB: ' with patch('django.db.backends.utils.CursorWrapper') as mock_cursor: mock_cursor = mock_cursor.return_value.__enter__.return_value mock_cursor.execute.side_effect = InterfaceError() with self.assertLogs('masu.api.status', level='INFO') as logger: ApplicationStatus().startup() self.assertIn(expected, logger.output)
def test_close_database__interface_error(self, mocker): conn = MagicMock() conn.close.side_effect = InterfaceError() all_ = mocker.patch("django.db.connections.all") all_.return_value = [conn] worker = get_worker() worker.close_database() assert conn.close.called
def test_create_source_event_db_down(self): """Tests creating a source db record with invalid auth_header.""" test_source_id = 2 test_offset = 3 with patch("sources.storage.Sources.objects") as mock_objects: mock_objects.get.side_effect = InterfaceError("Test exception") with self.assertRaises(InterfaceError): storage.create_source_event(test_source_id, Config.SOURCES_FAKE_HEADER, test_offset)
def test_enqueue_source_delete_db_down(self): """Tests enqueues source_delete with database error.""" test_source_id = 2 test_offset = 3 ocp_obj = Sources(source_id=test_source_id, offset=3, out_of_order_delete=False, pending_delete=False) ocp_obj.save() with patch.object(Sources, "save") as mock_object: mock_object.side_effect = InterfaceError("Error") with self.assertRaises(InterfaceError): storage.enqueue_source_delete(test_source_id, Config.SOURCES_FAKE_HEADER, test_offset)
def test_create_source_event_db_down(self): """Tests creating a source db record with invalid auth_header.""" test_source_id = 2 test_offset = 3 ocp_obj = Sources(source_id=test_source_id, offset=3, out_of_order_delete=True, pending_delete=False) ocp_obj.save() with patch.object(Sources, "delete") as mock_object: mock_object.side_effect = InterfaceError("Error") with self.assertRaises(InterfaceError): storage.create_source_event(test_source_id, Config.SOURCES_FAKE_HEADER, test_offset)
def test_get_source_from_endpoint(self): """Test to source from endpoint id.""" test_source_id = 3 test_endpoint_id = 4 aws_obj = Sources( source_id=test_source_id, auth_header=self.test_header, offset=3, endpoint_id=test_endpoint_id, source_type=Provider.PROVIDER_AWS, name="Test AWS Source", authentication={"role_arn": "arn:test"}, billing_source={"bucket": "test-bucket"}, ) aws_obj.save() response = storage.get_source_from_endpoint(test_endpoint_id) self.assertEquals(response, test_source_id) self.assertEquals( storage.get_source_from_endpoint(test_source_id + 10), None) with patch("sources.storage.Sources.objects") as mock_objects: mock_objects.get.side_effect = InterfaceError("Test exception") with self.assertRaises(InterfaceError): storage.get_source_from_endpoint(test_endpoint_id)
def test_get_source_db_down(self, mock_objects): """Tests creating a source db record with invalid auth_header.""" mock_objects.get.side_effect = InterfaceError("test_exception") test_source_id = 2 with self.assertRaises(InterfaceError): storage.get_source(test_source_id, "error", Mock)
def test_is_known_souce_db_down(self, mock_objects): """Test InterfaceError in is_known_souce.""" mock_objects.get.side_effect = InterfaceError("test_exception") with self.assertRaises(InterfaceError): storage.is_known_source(self.test_source_id)
def test_destroy_source_event_db_down(self): """Tests when destroying a source when DB is down.""" with patch("sources.storage.Sources.objects") as mock_objects: mock_objects.get.side_effect = InterfaceError("Test exception") with self.assertRaises(InterfaceError): storage.destroy_source_event(self.test_source_id)