File: disable_test_cli_mgmt_cognitiveservices.py

package info (click to toggle)
python-azure 20230112%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 749,544 kB
  • sloc: python: 6,815,827; javascript: 287; makefile: 195; xml: 109; sh: 105
file content (131 lines) | stat: -rw-r--r-- 4,767 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# coding: utf-8

#-------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#--------------------------------------------------------------------------


# TEST SCENARIO COVERAGE
# ----------------------
# Methods Total   : 14
# Methods Covered : 14
# Examples Total  : 15
# Examples Tested : 13
# Coverage %      : 87
# ----------------------

import unittest

import azure.mgmt.cognitiveservices
from devtools_testutils import AzureMgmtTestCase, ResourceGroupPreparer

AZURE_LOCATION = 'eastus'

class MgmtCognitiveServicesTest(AzureMgmtTestCase):

    def setUp(self):
        super(MgmtCognitiveServicesTest, self).setUp()
        self.mgmt_client = self.create_mgmt_client(
            azure.mgmt.cognitiveservices.CognitiveServicesManagementClient
        )
    
    @unittest.skip('hard to test')
    @ResourceGroupPreparer(location=AZURE_LOCATION)
    def test_cognitiveservices(self, resource_group):

        SUBSCRIPTION_ID = self.settings.SUBSCRIPTION_ID
        RESOURCE_GROUP = resource_group.name
        ACCOUNT_NAME = "myAccount"
        LOCATION = "myLocation"

        # /Accounts/put/Create Account Min[put]
        BODY = {
          "location": "West US",
          "kind": "CognitiveServices",
          "sku": {
            "name": "S0"
          },
          "identity": {
            "type": "SystemAssigned"
          }
        }
        result = self.mgmt_client.accounts.create(resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME, account=BODY)

        # /Accounts/put/Create Account[put]
        BODY = {
          "location": "West US",
          "kind": "Emotion",
          "sku": {
            "name": "S0"
          },
          "properties": {
            "encryption": {
              "key_vault_properties": {
                "key_name": "KeyName",
                "key_version": "891CF236-D241-4738-9462-D506AF493DFA",
                "key_vault_uri": "https://pltfrmscrts-use-pc-dev.vault.azure.net/"
              },
              "key_source": "Microsoft.KeyVault"
            },
            "user_owned_storage": [
              {
                "resource_id": "/subscriptions/" + SUBSCRIPTION_ID + "/resourceGroups/" + RESOURCE_GROUP + "/providers/Microsoft.Storage/storageAccountsfelixwatest"
              }
            ]
          },
          "identity": {
            "type": "SystemAssigned"
          }
        }
        # result = self.mgmt_client.accounts.create(resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME, account=BODY)

        # /Accounts/get/Get Usages[get]
        result = self.mgmt_client.accounts.get_usages(resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME)

        # /Accounts/get/List SKUs[get]
        result = self.mgmt_client.accounts.list_skus(resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME)

        # /Accounts/get/Get Account[get]
        result = self.mgmt_client.accounts.get_properties(resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME)

        # /Accounts/get/List Accounts by Resource Group[get]
        result = self.mgmt_client.accounts.list_by_resource_group(resource_group_name=RESOURCE_GROUP)

        # /Accounts/get/List Accounts by Subscription[get]
        result = self.mgmt_client.accounts.list()

        # /ResourceSkus/get/Regenerate Keys[get]
        result = self.mgmt_client.resource_skus.list()

        # /Operations/get/Get Operations[get]
        result = self.mgmt_client.operations.list()

        # /Accounts/post/Regenerate Keys[post]
        result = self.mgmt_client.accounts.regenerate_key(resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME, key_name="Key2")

        # /Accounts/post/List Keys[post]
        result = self.mgmt_client.accounts.list_keys(resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME)

        # /Accounts/patch/Update Account[patch]
        BODY = {
          "sku": {
            "name": "S2"
          }
        }
        # result = self.mgmt_client.accounts.update(resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME, account=BODY)

        # //post/Check SKU Availability[post]
        SKUS = [
            "S0"
        ]
        result = self.mgmt_client.check_sku_availability(location="eastus", skus=SKUS, kind="Face", type="Microsoft.CognitiveServices/accounts")

        # /Accounts/delete/Delete Account[delete]
        result = self.mgmt_client.accounts.delete(resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME)


#------------------------------------------------------------------------------
if __name__ == '__main__':
    unittest.main()