def test_rotate_subscription_key(self, resource_group, location,
                                     text_analytics_account,
                                     text_analytics_account_key):
        credential = AzureKeyCredential(text_analytics_account_key)
        client = TextAnalyticsClient(text_analytics_account, credential)

        docs = [{
            "id": "1",
            "text": "I will go to the park."
        }, {
            "id": "2",
            "text": "I did not like the hotel we stayed at."
        }, {
            "id": "3",
            "text": "The restaurant had really good food."
        }]

        response = client.recognize_entities(docs)
        self.assertIsNotNone(response)

        credential.update("xxx")  # Make authentication fail
        with self.assertRaises(ClientAuthenticationError):
            response = client.recognize_entities(docs)

        credential.update(
            text_analytics_account_key)  # Authenticate successfully again
        response = client.recognize_entities(docs)
        self.assertIsNotNone(response)
    def test_rotate_subscription_key(self, textanalytics_test_endpoint,
                                     textanalytics_test_api_key):
        credential = AzureKeyCredential(textanalytics_test_api_key)
        client = TextAnalyticsClient(textanalytics_test_endpoint, credential)

        docs = [{
            "id": "1",
            "text": "I will go to the park."
        }, {
            "id": "2",
            "text": "I did not like the hotel we stayed at."
        }, {
            "id": "3",
            "text": "The restaurant had really good food."
        }]

        response = client.recognize_linked_entities(docs)
        assert response is not None

        credential.update("xxx")  # Make authentication fail
        with pytest.raises(ClientAuthenticationError):
            response = client.recognize_linked_entities(docs)

        credential.update(
            textanalytics_test_api_key)  # Authenticate successfully again
        response = client.recognize_linked_entities(docs)
        assert response is not None
    async def test_rotate_subscription_key(self, textanalytics_test_endpoint,
                                           textanalytics_test_api_key):
        credential = AzureKeyCredential(textanalytics_test_api_key)
        client = TextAnalyticsClient(textanalytics_test_endpoint, credential)

        docs = [{
            "id": "1",
            "text": "I will go to the park."
        }, {
            "id": "2",
            "text": "I did not like the hotel we stayed at."
        }, {
            "id": "3",
            "text": "The restaurant had really good food."
        }]

        response = await client.analyze_sentiment(docs)
        self.assertIsNotNone(response)

        credential.update("xxx")  # Make authentication fail
        with self.assertRaises(ClientAuthenticationError):
            response = await client.analyze_sentiment(docs)

        credential.update(
            textanalytics_test_api_key)  # Authenticate successfully again
        response = await client.analyze_sentiment(docs)
        self.assertIsNotNone(response)
def test_azure_key_credential_updates():
    """Tests AzureKeyCredential updates"""
    api_key = "original"

    credential = AzureKeyCredential(api_key)
    assert credential.key == api_key

    api_key = "new"
    credential.update(api_key)
    assert credential.key == api_key
 def test_indexer_credential_roll(self):
     credential = AzureKeyCredential(key="old_api_key")
     client = SearchIndexerClient("endpoint", credential)
     assert client._headers == {
         "api-key": "old_api_key",
         "Accept": "application/json;odata.metadata=minimal",
     }
     credential.update("new_api_key")
     assert client._headers == {
         "api-key": "new_api_key",
         "Accept": "application/json;odata.metadata=minimal",
     }
Ejemplo n.º 6
0
    def test_rotate_subscription_key(self, resource_group, location,
                                     text_analytics_account,
                                     text_analytics_account_key):

        credential = AzureKeyCredential(text_analytics_account_key)
        client = TextAnalyticsClient(text_analytics_account, credential)

        docs = [{
            "id": "1",
            "text": "I will go to the park."
        }, {
            "id": "2",
            "text": "I did not like the hotel we stayed at."
        }, {
            "id": "3",
            "text": "The restaurant had really good food."
        }]

        response = client.begin_analyze(
            docs,
            entities_recognition_tasks=[EntitiesRecognitionTask()],
            key_phrase_extraction_tasks=[KeyPhraseExtractionTask()],
            pii_entities_recognition_tasks=[PiiEntitiesRecognitionTask()],
            polling_interval=self._interval(),
        ).result()

        self.assertIsNotNone(response)

        credential.update("xxx")  # Make authentication fail
        with self.assertRaises(ClientAuthenticationError):
            response = client.begin_analyze(
                docs,
                entities_recognition_tasks=[EntitiesRecognitionTask()],
                key_phrase_extraction_tasks=[KeyPhraseExtractionTask()],
                pii_entities_recognition_tasks=[PiiEntitiesRecognitionTask()],
                polling_interval=self._interval(),
            ).result()

        credential.update(
            text_analytics_account_key)  # Authenticate successfully again
        response = client.begin_analyze(
            docs,
            entities_recognition_tasks=[EntitiesRecognitionTask()],
            key_phrase_extraction_tasks=[KeyPhraseExtractionTask()],
            pii_entities_recognition_tasks=[PiiEntitiesRecognitionTask()],
            polling_interval=self._interval(),
        ).result()
        self.assertIsNotNone(response)
    async def test_rotate_subscription_key(self, resource_group, location,
                                           text_analytics_account,
                                           text_analytics_account_key):

        credential = AzureKeyCredential(text_analytics_account_key)
        client = TextAnalyticsClient(text_analytics_account, credential)

        docs = [{
            "id": "1",
            "text": "I will go to the park."
        }, {
            "id": "2",
            "text": "I did not like the hotel we stayed at."
        }, {
            "id": "3",
            "text": "The restaurant had really good food."
        }]

        async with client:
            response = await (await client.begin_analyze_batch_actions(
                docs,
                actions=[
                    RecognizeEntitiesAction(),
                ],
                polling_interval=self._interval())).result()

            self.assertIsNotNone(response)

            credential.update("xxx")  # Make authentication fail
            with self.assertRaises(ClientAuthenticationError):
                response = await (await client.begin_analyze_batch_actions(
                    docs,
                    actions=[
                        RecognizeEntitiesAction(),
                    ],
                    polling_interval=self._interval())).result()

            credential.update(
                text_analytics_account_key)  # Authenticate successfully again
            response = await (await client.begin_analyze_batch_actions(
                docs,
                actions=[
                    RecognizeEntitiesAction(),
                ],
                polling_interval=self._interval())).result()
            self.assertIsNotNone(response)
Ejemplo n.º 8
0
    def test_rotate_subscription_key(self, resource_group, location, text_analytics_account, text_analytics_account_key):

        credential = AzureKeyCredential(text_analytics_account_key)
        client = TextAnalyticsClient(text_analytics_account, credential, api_version=TextAnalyticsApiVersion.V3_1_PREVIEW_3)

        docs = [{"id": "1", "text": "I will go to the park."},
                {"id": "2", "text": "I did not like the hotel we stayed at."},
                {"id": "3", "text": "The restaurant had really good food."}]

        response = client.begin_analyze_healthcare(docs, polling_interval=self._interval()).result()
        self.assertIsNotNone(response)

        credential.update("xxx")  # Make authentication fail
        with self.assertRaises(ClientAuthenticationError):
            response = client.begin_analyze_healthcare(docs, polling_interval=self._interval()).result()

        credential.update(text_analytics_account_key)  # Authenticate successfully again
        response = client.begin_analyze_healthcare(docs, polling_interval=self._interval()).result()
        self.assertIsNotNone(response)