File: disable_test_cli_mgmt_cosmosdb_mongodb.py

package info (click to toggle)
python-azure 20250603%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 851,724 kB
  • sloc: python: 7,362,925; ansic: 804; javascript: 287; makefile: 195; sh: 145; xml: 109
file content (215 lines) | stat: -rw-r--r-- 11,007 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:
#   MongoDBResources: 16/16

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.mgmt_client = self.create_mgmt_client(azure.mgmt.cosmosdb.CosmosDBManagementClient)

    @unittest.skip("hard to test")
    @ResourceGroupPreparer(location=AZURE_LOCATION)
    def test_mongodb_resource(self, resource_group):

        RESOURCE_GROUP = resource_group.name
        ACCOUNT_NAME = "myaccountxxyyzzz"
        DATABASE_NAME = "myDatabase"
        COLLECTION_NAME = "myCollection"

        # --------------------------------------------------------------------------
        # /DatabaseAccounts/put/CosmosDBDatabaseAccountCreateMin[put]
        # --------------------------------------------------------------------------
        BODY = {
            "location": AZURE_LOCATION,
            "kind": "MongoDB",
            "database_account_offer_type": "Standard",
            "locations": [{"location_name": "eastus", "is_zone_redundant": False, "failover_priority": "0"}],
            "api_properties": {},
        }
        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()

        # --------------------------------------------------------------------------
        # /MongoDBResources/put/CosmosDBMongoDBDatabaseCreateUpdate[put]
        # --------------------------------------------------------------------------
        BODY = {"location": AZURE_LOCATION, "resource": {"id": DATABASE_NAME}, "options": {"throughput": "2000"}}
        result = self.mgmt_client.mongo_db_resources.begin_create_update_mongo_db_database(
            resource_group_name=RESOURCE_GROUP,
            account_name=ACCOUNT_NAME,
            database_name=DATABASE_NAME,
            create_update_mongo_db_database_parameters=BODY,
        )
        result = result.result()

        # --------------------------------------------------------------------------
        # /MongoDBResources/put/CosmosDBMongoDBCollectionCreateUpdate[put]
        # --------------------------------------------------------------------------
        BODY = {
            "location": AZURE_LOCATION,
            "resource": {"id": COLLECTION_NAME, "shard_key": {"theShardKey": "Hash"}},
            "options": {"throughput": "2000"},
        }
        result = self.mgmt_client.mongo_db_resources.begin_create_update_mongo_db_collection(
            resource_group_name=RESOURCE_GROUP,
            account_name=ACCOUNT_NAME,
            database_name=DATABASE_NAME,
            collection_name=COLLECTION_NAME,
            create_update_mongo_db_collection_parameters=BODY,
        )
        result = result.result()

        # --------------------------------------------------------------------------
        # /MongoDBResources/put/CosmosDBMongoDBDatabaseThroughputUpdate[put]
        # --------------------------------------------------------------------------
        BODY = {"location": AZURE_LOCATION, "resource": {"throughput": "400"}}
        result = self.mgmt_client.mongo_db_resources.begin_update_mongo_db_database_throughput(
            resource_group_name=RESOURCE_GROUP,
            account_name=ACCOUNT_NAME,
            database_name=DATABASE_NAME,
            update_throughput_parameters=BODY,
        )
        result = result.result()

        # --------------------------------------------------------------------------
        # /MongoDBResources/put/CosmosDBMongoDBCollectionThroughputUpdate[put]
        # --------------------------------------------------------------------------
        BODY = {"location": AZURE_LOCATION, "resource": {"throughput": "400"}}
        result = self.mgmt_client.mongo_db_resources.begin_update_mongo_db_collection_throughput(
            resource_group_name=RESOURCE_GROUP,
            account_name=ACCOUNT_NAME,
            database_name=DATABASE_NAME,
            collection_name=COLLECTION_NAME,
            update_throughput_parameters=BODY,
        )
        result = result.result()

        # --------------------------------------------------------------------------
        # /MongoDBResources/get/CosmosDBMongoDBCollectionThroughputGet[get]
        # --------------------------------------------------------------------------
        result = self.mgmt_client.mongo_db_resources.get_mongo_db_collection_throughput(
            resource_group_name=RESOURCE_GROUP,
            account_name=ACCOUNT_NAME,
            database_name=DATABASE_NAME,
            collection_name=COLLECTION_NAME,
        )

        # --------------------------------------------------------------------------
        # /MongoDBResources/get/CosmosDBMongoDBDatabaseThroughputGet[get]
        # --------------------------------------------------------------------------
        result = self.mgmt_client.mongo_db_resources.get_mongo_db_database_throughput(
            resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME, database_name=DATABASE_NAME
        )

        # --------------------------------------------------------------------------
        # /MongoDBResources/get/CosmosDBMongoDBCollectionGet[get]
        # --------------------------------------------------------------------------
        result = self.mgmt_client.mongo_db_resources.get_mongo_db_collection(
            resource_group_name=RESOURCE_GROUP,
            account_name=ACCOUNT_NAME,
            database_name=DATABASE_NAME,
            collection_name=COLLECTION_NAME,
        )

        # --------------------------------------------------------------------------
        # /MongoDBResources/get/CosmosDBMongoDBCollectionList[get]
        # --------------------------------------------------------------------------
        result = self.mgmt_client.mongo_db_resources.list_mongo_db_collections(
            resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME, database_name=DATABASE_NAME
        )

        # --------------------------------------------------------------------------
        # /MongoDBResources/get/CosmosDBMongoDBDatabaseGet[get]
        # --------------------------------------------------------------------------
        result = self.mgmt_client.mongo_db_resources.get_mongo_db_database(
            resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME, database_name=DATABASE_NAME
        )

        # --------------------------------------------------------------------------
        # /MongoDBResources/get/CosmosDBMongoDBDatabaseList[get]
        # --------------------------------------------------------------------------
        result = self.mgmt_client.mongo_db_resources.list_mongo_db_databases(
            resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME
        )

        # --------------------------------------------------------------------------
        # /MongoDBResources/post/CosmosDBMongoDBCollectionMigrateToAutoscale[post]
        # --------------------------------------------------------------------------
        result = self.mgmt_client.mongo_db_resources.begin_migrate_mongo_db_collection_to_autoscale(
            resource_group_name=RESOURCE_GROUP,
            account_name=ACCOUNT_NAME,
            database_name=DATABASE_NAME,
            collection_name=COLLECTION_NAME,
        )
        result = result.result()

        # --------------------------------------------------------------------------
        # /MongoDBResources/post/CosmosDBMongoDBCollectionMigrateToManualThroughput[post]
        # --------------------------------------------------------------------------
        result = self.mgmt_client.mongo_db_resources.begin_migrate_mongo_db_collection_to_manual_throughput(
            resource_group_name=RESOURCE_GROUP,
            account_name=ACCOUNT_NAME,
            database_name=DATABASE_NAME,
            collection_name=COLLECTION_NAME,
        )
        result = result.result()

        # --------------------------------------------------------------------------
        # /MongoDBResources/post/CosmosDBMongoDBDatabaseMigrateToAutoscale[post]
        # --------------------------------------------------------------------------
        result = self.mgmt_client.mongo_db_resources.begin_migrate_mongo_db_database_to_autoscale(
            resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME, database_name=DATABASE_NAME
        )
        result = result.result()

        # --------------------------------------------------------------------------
        # /MongoDBResources/post/CosmosDBMongoDBDatabaseMigrateToManualThroughput[post]
        # --------------------------------------------------------------------------
        result = self.mgmt_client.mongo_db_resources.begin_migrate_mongo_db_database_to_manual_throughput(
            resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME, database_name=DATABASE_NAME
        )
        result = result.result()

        # --------------------------------------------------------------------------
        # /MongoDBResources/delete/CosmosDBMongoDBCollectionDelete[delete]
        # --------------------------------------------------------------------------
        result = self.mgmt_client.mongo_db_resources.begin_delete_mongo_db_collection(
            resource_group_name=RESOURCE_GROUP,
            account_name=ACCOUNT_NAME,
            database_name=DATABASE_NAME,
            collection_name=COLLECTION_NAME,
        )
        result = result.result()

        # --------------------------------------------------------------------------
        # /MongoDBResources/delete/CosmosDBMongoDBDatabaseDelete[delete]
        # --------------------------------------------------------------------------
        result = self.mgmt_client.mongo_db_resources.begin_delete_mongo_db_database(
            resource_group_name=RESOURCE_GROUP, account_name=ACCOUNT_NAME, database_name=DATABASE_NAME
        )
        result = result.result()

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