From 36970676d582be1f4ad50134b285bf8b7c10c5d9 Mon Sep 17 00:00:00 2001 From: Caio Saldanha Date: Mon, 24 Jul 2023 07:06:18 -0700 Subject: [PATCH] [FormRecognizer] Removed IgnoreServiceError attributes and overrode IsEnvironmentReady method --- .../DocumentAnalysisClientLiveTests.cs | 1 - .../OperationsLiveTests.cs | 1 - .../DocumentModelAdministrationLiveTests.cs | 1 - .../MiscellaneousOperationsLiveTests.cs | 1 - .../RecognizeCustomFormsLiveTests.cs | 1 - .../FormTrainingClientLiveTests.cs | 1 - .../DocumentAnalysisTestEnvironment.cs | 21 +++++++++++++++++++ .../tests/samples/DocumentAnalysisSamples.cs | 1 - .../samples/V3.1/FormRecognizerSamples.cs | 1 - 9 files changed, 21 insertions(+), 8 deletions(-) diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/DocumentAnalysisClient/DocumentAnalysisClientLiveTests.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/DocumentAnalysisClient/DocumentAnalysisClientLiveTests.cs index 4d3feeec45ec6..aabb4b112db35 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/DocumentAnalysisClient/DocumentAnalysisClientLiveTests.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/DocumentAnalysisClient/DocumentAnalysisClientLiveTests.cs @@ -20,7 +20,6 @@ namespace Azure.AI.FormRecognizer.DocumentAnalysis.Tests /// These tests have a dependency on live Azure services and may incur costs for the associated /// Azure subscription. /// - [IgnoreServiceError(400, "InvalidRequest", Message = "Content is not accessible: Invalid data URL", Reason = "https://github.com/Azure/azure-sdk-for-net/issues/28923")] public class DocumentAnalysisClientLiveTests : DocumentAnalysisLiveTestBase { /// diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/DocumentAnalysisModels/OperationsLiveTests.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/DocumentAnalysisModels/OperationsLiveTests.cs index da746cd3181d0..a95f411d39999 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/DocumentAnalysisModels/OperationsLiveTests.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/DocumentAnalysisModels/OperationsLiveTests.cs @@ -16,7 +16,6 @@ namespace Azure.AI.FormRecognizer.DocumentAnalysis.Tests /// These tests have a dependency on live Azure services and may incur costs for the associated /// Azure subscription. /// - [IgnoreServiceError(400, "InvalidRequest", Message = "Content is not accessible: Invalid data URL", Reason = "https://github.com/Azure/azure-sdk-for-net/issues/28923")] public class OperationsLiveTests : DocumentAnalysisLiveTestBase { /// diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/DocumentModelAdministrationClient/DocumentModelAdministrationLiveTests.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/DocumentModelAdministrationClient/DocumentModelAdministrationLiveTests.cs index 6fbcd627cc4a2..72a6b1ea19284 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/DocumentModelAdministrationClient/DocumentModelAdministrationLiveTests.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/DocumentModelAdministrationClient/DocumentModelAdministrationLiveTests.cs @@ -17,7 +17,6 @@ namespace Azure.AI.FormRecognizer.DocumentAnalysis.Tests /// These tests have a dependency on live Azure services and may incur costs for the associated /// Azure subscription. /// - [IgnoreServiceError(400, "InvalidRequest", Message = "Content is not accessible: Invalid data URL", Reason = "https://github.com/Azure/azure-sdk-for-net/issues/28923")] public class DocumentModelAdministrationLiveTests : DocumentAnalysisLiveTestBase { private static readonly DocumentBuildMode[] s_buildDocumentModelTestCases = new[] diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/DocumentModelAdministrationClient/MiscellaneousOperationsLiveTests.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/DocumentModelAdministrationClient/MiscellaneousOperationsLiveTests.cs index dc2e32e3023fa..95672478dc05a 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/DocumentModelAdministrationClient/MiscellaneousOperationsLiveTests.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/DocumentModelAdministrationClient/MiscellaneousOperationsLiveTests.cs @@ -17,7 +17,6 @@ namespace Azure.AI.FormRecognizer.DocumentAnalysis.Tests /// These tests have a dependency on live Azure services and may incur costs for the associated /// Azure subscription. /// - [IgnoreServiceError(400, "InvalidRequest", Message = "Content is not accessible: Invalid data URL", Reason = "https://github.com/Azure/azure-sdk-for-net/issues/28923")] public class MiscellaneousOperationsLiveTests : DocumentAnalysisLiveTestBase { private readonly IReadOnlyDictionary _testingTags = new Dictionary() diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/FormRecognizerClient/RecognizeCustomFormsLiveTests.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/FormRecognizerClient/RecognizeCustomFormsLiveTests.cs index 073dc3ce650c9..a92e07eecb390 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/FormRecognizerClient/RecognizeCustomFormsLiveTests.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/FormRecognizerClient/RecognizeCustomFormsLiveTests.cs @@ -20,7 +20,6 @@ namespace Azure.AI.FormRecognizer.Tests [ClientTestFixture( FormRecognizerClientOptions.ServiceVersion.V2_0, FormRecognizerClientOptions.ServiceVersion.V2_1)] - [IgnoreServiceError(200, "3014", Message = "Generic error during training.", Reason = "https://github.com/Azure/azure-sdk-for-net/issues/28913")] public class RecognizeCustomFormsLiveTests : FormRecognizerLiveTestBase { public RecognizeCustomFormsLiveTests(bool isAsync, FormRecognizerClientOptions.ServiceVersion serviceVersion) diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/FormTrainingClient/FormTrainingClientLiveTests.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/FormTrainingClient/FormTrainingClientLiveTests.cs index ac71c02062992..bd850f72ef120 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/FormTrainingClient/FormTrainingClientLiveTests.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/FormTrainingClient/FormTrainingClientLiveTests.cs @@ -19,7 +19,6 @@ namespace Azure.AI.FormRecognizer.Tests /// These tests have a dependency on live Azure services and may incur costs for the associated /// Azure subscription. /// - [IgnoreServiceError(200, "3014", Message = "Generic error during training.", Reason = "https://github.com/Azure/azure-sdk-for-net/issues/28913")] public class FormTrainingClientLiveTests : FormRecognizerLiveTestBase { /// diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/Infrastructure/DocumentAnalysisTestEnvironment.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/Infrastructure/DocumentAnalysisTestEnvironment.cs index daf78a409ebfa..9ff699b63b146 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/Infrastructure/DocumentAnalysisTestEnvironment.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/Infrastructure/DocumentAnalysisTestEnvironment.cs @@ -4,6 +4,7 @@ using System; using System.IO; using System.Reflection; +using System.Threading.Tasks; using Azure.Core.TestFramework; namespace Azure.AI.FormRecognizer.DocumentAnalysis.Tests @@ -73,6 +74,26 @@ public class DocumentAnalysisTestEnvironment : TestEnvironment /// public string ClassifierTrainingSasUrl => GetRecordedVariable("CLASSIFIER_BLOB_CONTAINER_SAS_URL", options => options.IsSecret(SanitizedSasUrl)); + protected override async ValueTask IsEnvironmentReadyAsync() + { + var endpoint = new Uri(Endpoint); + var keyCredential = new AzureKeyCredential(ApiKey); + var keyCredentialClient = new DocumentModelAdministrationClient(endpoint, keyCredential); + var tokenCredentialClient = new DocumentModelAdministrationClient(endpoint, Credential); + + try + { + await keyCredentialClient.GetResourceDetailsAsync(); + await tokenCredentialClient.GetResourceDetailsAsync(); + } + catch (RequestFailedException e) when (e.Status == 401) + { + return false; + } + + return true; + } + /// /// Creates an absolute path to a file contained in the local test assets folder. /// diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/samples/DocumentAnalysisSamples.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/samples/DocumentAnalysisSamples.cs index 7a1a235e6c740..586cd0467914d 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/samples/DocumentAnalysisSamples.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/samples/DocumentAnalysisSamples.cs @@ -8,7 +8,6 @@ namespace Azure.AI.FormRecognizer.DocumentAnalysis.Samples { [LiveOnly] [AsyncOnly] // Ensure that each sample will only run once. - [IgnoreServiceError(400, "InvalidRequest", Message = "Content is not accessible: Invalid data URL", Reason = "https://github.com/Azure/azure-sdk-for-net/issues/28923")] public partial class DocumentAnalysisSamples : RecordedTestBase { public DocumentAnalysisSamples(bool isAsync) : base(isAsync, RecordedTestMode.Live) diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/samples/V3.1/FormRecognizerSamples.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/samples/V3.1/FormRecognizerSamples.cs index 1f9af7f3f9c99..8dde4a184b7d4 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/samples/V3.1/FormRecognizerSamples.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/samples/V3.1/FormRecognizerSamples.cs @@ -8,7 +8,6 @@ namespace Azure.AI.FormRecognizer.Samples { [LiveOnly] [AsyncOnly] // Ensure that each sample will only run once. - [IgnoreServiceError(200, "3014", Message = "Generic error during training.", Reason = "https://github.com/Azure/azure-sdk-for-net/issues/28913")] public partial class FormRecognizerSamples : RecordedTestBase { public FormRecognizerSamples(bool isAsync) : base(isAsync, RecordedTestMode.Live)