File: test_mgmt_iotcentral.py

package info (click to toggle)
python-azure 20201208%2Bgit-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,437,920 kB
  • sloc: python: 4,287,452; javascript: 269; makefile: 198; sh: 187; xml: 106
file content (68 lines) | stat: -rw-r--r-- 2,517 bytes parent folder | download | duplicates (2)
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
# 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.
#--------------------------------------------------------------------------
import unittest

import azure.mgmt.iotcentral
from azure.mgmt.iotcentral.models import App, AppSkuInfo
from datetime import date, timedelta
from devtools_testutils import AzureMgmtTestCase, ResourceGroupPreparer

class MgmtIoTCentralTest(AzureMgmtTestCase):

    def setUp(self):
        super(MgmtIoTCentralTest, self).setUp()
        self.iotcentral_client = self.create_mgmt_client(
            azure.mgmt.iotcentral.IotCentralClient
        )

    @ResourceGroupPreparer()
    def test_iotcentral(self, resource_group, location):
        account_name = self.get_resource_name('iot')
        
        is_available = self.iotcentral_client.apps.check_name_availability(
            account_name
        )
        self.assertTrue(is_available.name_available)

        async_iotcentral_app = self.iotcentral_client.apps.create_or_update(
            resource_group.name,
            account_name,
            {
                'location': location,
                'subscriptionid': self.settings.SUBSCRIPTION_ID,
                'subdomain': account_name,
                'display_name': account_name,
                'sku': {
                  'name': 'S1'
                }
            }
        )
        iotcentral_account = async_iotcentral_app.result()
        self.assertEqual(iotcentral_account.name, account_name)

        iotcentral_account = self.iotcentral_client.apps.get(
            resource_group.name,
            account_name
        )
        self.assertEqual(iotcentral_account.display_name, account_name)

        iotcentral_accounts = list(self.iotcentral_client.apps.list_by_resource_group(resource_group.name))
        self.assertTrue(all(i.display_name == account_name for i in iotcentral_accounts))

        iotcentral_accounts =  list(self.iotcentral_client.apps.list_by_subscription())
        self.assertTrue(any(i.display_name == account_name for i in iotcentral_accounts))

        async_delete = self.iotcentral_client.apps.delete(
            resource_group.name,
            account_name
        )
        async_delete.wait()

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