From f693d721b264f22626b491d22bebe1cc2bdc0d7b Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Mon, 7 Jun 2021 21:52:10 -0400 Subject: [PATCH] fix stats for analyze and healthcare --- .../azure/ai/textanalytics/_policies.py | 8 +- ...est_analyze.test_disable_service_logs.yaml | 245 +++++++++++++++++- .../tests/test_analyze.py | 19 +- .../tests/test_analyze_async.py | 22 +- .../tests/test_analyze_healthcare.py | 11 +- .../tests/test_analyze_healthcare_async.py | 11 +- .../cognitiveservices_testcase.py | 6 +- 7 files changed, 302 insertions(+), 20 deletions(-) diff --git a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_policies.py b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_policies.py index 0db101c7f079..d03249808f28 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_policies.py +++ b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_policies.py @@ -7,20 +7,26 @@ from azure.core.pipeline.policies import ContentDecodePolicy from azure.core.pipeline.policies import SansIOHTTPPolicy from ._models import TextDocumentBatchStatistics +from ._lro import _FINISHED class TextAnalyticsResponseHookPolicy(SansIOHTTPPolicy): def __init__(self, **kwargs): self._response_callback = kwargs.get("raw_response_hook") + self._is_lro = None super(TextAnalyticsResponseHookPolicy, self).__init__() def on_request(self, request): self._response_callback = request.context.options.pop("raw_response_hook", self._response_callback) def on_response(self, request, response): - + if self._is_lro is None: + # determine LRO based off of initial response. If 202, we say it's an LRO + self._is_lro = response.http_response.status_code == 202 if self._response_callback: data = ContentDecodePolicy.deserialize_from_http_generics(response.http_response) + if self._is_lro and (not data or data.get("status") not in _FINISHED): + return if data: statistics = data.get("statistics", None) model_version = data.get("modelVersion", None) diff --git a/sdk/textanalytics/azure-ai-textanalytics/tests/recordings/test_analyze.test_disable_service_logs.yaml b/sdk/textanalytics/azure-ai-textanalytics/tests/recordings/test_analyze.test_disable_service_logs.yaml index c8261a7586fc..f445bdb237a6 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/tests/recordings/test_analyze.test_disable_service_logs.yaml +++ b/sdk/textanalytics/azure-ai-textanalytics/tests/recordings/test_analyze.test_disable_service_logs.yaml @@ -21,7 +21,7 @@ interactions: Content-Type: - application/json User-Agent: - - azsdk-python-ai-textanalytics/5.1.0b7 Python/3.9.1 (macOS-10.16-x86_64-i386-64bit) + - azsdk-python-ai-textanalytics/5.1.0b8 Python/3.9.1 (macOS-10.16-x86_64-i386-64bit) method: POST uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.5/analyze response: @@ -29,11 +29,11 @@ interactions: string: '' headers: apim-request-id: - - 2aca33d0-c4c8-4a05-bae1-cb78525a6e7f + - 5d323600-976b-499d-b100-65017f5a9031 date: - - Tue, 18 May 2021 18:25:21 GMT + - Tue, 08 Jun 2021 01:31:27 GMT operation-location: - - https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.5/analyze/jobs/d64ff7b6-4882-4694-ba8a-7055d50e5faf + - https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.5/analyze/jobs/5d783e81-0585-4d59-b361-7eb148b39377 strict-transport-security: - max-age=31536000; includeSubDomains; preload transfer-encoding: @@ -41,7 +41,7 @@ interactions: x-content-type-options: - nosniff x-envoy-upstream-service-time: - - '230' + - '7789' status: code: 202 message: Accepted @@ -55,21 +55,21 @@ interactions: Connection: - keep-alive User-Agent: - - azsdk-python-ai-textanalytics/5.1.0b7 Python/3.9.1 (macOS-10.16-x86_64-i386-64bit) + - azsdk-python-ai-textanalytics/5.1.0b8 Python/3.9.1 (macOS-10.16-x86_64-i386-64bit) method: GET - uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.5/analyze/jobs/d64ff7b6-4882-4694-ba8a-7055d50e5faf + uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.5/analyze/jobs/5d783e81-0585-4d59-b361-7eb148b39377 response: body: - string: '{"jobId":"d64ff7b6-4882-4694-ba8a-7055d50e5faf","lastUpdateDateTime":"2021-05-18T18:25:24Z","createdDateTime":"2021-05-18T18:25:21Z","expirationDateTime":"2021-05-19T18:25:21Z","status":"running","errors":[],"displayName":"NA","tasks":{"details":{"name":"NA","lastUpdateDateTime":"2021-05-18T18:25:24Z"},"completed":1,"failed":0,"inProgress":4,"total":5,"entityLinkingTasks":[{"lastUpdateDateTime":"2021-05-18T18:25:22.822091Z","name":"NA","state":"succeeded","results":{"documents":[{"id":"0","entities":[{"name":"Test + string: '{"jobId":"5d783e81-0585-4d59-b361-7eb148b39377","lastUpdateDateTime":"2021-06-08T01:31:30Z","createdDateTime":"2021-06-08T01:31:19Z","expirationDateTime":"2021-06-09T01:31:19Z","status":"running","errors":[],"displayName":"NA","tasks":{"details":{"name":"NA","lastUpdateDateTime":"2021-06-08T01:31:30Z"},"completed":1,"failed":0,"inProgress":4,"total":5,"entityLinkingTasks":[{"lastUpdateDateTime":"2021-06-08T01:31:30.1194597Z","name":"NA","state":"succeeded","results":{"documents":[{"id":"0","entities":[{"name":"Test (assessment)","matches":[{"text":"Test","offset":0,"length":4,"confidenceScore":0.04}],"language":"en","id":"Test (assessment)","url":"https://en.wikipedia.org/wiki/Test_(assessment)","dataSource":"Wikipedia"}],"warnings":[]}],"errors":[],"modelVersion":"2020-02-01"}}]}}' headers: apim-request-id: - - 5f754806-ec40-4b7d-b75b-b26551a82046 + - b6330ac5-ec6c-491a-8a60-b528ce1c5633 content-type: - application/json; charset=utf-8 date: - - Tue, 18 May 2021 18:25:26 GMT + - Tue, 08 Jun 2021 01:31:34 GMT strict-transport-security: - max-age=31536000; includeSubDomains; preload transfer-encoding: @@ -77,7 +77,230 @@ interactions: x-content-type-options: - nosniff x-envoy-upstream-service-time: - - '31' + - '2619' + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - azsdk-python-ai-textanalytics/5.1.0b8 Python/3.9.1 (macOS-10.16-x86_64-i386-64bit) + method: GET + uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.5/analyze/jobs/5d783e81-0585-4d59-b361-7eb148b39377 + response: + body: + string: '{"jobId":"5d783e81-0585-4d59-b361-7eb148b39377","lastUpdateDateTime":"2021-06-08T01:31:30Z","createdDateTime":"2021-06-08T01:31:19Z","expirationDateTime":"2021-06-09T01:31:19Z","status":"running","errors":[],"displayName":"NA","tasks":{"details":{"name":"NA","lastUpdateDateTime":"2021-06-08T01:31:30Z"},"completed":1,"failed":0,"inProgress":4,"total":5,"entityLinkingTasks":[{"lastUpdateDateTime":"2021-06-08T01:31:30.1194597Z","name":"NA","state":"succeeded","results":{"documents":[{"id":"0","entities":[{"name":"Test + (assessment)","matches":[{"text":"Test","offset":0,"length":4,"confidenceScore":0.04}],"language":"en","id":"Test + (assessment)","url":"https://en.wikipedia.org/wiki/Test_(assessment)","dataSource":"Wikipedia"}],"warnings":[]}],"errors":[],"modelVersion":"2020-02-01"}}]}}' + headers: + apim-request-id: + - db60a717-9a67-423f-8a66-791a5929a75a + content-type: + - application/json; charset=utf-8 + date: + - Tue, 08 Jun 2021 01:31:39 GMT + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + transfer-encoding: + - chunked + x-content-type-options: + - nosniff + x-envoy-upstream-service-time: + - '19' + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - azsdk-python-ai-textanalytics/5.1.0b8 Python/3.9.1 (macOS-10.16-x86_64-i386-64bit) + method: GET + uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.5/analyze/jobs/5d783e81-0585-4d59-b361-7eb148b39377 + response: + body: + string: '{"jobId":"5d783e81-0585-4d59-b361-7eb148b39377","lastUpdateDateTime":"2021-06-08T01:31:40Z","createdDateTime":"2021-06-08T01:31:19Z","expirationDateTime":"2021-06-09T01:31:19Z","status":"running","errors":[],"displayName":"NA","tasks":{"details":{"name":"NA","lastUpdateDateTime":"2021-06-08T01:31:40Z"},"completed":2,"failed":0,"inProgress":3,"total":5,"entityRecognitionTasks":[{"lastUpdateDateTime":"2021-06-08T01:31:40.3875777Z","name":"NA","state":"succeeded","results":{"documents":[{"id":"0","entities":[{"text":"logging","category":"Skill","offset":9,"length":7,"confidenceScore":0.61}],"warnings":[]}],"errors":[],"modelVersion":"2021-06-01"}}],"entityLinkingTasks":[{"lastUpdateDateTime":"2021-06-08T01:31:30.1194597Z","name":"NA","state":"succeeded","results":{"documents":[{"id":"0","entities":[{"name":"Test + (assessment)","matches":[{"text":"Test","offset":0,"length":4,"confidenceScore":0.04}],"language":"en","id":"Test + (assessment)","url":"https://en.wikipedia.org/wiki/Test_(assessment)","dataSource":"Wikipedia"}],"warnings":[]}],"errors":[],"modelVersion":"2020-02-01"}}]}}' + headers: + apim-request-id: + - 3ba36732-3651-44c0-a13f-dcd9a55a7409 + content-type: + - application/json; charset=utf-8 + date: + - Tue, 08 Jun 2021 01:31:50 GMT + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + transfer-encoding: + - chunked + x-content-type-options: + - nosniff + x-envoy-upstream-service-time: + - '5059' + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - azsdk-python-ai-textanalytics/5.1.0b8 Python/3.9.1 (macOS-10.16-x86_64-i386-64bit) + method: GET + uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.5/analyze/jobs/5d783e81-0585-4d59-b361-7eb148b39377 + response: + body: + string: '{"jobId":"5d783e81-0585-4d59-b361-7eb148b39377","lastUpdateDateTime":"2021-06-08T01:31:45Z","createdDateTime":"2021-06-08T01:31:19Z","expirationDateTime":"2021-06-09T01:31:19Z","status":"running","errors":[],"displayName":"NA","tasks":{"details":{"name":"NA","lastUpdateDateTime":"2021-06-08T01:31:45Z"},"completed":3,"failed":0,"inProgress":2,"total":5,"entityRecognitionTasks":[{"lastUpdateDateTime":"2021-06-08T01:31:40.3875777Z","name":"NA","state":"succeeded","results":{"documents":[{"id":"0","entities":[{"text":"logging","category":"Skill","offset":9,"length":7,"confidenceScore":0.61}],"warnings":[]}],"errors":[],"modelVersion":"2021-06-01"}}],"entityLinkingTasks":[{"lastUpdateDateTime":"2021-06-08T01:31:30.1194597Z","name":"NA","state":"succeeded","results":{"documents":[{"id":"0","entities":[{"name":"Test + (assessment)","matches":[{"text":"Test","offset":0,"length":4,"confidenceScore":0.04}],"language":"en","id":"Test + (assessment)","url":"https://en.wikipedia.org/wiki/Test_(assessment)","dataSource":"Wikipedia"}],"warnings":[]}],"errors":[],"modelVersion":"2020-02-01"}}],"entityRecognitionPiiTasks":[{"lastUpdateDateTime":"2021-06-08T01:31:45.5629681Z","name":"NA","state":"succeeded","results":{"documents":[{"redactedText":"Test + for logging disable","id":"0","entities":[],"warnings":[]}],"errors":[],"modelVersion":"2021-01-15"}}]}}' + headers: + apim-request-id: + - 70c029ea-1e47-46f2-8ab2-76138764b923 + content-type: + - application/json; charset=utf-8 + date: + - Tue, 08 Jun 2021 01:31:55 GMT + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + transfer-encoding: + - chunked + x-content-type-options: + - nosniff + x-envoy-upstream-service-time: + - '50' + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - azsdk-python-ai-textanalytics/5.1.0b8 Python/3.9.1 (macOS-10.16-x86_64-i386-64bit) + method: GET + uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.5/analyze/jobs/5d783e81-0585-4d59-b361-7eb148b39377 + response: + body: + string: '{"jobId":"5d783e81-0585-4d59-b361-7eb148b39377","lastUpdateDateTime":"2021-06-08T01:31:56Z","createdDateTime":"2021-06-08T01:31:19Z","expirationDateTime":"2021-06-09T01:31:19Z","status":"running","errors":[],"displayName":"NA","tasks":{"details":{"name":"NA","lastUpdateDateTime":"2021-06-08T01:31:56Z"},"completed":4,"failed":0,"inProgress":1,"total":5,"entityRecognitionTasks":[{"lastUpdateDateTime":"2021-06-08T01:31:40.3875777Z","name":"NA","state":"succeeded","results":{"documents":[{"id":"0","entities":[{"text":"logging","category":"Skill","offset":9,"length":7,"confidenceScore":0.61}],"warnings":[]}],"errors":[],"modelVersion":"2021-06-01"}}],"entityLinkingTasks":[{"lastUpdateDateTime":"2021-06-08T01:31:30.1194597Z","name":"NA","state":"succeeded","results":{"documents":[{"id":"0","entities":[{"name":"Test + (assessment)","matches":[{"text":"Test","offset":0,"length":4,"confidenceScore":0.04}],"language":"en","id":"Test + (assessment)","url":"https://en.wikipedia.org/wiki/Test_(assessment)","dataSource":"Wikipedia"}],"warnings":[]}],"errors":[],"modelVersion":"2020-02-01"}}],"entityRecognitionPiiTasks":[{"lastUpdateDateTime":"2021-06-08T01:31:45.5629681Z","name":"NA","state":"succeeded","results":{"documents":[{"redactedText":"Test + for logging disable","id":"0","entities":[],"warnings":[]}],"errors":[],"modelVersion":"2021-01-15"}}],"sentimentAnalysisTasks":[{"lastUpdateDateTime":"2021-06-08T01:31:56.2415819Z","name":"NA","state":"succeeded","results":{"documents":[{"id":"0","sentiment":"negative","confidenceScores":{"positive":0.02,"neutral":0.12,"negative":0.86},"sentences":[{"sentiment":"negative","confidenceScores":{"positive":0.02,"neutral":0.12,"negative":0.86},"offset":0,"length":24,"text":"Test + for logging disable"}],"warnings":[]}],"errors":[],"modelVersion":"2020-04-01"}}]}}' + headers: + apim-request-id: + - 747dee06-ff9c-461c-98aa-6e564623d1e3 + content-type: + - application/json; charset=utf-8 + date: + - Tue, 08 Jun 2021 01:32:00 GMT + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + transfer-encoding: + - chunked + x-content-type-options: + - nosniff + x-envoy-upstream-service-time: + - '61' + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - azsdk-python-ai-textanalytics/5.1.0b8 Python/3.9.1 (macOS-10.16-x86_64-i386-64bit) + method: GET + uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.5/analyze/jobs/5d783e81-0585-4d59-b361-7eb148b39377 + response: + body: + string: '{"jobId":"5d783e81-0585-4d59-b361-7eb148b39377","lastUpdateDateTime":"2021-06-08T01:31:56Z","createdDateTime":"2021-06-08T01:31:19Z","expirationDateTime":"2021-06-09T01:31:19Z","status":"running","errors":[],"displayName":"NA","tasks":{"details":{"name":"NA","lastUpdateDateTime":"2021-06-08T01:31:56Z"},"completed":4,"failed":0,"inProgress":1,"total":5,"entityRecognitionTasks":[{"lastUpdateDateTime":"2021-06-08T01:31:40.3875777Z","name":"NA","state":"succeeded","results":{"documents":[{"id":"0","entities":[{"text":"logging","category":"Skill","offset":9,"length":7,"confidenceScore":0.61}],"warnings":[]}],"errors":[],"modelVersion":"2021-06-01"}}],"entityLinkingTasks":[{"lastUpdateDateTime":"2021-06-08T01:31:30.1194597Z","name":"NA","state":"succeeded","results":{"documents":[{"id":"0","entities":[{"name":"Test + (assessment)","matches":[{"text":"Test","offset":0,"length":4,"confidenceScore":0.04}],"language":"en","id":"Test + (assessment)","url":"https://en.wikipedia.org/wiki/Test_(assessment)","dataSource":"Wikipedia"}],"warnings":[]}],"errors":[],"modelVersion":"2020-02-01"}}],"entityRecognitionPiiTasks":[{"lastUpdateDateTime":"2021-06-08T01:31:45.5629681Z","name":"NA","state":"succeeded","results":{"documents":[{"redactedText":"Test + for logging disable","id":"0","entities":[],"warnings":[]}],"errors":[],"modelVersion":"2021-01-15"}}],"sentimentAnalysisTasks":[{"lastUpdateDateTime":"2021-06-08T01:31:56.2415819Z","name":"NA","state":"succeeded","results":{"documents":[{"id":"0","sentiment":"negative","confidenceScores":{"positive":0.02,"neutral":0.12,"negative":0.86},"sentences":[{"sentiment":"negative","confidenceScores":{"positive":0.02,"neutral":0.12,"negative":0.86},"offset":0,"length":24,"text":"Test + for logging disable"}],"warnings":[]}],"errors":[],"modelVersion":"2020-04-01"}}]}}' + headers: + apim-request-id: + - 43bec792-47e3-4676-b80d-fdb8d957c5a9 + content-type: + - application/json; charset=utf-8 + date: + - Tue, 08 Jun 2021 01:32:05 GMT + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + transfer-encoding: + - chunked + x-content-type-options: + - nosniff + x-envoy-upstream-service-time: + - '55' + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - azsdk-python-ai-textanalytics/5.1.0b8 Python/3.9.1 (macOS-10.16-x86_64-i386-64bit) + method: GET + uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.1-preview.5/analyze/jobs/5d783e81-0585-4d59-b361-7eb148b39377 + response: + body: + string: '{"jobId":"5d783e81-0585-4d59-b361-7eb148b39377","lastUpdateDateTime":"2021-06-08T01:32:06Z","createdDateTime":"2021-06-08T01:31:19Z","expirationDateTime":"2021-06-09T01:31:19Z","status":"succeeded","errors":[],"displayName":"NA","tasks":{"details":{"name":"NA","lastUpdateDateTime":"2021-06-08T01:32:06Z"},"completed":5,"failed":0,"inProgress":0,"total":5,"entityRecognitionTasks":[{"lastUpdateDateTime":"2021-06-08T01:31:40.3875777Z","name":"NA","state":"succeeded","results":{"documents":[{"id":"0","entities":[{"text":"logging","category":"Skill","offset":9,"length":7,"confidenceScore":0.61}],"warnings":[]}],"errors":[],"modelVersion":"2021-06-01"}}],"entityLinkingTasks":[{"lastUpdateDateTime":"2021-06-08T01:31:30.1194597Z","name":"NA","state":"succeeded","results":{"documents":[{"id":"0","entities":[{"name":"Test + (assessment)","matches":[{"text":"Test","offset":0,"length":4,"confidenceScore":0.04}],"language":"en","id":"Test + (assessment)","url":"https://en.wikipedia.org/wiki/Test_(assessment)","dataSource":"Wikipedia"}],"warnings":[]}],"errors":[],"modelVersion":"2020-02-01"}}],"entityRecognitionPiiTasks":[{"lastUpdateDateTime":"2021-06-08T01:31:45.5629681Z","name":"NA","state":"succeeded","results":{"documents":[{"redactedText":"Test + for logging disable","id":"0","entities":[],"warnings":[]}],"errors":[],"modelVersion":"2021-01-15"}}],"keyPhraseExtractionTasks":[{"lastUpdateDateTime":"2021-06-08T01:32:06.4267819Z","name":"NA","state":"succeeded","results":{"documents":[{"id":"0","keyPhrases":["Test","logging"],"warnings":[]}],"errors":[],"modelVersion":"2021-06-01"}}],"sentimentAnalysisTasks":[{"lastUpdateDateTime":"2021-06-08T01:31:56.2415819Z","name":"NA","state":"succeeded","results":{"documents":[{"id":"0","sentiment":"negative","confidenceScores":{"positive":0.02,"neutral":0.12,"negative":0.86},"sentences":[{"sentiment":"negative","confidenceScores":{"positive":0.02,"neutral":0.12,"negative":0.86},"offset":0,"length":24,"text":"Test + for logging disable"}],"warnings":[]}],"errors":[],"modelVersion":"2020-04-01"}}]}}' + headers: + apim-request-id: + - 76c080b0-c1f3-40a3-bd1f-79cfbe1e9711 + content-type: + - application/json; charset=utf-8 + date: + - Tue, 08 Jun 2021 01:32:11 GMT + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + transfer-encoding: + - chunked + x-content-type-options: + - nosniff + x-envoy-upstream-service-time: + - '82' status: code: 200 message: OK diff --git a/sdk/textanalytics/azure-ai-textanalytics/tests/test_analyze.py b/sdk/textanalytics/azure-ai-textanalytics/tests/test_analyze.py index 1484add75994..96e7419257fc 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/tests/test_analyze.py +++ b/sdk/textanalytics/azure-ai-textanalytics/tests/test_analyze.py @@ -354,8 +354,23 @@ def test_out_of_order_ids_multiple_tasks(self, client): def test_show_stats_and_model_version_multiple_tasks(self, client): def callback(resp): - if resp.raw_response: - a = "b" + assert resp.raw_response + tasks = resp.raw_response['tasks'] + assert tasks['completed'] == 5 + assert tasks['inProgress'] == 0 + assert tasks['failed'] == 0 + assert tasks['total'] == 5 + num_tasks = 0 + for key, task in tasks.items(): + if "Tasks" in key: + num_tasks += 1 + assert len(task) == 1 + task_stats = task[0]['results']['statistics'] + assert task_stats['documentsCount'] == 4 + assert task_stats['validDocumentsCount'] == 4 + assert task_stats['erroneousDocumentsCount'] == 0 + assert task_stats['transactionsCount'] == 4 + assert num_tasks == 5 docs = [{"id": "56", "text": ":)"}, {"id": "0", "text": ":("}, diff --git a/sdk/textanalytics/azure-ai-textanalytics/tests/test_analyze_async.py b/sdk/textanalytics/azure-ai-textanalytics/tests/test_analyze_async.py index e8bf3cd7d823..6230eb51c9ce 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/tests/test_analyze_async.py +++ b/sdk/textanalytics/azure-ai-textanalytics/tests/test_analyze_async.py @@ -391,6 +391,25 @@ async def test_show_stats_and_model_version_multiple_tasks(self, client): {"id": "19", "text": ":P"}, {"id": "1", "text": ":D"}] + def callback(resp): + assert resp.raw_response + tasks = resp.raw_response['tasks'] + assert tasks['completed'] == 5 + assert tasks['inProgress'] == 0 + assert tasks['failed'] == 0 + assert tasks['total'] == 5 + num_tasks = 0 + for key, task in tasks.items(): + if "Tasks" in key: + num_tasks += 1 + assert len(task) == 1 + task_stats = task[0]['results']['statistics'] + assert task_stats['documentsCount'] == 4 + assert task_stats['validDocumentsCount'] == 4 + assert task_stats['erroneousDocumentsCount'] == 0 + assert task_stats['transactionsCount'] == 4 + assert num_tasks == 5 + async with client: response = await (await client.begin_analyze_actions( docs, @@ -402,7 +421,8 @@ async def test_show_stats_and_model_version_multiple_tasks(self, client): AnalyzeSentimentAction(model_version="latest") ], show_stats=True, - polling_interval=self._interval() + polling_interval=self._interval(), + raw_response_hook=callback, )).result() action_results = [] diff --git a/sdk/textanalytics/azure-ai-textanalytics/tests/test_analyze_healthcare.py b/sdk/textanalytics/azure-ai-textanalytics/tests/test_analyze_healthcare.py index 5f30ede5c8ca..94ffbd39f206 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/tests/test_analyze_healthcare.py +++ b/sdk/textanalytics/azure-ai-textanalytics/tests/test_analyze_healthcare.py @@ -132,11 +132,20 @@ def test_show_stats_and_model_version(self, client): {"id": "19", "text": ":P"}, {"id": "1", "text": ":D"}] + def callback(resp): + assert resp.raw_response + stats = resp.raw_response['results']['statistics'] + assert stats['documentsCount'] == 5 + assert stats['validDocumentsCount'] == 4 + assert stats['erroneousDocumentsCount'] == 1 + assert stats['transactionsCount'] == 4 + response = client.begin_analyze_healthcare_entities( docs, show_stats=True, model_version="2021-01-11", - polling_interval=self._interval() + polling_interval=self._interval(), + raw_response_hook = callback, ).result() num_error = 0 diff --git a/sdk/textanalytics/azure-ai-textanalytics/tests/test_analyze_healthcare_async.py b/sdk/textanalytics/azure-ai-textanalytics/tests/test_analyze_healthcare_async.py index 7657c2e17ace..0505592c2186 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/tests/test_analyze_healthcare_async.py +++ b/sdk/textanalytics/azure-ai-textanalytics/tests/test_analyze_healthcare_async.py @@ -158,12 +158,21 @@ async def test_show_stats_and_model_version(self, client): {"id": "19", "text": ":P"}, {"id": "1", "text": ":D"}] + def callback(resp): + assert resp.raw_response + stats = resp.raw_response['results']['statistics'] + assert stats['documentsCount'] == 5 + assert stats['validDocumentsCount'] == 4 + assert stats['erroneousDocumentsCount'] == 1 + assert stats['transactionsCount'] == 4 + async with client: response = await (await client.begin_analyze_healthcare_entities( docs, show_stats=True, model_version="2021-01-11", - polling_interval=self._interval() + polling_interval=self._interval(), + raw_response_hook=callback, )).result() assert response diff --git a/tools/azure-sdk-tools/devtools_testutils/cognitiveservices_testcase.py b/tools/azure-sdk-tools/devtools_testutils/cognitiveservices_testcase.py index f50c05b94233..c11149bf95d6 100644 --- a/tools/azure-sdk-tools/devtools_testutils/cognitiveservices_testcase.py +++ b/tools/azure-sdk-tools/devtools_testutils/cognitiveservices_testcase.py @@ -62,7 +62,7 @@ def create_resource(self, name, **kwargs): if self.is_live: self.client = self.create_mgmt_client(CognitiveServicesManagementClient) group = self._get_resource_group(**kwargs) - cogsci_account = self.client.accounts.create( + cogsci_account = self.client.accounts.begin_create( group.name, name, account={ @@ -71,7 +71,7 @@ def create_resource(self, name, **kwargs): "kind": self.kind, "properties": {"custom_sub_domain_name": self.custom_subdomain_name}, }, - ) + ).result() time.sleep(10) # it takes a few seconds to create a cognitive services account self.resource = cogsci_account self.cogsci_key = self.client.accounts.list_keys(group.name, name).key1 @@ -114,7 +114,7 @@ def create_resource(self, name, **kwargs): def remove_resource(self, name, **kwargs): if self.is_live: group = self._get_resource_group(**kwargs) - self.client.accounts.delete(group.name, name) + self.client.accounts.begin_delete(group.name, name).wait() def _get_resource_group(self, **kwargs): try: