def test_download_cost_report_exception(self, mock_factory): """Test that function handles a raised exception.""" key = FAKE.word() mock_blob = Mock(last_modified=Mock(date=Mock( return_value=datetime.now()))) name_attr = PropertyMock(return_value=key) type( mock_blob).name = name_attr # kludge to set name attribute on Mock mock_factory.return_value = Mock( spec=AzureClientFactory, cloud_storage_account=Mock(return_value=Mock( spec=BlobServiceClient, get_blob_client=Mock(side_effect=AdalError("test error")), get_container_client=Mock( return_value=Mock(spec=ContainerClient, list_blobs=Mock( return_value=[mock_blob]))), )), ) with self.assertRaises(AzureServiceError): service = AzureService(self.tenant_id, self.client_id, self.client_secret, self.resource_group_name, self.storage_account_name) service.download_cost_export(key=key, container_name=FAKE.word())
def _run_magic(magic, content): if magic == "reload_ext": return None if magic == "config": if "=" in content: return "dummy_setting" return True check.equal(magic, "kql") if "KqlErrorUnk" in content: resp = '{"error": {"code": "UnknownError"}}' raise KqlError(http_response=resp, message=resp) if "KqlErrorWS" in content: resp = '{"error": {"code": "WorkspaceNotFoundError"}}' raise KqlError(http_response=resp, message=resp) if "KqlEngineError" in content: raise KqlEngineError("Test Error") if "AdalErrorUnk" in content: resp = {"error_description": "unknown error"} raise AdalError("Test Error", error_response=resp) if "AdalErrorNR" in content: raise AdalError("Test Error") if "AdalErrorPoll" in content: raise AdalError("Unexpected polling state code_expired") if "AuthenticationError" in content: raise AuthenticationError("Test Error") if content == "--schema": return { "table1": { "field1": int, "field2": str }, "table2": { "field1": int, "field2": str }, } if "query_partial" in content: return KqlResultTest(code=0, partial=True, status="partial") if "query_failed" in content: return KqlResultTest(code=1, partial=False, status="failed") return KqlResultTest(code=0, partial=False, status="success")
def test_get_latest_cost_export_for_path_exception(self, mock_factory): """Test that function handles a raised exception.""" mock_factory.return_value = Mock( spec=AzureClientFactory, cloud_storage_account=Mock(return_value=Mock( spec=BlobServiceClient, get_container_client=Mock(return_value=Mock( spec=ContainerClient, list_blobs=Mock(side_effect=AdalError("test error")))), )), ) with self.assertRaises(AzureServiceError): service = AzureService(self.tenant_id, self.client_id, self.client_secret, self.resource_group_name, self.storage_account_name) service.get_latest_cost_export_for_path(report_path=FAKE.word(), container_name=FAKE.word())