File: disable_test_cli_mgmt_cosmosdb_db.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 (215 lines) | stat: -rw-r--r-- 11,651 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# 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.
#--------------------------------------------------------------------------

# Current Operation Coverage:
#   DatabaseAccounts: 16/18
#   Operations: 1/1

import unittest

import azure.mgmt.cosmosdb
from devtools_testutils import AzureMgmtTestCase, RandomNameResourceGroupPreparer, ResourceGroupPreparer

AZURE_LOCATION = 'eastus'

class MgmtCosmosDBTest(AzureMgmtTestCase):

    def setUp(self):
        super(MgmtCosmosDBTest, self).setUp()
        self.re_replacer.register_pattern_pair(
            '"primaryMasterKey":".{88}"',
            '"primaryMasterKey":"FakeKey"',
        )
        self.re_replacer.register_pattern_pair(
            '"secondaryMasterKey":".{88}"',
            '"secondaryMasterKey":"FakeKey"',
        )
        self.re_replacer.register_pattern_pair(
            '"primaryReadonlyMasterKey":".{88}"',
            '"primaryReadonlyMasterKey":"FakeKey"',
        )
        self.re_replacer.register_pattern_pair(
            '"secondaryReadonlyMasterKey":".{88}"',
            '"secondaryReadonlyMasterKey":"FakeKey"',
        )
        self.mgmt_client = self.create_mgmt_client(
            azure.mgmt.cosmosdb.CosmosDBManagementClient
        )
    
    @unittest.skip('hard to test')
    @ResourceGroupPreparer(location=AZURE_LOCATION)
    def test_dbaccount(self, resource_group):
        RESOURCE_GROUP = resource_group.name
        ACCOUNT_NAME = "myaccountxxyyzzz"

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

#--------------------------------------------------------------------------
        # /DatabaseAccounts/put/CosmosDBDatabaseAccountCreateMin[put]
#--------------------------------------------------------------------------
        BODY = {
          "location": AZURE_LOCATION,
          "database_account_offer_type": "Standard",
          "locations": [
            {
              "failover_priority": "2",
              "location_name": "southcentralus",
              "is_zone_redundant": False
            },
            {
              "location_name": "eastus",
              "failover_priority": "1"
            },
            {
              "location_name": "westus",
              "failover_priority": "0"
            }
          ]
        }
        result = self.mgmt_client.database_accounts.begin_create_or_update(resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME, create_update_parameters=BODY)
        result = result.result()

#--------------------------------------------------------------------------
        # /DatabaseAccounts/get/CosmosDBDatabaseAccountGetMetricDefinitions[get]
#--------------------------------------------------------------------------
        result = self.mgmt_client.database_accounts.list_metric_definitions(resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME)

#--------------------------------------------------------------------------
        # /DatabaseAccounts/get/CosmosDBDatabaseAccountListReadOnlyKeys[get]
#--------------------------------------------------------------------------
        result = self.mgmt_client.database_accounts.get_read_only_keys(resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME)

#--------------------------------------------------------------------------
        # /DatabaseAccounts/get/CosmosDBDatabaseAccountGetMetrics[get]
#--------------------------------------------------------------------------
        result = self.mgmt_client.database_accounts.list_metrics(resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME, filter="$filter=(name.value eq 'Total Requests') and timeGrain eq duration'PT5M' and startTime eq '2017-11-19T23:53:55.2780000Z' and endTime eq '2017-11-20T00:13:55.2780000Z")

#--------------------------------------------------------------------------
        # /DatabaseAccounts/get/CosmosDBDatabaseAccountGetUsages[get]
#--------------------------------------------------------------------------
        result = self.mgmt_client.database_accounts.list_usages(resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME, filter="$filter=name.value eq 'Storage'")

#--------------------------------------------------------------------------
        # /DatabaseAccounts/get/CosmosDBDatabaseAccountGet[get]
#--------------------------------------------------------------------------
        result = self.mgmt_client.database_accounts.get(resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME)

#--------------------------------------------------------------------------
        # /DatabaseAccounts/get/CosmosDBDatabaseAccountListByResourceGroup[get]
#--------------------------------------------------------------------------
        result = self.mgmt_client.database_accounts.list_by_resource_group(resource_group_name=RESOURCE_GROUP)

#--------------------------------------------------------------------------
        # /DatabaseAccounts/get/CosmosDBDatabaseAccountList[get]
#--------------------------------------------------------------------------
        result = self.mgmt_client.database_accounts.list()

#--------------------------------------------------------------------------
        # /DatabaseAccounts/post/CosmosDBDatabaseAccountFailoverPriorityChange[post]
#--------------------------------------------------------------------------
        BODY = {
          "failover_policies": [
            {
              "location_name": "eastus",
              "failover_priority": "0"
            },
            {
              "location_name": "westus",
              "failover_priority": "1"
            },
            {
              "failover_priority": "2",
              "location_name": "southcentralus"
            }
          ]
        }
        result = self.mgmt_client.database_accounts.begin_failover_priority_change(resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME, failover_parameters=BODY)
        result = result.result()

#--------------------------------------------------------------------------
        # /DatabaseAccounts/post/CosmosDBDatabaseAccountListConnectionStrings[post]
#--------------------------------------------------------------------------
        result = self.mgmt_client.database_accounts.list_connection_strings(resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME)

#--------------------------------------------------------------------------
        # /DatabaseAccounts/post/CosmosDBDatabaseAccountListConnectionStringsMongo[post]
#--------------------------------------------------------------------------
        result = self.mgmt_client.database_accounts.list_connection_strings(resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME)

#--------------------------------------------------------------------------
        # /DatabaseAccountRegion/get/CosmosDBDatabaseAccountRegionGetMetrics[get]
#--------------------------------------------------------------------------
        # result = self.mgmt_client.database_account_region.list_metrics(resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME, region=REGION, filter="$filter=(name.value eq 'Total Requests') and timeGrain eq duration'PT5M' and startTime eq '2017-11-19T23:53:55.2780000Z' and endTime eq '2017-11-20T00:13:55.2780000Z")

#--------------------------------------------------------------------------
        # /CollectionRegion/get/CosmosDBRegionCollectionGetMetrics[get]
#--------------------------------------------------------------------------
        # result = self.mgmt_client.collection_region.list_metrics(resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME, region=REGION, database_rid=DATABASE_RID, collection_rid=COLLECTION_RID, filter="$filter=(name.value eq 'Total Requests') and timeGrain eq duration'PT5M' and startTime eq '2017-11-19T23:53:55.2780000Z' and endTime eq '2017-11-20T00:13:55.2780000Z")

#--------------------------------------------------------------------------
        # /DatabaseAccounts/post/CosmosDBDatabaseAccountOfflineRegion[post]
#--------------------------------------------------------------------------
        BODY = {
            "region": "eastus"
        }
        # result = self.mgmt_client.database_accounts.begin_offline_region(resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME, region_parameter_for_offline=BODY)
        # result = result.result()

#--------------------------------------------------------------------------
        # /DatabaseAccounts/post/CosmosDBDatabaseAccountOnlineRegion[post]
#--------------------------------------------------------------------------
        BODY = {
            "region": "eastus"
        }
        # result = self.mgmt_client.database_accounts.begin_online_region(resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME, region_parameter_for_online=BODY)
        # result = result.result()

#--------------------------------------------------------------------------
        # /DatabaseAccounts/post/CosmosDBDatabaseAccountRegenerateKey[post]
#--------------------------------------------------------------------------
        BODY = {
          "key_kind": "primary"
        }
        result = self.mgmt_client.database_accounts.begin_regenerate_key(resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME, key_to_regenerate=BODY)
        result = result.result()

#--------------------------------------------------------------------------
        # /DatabaseAccounts/post/CosmosDBDatabaseAccountListReadOnlyKeys[post]
#--------------------------------------------------------------------------
        result = self.mgmt_client.database_accounts.list_read_only_keys(resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME)

#--------------------------------------------------------------------------
        # /DatabaseAccounts/post/CosmosDBDatabaseAccountListKeys[post]
#--------------------------------------------------------------------------
        result = self.mgmt_client.database_accounts.list_keys(resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME)

#--------------------------------------------------------------------------
        # /DatabaseAccounts/patch/CosmosDBDatabaseAccountPatch[patch]
#--------------------------------------------------------------------------
        BODY = {
          "tags": {
            "dept": "finance"
          }
        }
        result = self.mgmt_client.database_accounts.begin_update(resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME, update_parameters=BODY)
        result = result.result()

#--------------------------------------------------------------------------
        # /DatabaseAccounts/head/CosmosDBDatabaseAccountCheckNameExists[head]
#--------------------------------------------------------------------------
        result = self.mgmt_client.database_accounts.check_name_exists(account_name=ACCOUNT_NAME)

#--------------------------------------------------------------------------
        # /DatabaseAccounts/delete/CosmosDBDatabaseAccountDelete[delete]
#--------------------------------------------------------------------------
        result = self.mgmt_client.database_accounts.begin_delete(resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME)
        result = result.result()