Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[textanalytics] convert to test proxy #21696

Merged
merged 32 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e888854
try one test
kristapratico Nov 5, 2021
873c8eb
test proxy initial work
kristapratico Nov 10, 2021
923f9ed
Merge branch 'main' into ta-test-proxy
kristapratico Nov 11, 2021
0050c5c
adding sanitizer and recording, not working in playback yet
kristapratico Nov 12, 2021
c152283
Merge branch 'main' into ta-test-proxy
kristapratico Nov 16, 2021
25f38e5
Merge branch 'main' into ta-test-proxy
kristapratico Nov 18, 2021
abff538
update conftest and testcases
kristapratico Nov 19, 2021
f6ae10a
analyze actions - add new recordings and delete old
kristapratico Nov 19, 2021
238d579
analyze healthcare - add new recordings and delete old
kristapratico Nov 19, 2021
8c1d479
analyze sentiment - add new recordings and delete old
kristapratico Nov 19, 2021
636d750
auth tests should use get_credential, removes async base test class -…
kristapratico Nov 19, 2021
3a46967
detect language - add new recordings and delete old
kristapratico Nov 19, 2021
9d9ca4c
test encoding - add new recordings and delete old
kristapratico Nov 19, 2021
9872edf
extract key phrases - add new recordings and delete old
kristapratico Nov 19, 2021
c9f1a25
recognize entities - add new recordings and delete old
kristapratico Nov 19, 2021
b6a8a44
recognize linked entities - add new recordings and delete old
kristapratico Nov 19, 2021
54e5d94
recognize pii entities - add new recordings and delete old
kristapratico Nov 19, 2021
1d2ffc0
add testproxy config to ci/tests.yml
kristapratico Nov 19, 2021
046a666
delete unused recordings I missed
kristapratico Nov 19, 2021
4cee9fa
rstrip endpoint
kristapratico Nov 23, 2021
9fb30d2
add oauth sanitizer
kristapratico Dec 3, 2021
2f699a5
merge main
kristapratico Dec 13, 2021
c501293
fix rstrip endpoint, start the proxy automatically, rerecord a few tests
kristapratico Dec 13, 2021
0d87a72
Merge branch 'main' into ta-test-proxy
kristapratico Dec 13, 2021
590747b
try something
kristapratico Dec 13, 2021
cd64010
more logging
kristapratico Dec 14, 2021
bba65de
Merge branch 'main' into ta-test-proxy
kristapratico Dec 14, 2021
9779077
update all recordings
kristapratico Dec 14, 2021
14927e4
ignore body for tests where we scrub
kristapratico Dec 14, 2021
753f734
merge main
kristapratico Dec 14, 2021
da941ab
rerecord again
kristapratico Dec 14, 2021
f5f88d2
remove from tests.yml
kristapratico Dec 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ def __init__(self, endpoint, credential, **kwargs):
"opinionMining",
}
)

try:
endpoint = endpoint.rstrip("/")
except AttributeError:
raise ValueError("Parameter 'endpoint' must be a string.")
self._client = _TextAnalyticsClient(
endpoint=endpoint,
credential=credential,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from azure.core.exceptions import (
HttpResponseError,
ClientAuthenticationError,
ResourceNotFoundError,
ODataV4Format,
)
from azure.core.paging import ItemPaged
Expand Down Expand Up @@ -57,6 +58,8 @@ def process_http_response_error(error):
raise_error = HttpResponseError
if error.status_code == 401:
raise_error = ClientAuthenticationError
if error.status_code == 404:
raise_error = ResourceNotFoundError
raise raise_error(response=error.response, error_format=CSODataV4Format)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ def __init__(self, endpoint, credential, **kwargs):
"opinionMining",
}
)

try:
endpoint = endpoint.rstrip("/")
except AttributeError:
raise ValueError("Parameter 'endpoint' must be a string.")
self._client = _TextAnalyticsClient(
endpoint=endpoint,
credential=credential,
Expand Down
40 changes: 0 additions & 40 deletions sdk/textanalytics/azure-ai-textanalytics/tests/asynctestcase.py

This file was deleted.

18 changes: 18 additions & 0 deletions sdk/textanalytics/azure-ai-textanalytics/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,26 @@
# --------------------------------------------------------------------------

import sys
import pytest
from devtools_testutils import (
test_proxy,
add_remove_header_sanitizer,
add_general_regex_sanitizer,
add_oauth_response_sanitizer,
)


# Ignore async tests for Python < 3.6
collect_ignore_glob = []
if sys.version_info < (3, 6):
collect_ignore_glob.append("*_async.py")


@pytest.fixture(scope="session", autouse=True)
def add_sanitizers(test_proxy):
add_remove_header_sanitizer(headers="Ocp-Apim-Subscription-Key")
add_general_regex_sanitizer(
value="fakeendpoint",
regex="(?<=\\/\\/)[a-z-]+(?=\\.cognitiveservices\\.azure\\.com)"
)
add_oauth_response_sanitizer()
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{
"Entries": [
{
"RequestUri": "https://fakeendpoint.cognitiveservices.azure.com/text/analytics/v3.2-preview.2/analyze",
"RequestMethod": "POST",
"RequestHeaders": {
"Accept": "application/json, text/json",
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive",
"Content-Length": "2177",
"Content-Type": "application/json",
"User-Agent": "azsdk-python-ai-textanalytics/5.2.0b3 Python/3.10.0 (Windows-10-10.0.22000-SP0)",
"x-ms-client-request-id": "25293ed1-5d0f-11ec-aac3-b831b58100e8"
},
"RequestBody": "{\u0022tasks\u0022: {\u0022entityRecognitionTasks\u0022: [], \u0022entityRecognitionPiiTasks\u0022: [], \u0022keyPhraseExtractionTasks\u0022: [], \u0022entityLinkingTasks\u0022: [], \u0022sentimentAnalysisTasks\u0022: [], \u0022extractiveSummarizationTasks\u0022: [{\u0022parameters\u0022: {\u0022stringIndexType\u0022: \u0022UnicodeCodePoint\u0022}, \u0022taskName\u0022: \u00220\u0022}], \u0022customEntityRecognitionTasks\u0022: [], \u0022customSingleClassificationTasks\u0022: [], \u0022customMultiClassificationTasks\u0022: []}, \u0022analysisInput\u0022: {\u0022documents\u0022: [{\u0022id\u0022: \u00221\u0022, \u0022text\u0022: \u0022The government of British Prime Minster Theresa May has been plunged into turmoil with the resignation of two senior Cabinet ministers in a deep split over her Brexit strategy. The Foreign Secretary Boris Johnson, quit on Monday, hours after the resignation late on Sunday night of the minister in charge of Brexit negotiations, David Davis. Their decision to leave the government came three days after May appeared to have agreed a deal with herfractured Cabinet on the UK\u0027s post Brexit relationship with the EU. That plan is now in tatters and her political future appears uncertain. May appeared in Parliament on Monday afternoon to defend her plan, minutes after Downing Street confirmed the departure of Johnson. May acknowledged the splits in her statement to MPs, saying of the ministers who quit: We do not agree about the best way of delivering our shared commitment to honoring the result of the referendum. The Prime Minister\u0027s latest plitical drama began late on Sunday night when Davis quit, declaring he could not support May\u0027s Brexit plan. He said it involved too close a relationship with the EU and gave only an illusion of control being returned to the UK after it left the EU. It seems to me we\u0027re giving too much away, too easily, and that\u0027s a dangerous strategy at this time, Davis said in a BBC radio interview Monday morning. Johnson\u0027s resignation came Monday afternoon local time, just before the Prime Minister was due to make a scheduled statement in Parliament. This afternoon, the Prime Minister accepted the resignation of Boris Johnson as Foreign Secretary, a statement from Downing Street said.\u0022, \u0022language\u0022: \u0022en\u0022}, {\u0022id\u0022: \u00222\u0022, \u0022text\u0022: \u0022Microsoft fue fundado por Bill Gates y Paul Allen\u0022, \u0022language\u0022: \u0022es\u0022}]}}",
"StatusCode": 202,
"ResponseHeaders": {
"apim-request-id": "a03b6b25-f013-4368-bd31-ad425c9179ac",
"Date": "Tue, 14 Dec 2021 18:53:37 GMT",
"operation-location": "https://fakeendpoint.cognitiveservices.azure.com/text/analytics/v3.2-preview.2/analyze/jobs/0a0d1391-60f6-4b43-8d4f-41abe9f6f861",
"Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload",
"Transfer-Encoding": "chunked",
"X-Content-Type-Options": "nosniff",
"x-envoy-upstream-service-time": "217"
},
"ResponseBody": null
},
{
"RequestUri": "https://fakeendpoint.cognitiveservices.azure.com/text/analytics/v3.2-preview.2/analyze/jobs/0a0d1391-60f6-4b43-8d4f-41abe9f6f861?showStats=True",
"RequestMethod": "GET",
"RequestHeaders": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive",
"User-Agent": "azsdk-python-ai-textanalytics/5.2.0b3 Python/3.10.0 (Windows-10-10.0.22000-SP0)",
"x-ms-client-request-id": "25293ed1-5d0f-11ec-aac3-b831b58100e8"
},
"RequestBody": null,
"StatusCode": 200,
"ResponseHeaders": {
"apim-request-id": "3fa18449-f763-4f73-b925-eae5942bf462",
"Content-Type": "application/json; charset=utf-8",
"Date": "Tue, 14 Dec 2021 18:53:42 GMT",
"Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload",
"Transfer-Encoding": "chunked",
"X-Content-Type-Options": "nosniff",
"x-envoy-upstream-service-time": "114"
},
"ResponseBody": {
"jobId": "0a0d1391-60f6-4b43-8d4f-41abe9f6f861",
"lastUpdateDateTime": "2021-12-14T18:53:41Z",
"createdDateTime": "2021-12-14T18:53:37Z",
"expirationDateTime": "2021-12-15T18:53:37Z",
"status": "succeeded",
"errors": [],
"tasks": {
"completed": 1,
"failed": 0,
"inProgress": 0,
"total": 1,
"extractiveSummarizationTasks": [
{
"lastUpdateDateTime": "2021-12-14T18:53:41.3509318Z",
"taskName": "0",
"state": "succeeded",
"results": {
"statistics": {
"documentsCount": 2,
"validDocumentsCount": 2,
"erroneousDocumentsCount": 0,
"transactionsCount": 3
},
"documents": [
{
"id": "1",
"statistics": {
"charactersCount": 1625,
"transactionsCount": 2
},
"sentences": [
{
"text": "The government of British Prime Minster Theresa May has been plunged into turmoil with the resignation of two senior Cabinet ministers in a deep split over her Brexit strategy.",
"rankScore": 0.57,
"offset": 0,
"length": 176
},
{
"text": "The Foreign Secretary Boris Johnson, quit on Monday, hours after the resignation late on Sunday night of the minister in charge of Brexit negotiations, David Davis.",
"rankScore": 1.0,
"offset": 177,
"length": 164
},
{
"text": "Their decision to leave the government came three days after May appeared to have agreed a deal with herfractured Cabinet on the UK\u0027s post Brexit relationship with the EU.",
"rankScore": 0.47,
"offset": 342,
"length": 171
}
],
"warnings": []
},
{
"id": "2",
"statistics": {
"charactersCount": 49,
"transactionsCount": 1
},
"sentences": [
{
"text": "Microsoft fue fundado por Bill Gates y Paul Allen",
"rankScore": 1.0,
"offset": 0,
"length": 49
}
],
"warnings": []
}
],
"errors": [],
"modelVersion": "2021-08-01"
}
}
]
}
}
}
],
"Variables": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{
"Entries": [
{
"RequestUri": "https://fakeendpoint.cognitiveservices.azure.com/text/analytics/v3.2-preview.2/analyze",
"RequestMethod": "POST",
"RequestHeaders": {
"Accept": "application/json, text/json",
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive",
"Content-Length": "565",
"Content-Type": "application/json",
"User-Agent": "azsdk-python-ai-textanalytics/5.2.0b3 Python/3.10.0 (Windows-10-10.0.22000-SP0)",
"x-ms-client-request-id": "ad73a7fb-5d0e-11ec-8699-b831b58100e8"
},
"RequestBody": "{\u0022tasks\u0022: {\u0022entityRecognitionTasks\u0022: [], \u0022entityRecognitionPiiTasks\u0022: [], \u0022keyPhraseExtractionTasks\u0022: [{\u0022parameters\u0022: {}, \u0022taskName\u0022: \u00220\u0022}], \u0022entityLinkingTasks\u0022: [], \u0022sentimentAnalysisTasks\u0022: [], \u0022extractiveSummarizationTasks\u0022: [], \u0022customEntityRecognitionTasks\u0022: [], \u0022customSingleClassificationTasks\u0022: [], \u0022customMultiClassificationTasks\u0022: []}, \u0022analysisInput\u0022: {\u0022documents\u0022: [{\u0022id\u0022: \u00221\u0022, \u0022text\u0022: \u0022Microsoft was founded by Bill Gates and Paul Allen\u0022, \u0022language\u0022: \u0022en\u0022}, {\u0022id\u0022: \u00222\u0022, \u0022text\u0022: \u0022Microsoft fue fundado por Bill Gates y Paul Allen\u0022, \u0022language\u0022: \u0022es\u0022}]}}",
"StatusCode": 202,
"ResponseHeaders": {
"apim-request-id": "7c5ba259-3eda-456a-9f46-a35de4ba0e09",
"Date": "Tue, 14 Dec 2021 18:50:17 GMT",
"operation-location": "https://fakeendpoint.cognitiveservices.azure.com/text/analytics/v3.2-preview.2/analyze/jobs/307a5fae-a297-46da-b37d-bc28cf04eb24",
"Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload",
"Transfer-Encoding": "chunked",
"X-Content-Type-Options": "nosniff",
"x-envoy-upstream-service-time": "318"
},
"ResponseBody": null
},
{
"RequestUri": "https://fakeendpoint.cognitiveservices.azure.com/text/analytics/v3.2-preview.2/analyze/jobs/307a5fae-a297-46da-b37d-bc28cf04eb24?showStats=True",
"RequestMethod": "GET",
"RequestHeaders": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive",
"User-Agent": "azsdk-python-ai-textanalytics/5.2.0b3 Python/3.10.0 (Windows-10-10.0.22000-SP0)",
"x-ms-client-request-id": "ad73a7fb-5d0e-11ec-8699-b831b58100e8"
},
"RequestBody": null,
"StatusCode": 200,
"ResponseHeaders": {
"apim-request-id": "2b4749c7-31e2-4381-adb7-9a1a7c146612",
"Content-Type": "application/json; charset=utf-8",
"Date": "Tue, 14 Dec 2021 18:50:22 GMT",
"Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload",
"Transfer-Encoding": "chunked",
"X-Content-Type-Options": "nosniff",
"x-envoy-upstream-service-time": "125"
},
"ResponseBody": {
"jobId": "307a5fae-a297-46da-b37d-bc28cf04eb24",
"lastUpdateDateTime": "2021-12-14T18:50:22Z",
"createdDateTime": "2021-12-14T18:50:17Z",
"expirationDateTime": "2021-12-15T18:50:17Z",
"status": "succeeded",
"errors": [],
"tasks": {
"completed": 1,
"failed": 0,
"inProgress": 0,
"total": 1,
"keyPhraseExtractionTasks": [
{
"lastUpdateDateTime": "2021-12-14T18:50:22.069458Z",
"taskName": "0",
"state": "succeeded",
"results": {
"statistics": {
"documentsCount": 2,
"validDocumentsCount": 2,
"erroneousDocumentsCount": 0,
"transactionsCount": 2
},
"documents": [
{
"id": "1",
"keyPhrases": [
"Bill Gates",
"Paul Allen",
"Microsoft"
],
"statistics": {
"charactersCount": 50,
"transactionsCount": 1
},
"warnings": []
},
{
"id": "2",
"keyPhrases": [
"Bill Gates",
"Paul Allen",
"Microsoft"
],
"statistics": {
"charactersCount": 49,
"transactionsCount": 1
},
"warnings": []
}
],
"errors": [],
"modelVersion": "2021-06-01"
}
}
]
}
}
}
],
"Variables": {}
}
Loading