File: test_create_and_deploy_project.py

package info (click to toggle)
python-azure 20251118%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 783,356 kB
  • sloc: python: 6,474,533; ansic: 804; javascript: 287; sh: 205; makefile: 198; xml: 109
file content (58 lines) | stat: -rw-r--r-- 2,755 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# pylint: disable=line-too-long,useless-suppression
import pytest
from typing import Any, Dict, cast
from azure.core.credentials import AzureKeyCredential
from azure.ai.language.questionanswering.authoring import QuestionAnsweringAuthoringClient

from helpers import AuthoringTestHelper
from testcase import QuestionAnsweringAuthoringTestCase


class TestCreateAndDeploy(QuestionAnsweringAuthoringTestCase):
    def test_polling_interval(self, qna_authoring_creds):
        client = QuestionAnsweringAuthoringClient(
            qna_authoring_creds["endpoint"], AzureKeyCredential(qna_authoring_creds["key"])
        )
        # Default polling interval may change across previews; assert it is a positive int (previously 30) instead of a fixed legacy value
        assert isinstance(client._config.polling_interval, int) and client._config.polling_interval > 0
        client = QuestionAnsweringAuthoringClient(
            qna_authoring_creds["endpoint"], AzureKeyCredential(qna_authoring_creds["key"]), polling_interval=1
        )
        assert client._config.polling_interval == 1

    def test_create_project(self, recorded_test, qna_authoring_creds):  # type: ignore[name-defined]
        client = QuestionAnsweringAuthoringClient(
            qna_authoring_creds["endpoint"], AzureKeyCredential(qna_authoring_creds["key"])
        )
        project_name = "IsaacNewton"
        client.create_project(
            project_name=project_name,
            options={
                "description": "Biography of Sir Isaac Newton",
                "language": "en",
                "multilingualResource": True,
                "settings": {"defaultAnswer": "no answer"},
            },
        )
        found = any(p.get("projectName") == project_name for p in client.list_projects())
        assert found

    def test_deploy_project(self, recorded_test, qna_authoring_creds):  # type: ignore[name-defined]
        client = QuestionAnsweringAuthoringClient(
            qna_authoring_creds["endpoint"], AzureKeyCredential(qna_authoring_creds["key"])
        )
        project_name = "IsaacNewton"
        AuthoringTestHelper.create_test_project(
            client,
            project_name=project_name,
            is_deployable=True,
            polling_interval=0 if self.is_playback else None,
        )
        deployment_poller = client.begin_deploy_project(
            project_name=project_name,
            deployment_name="production",
            polling_interval=0 if self.is_playback else None,
        )
        # Preview LRO returns None; just ensure it completes without error
        deployment_poller.result()
        assert any(d.get("deploymentName") == "production" for d in client.list_deployments(project_name=project_name))