def step__hostpools_get_hostpool_list(test, rg):
    test.cmd(
        'az desktopvirtualization hostpool list '
        '-g ""',
        checks=[
            JMESPathCheckExists('[?name==\'{}\']'.format(
                test.kwargs["myHostPool"])),
        ])
def step__applicationgroups_get_applicationgroup_listbyresourcegroup(test, rg):
    test.cmd(
        'az desktopvirtualization applicationgroup list '
        '--filter "applicationGroupType eq \'RailApplication\'" '
        '--resource-group "{rg}"',
        checks=[
            JMESPathCheckExists('[?name==\'{}\']'.format(
                test.kwargs["myApplicationGroup"])),
        ])
Beispiel #3
0
 def exists(self, query):
     from azure.cli.testsdk.checkers import JMESPathCheckExists
     query = self._apply_kwargs(query)
     return JMESPathCheckExists(query)
    def test_storage_message_general_scenario(self, resource_group, storage_account):
        account_info = self.get_account_info(resource_group, storage_account)
        connection_string = self.get_connection_string(resource_group, storage_account)
        queue = self.create_random_name('queue', 24)

        # prepare queue
        self.storage_cmd('storage queue create -n {}', account_info, queue)

        # put message using account name
        self.storage_cmd('storage message put -q {} --content "test message 1"', account_info, queue) \
            .assert_with_checks([JMESPathCheck('content', "test message 1"),
                                 JMESPathCheckExists('expirationTime'),
                                 JMESPathCheckExists('timeNextVisible')])

        # put message using connecting string, test `visibility_timeout`
        self.cmd(
            'storage message put -q {} --content "test message 2" --visibility-timeout 3600 --connection-string {}'
            .format(queue, connection_string)) \
            .assert_with_checks([JMESPathCheck('content', "test message 2"),
                                 JMESPathCheckExists('expirationTime'),
                                 JMESPathCheckExists('timeNextVisible')])

        # put message using auth mode: login, test `time_to_live`
        self.oauth_cmd('storage message put -q {} --content "test message 3" --time-to-live 3600 --account-name {}'
                       .format(queue, storage_account)) \
            .assert_with_checks([JMESPathCheck('content', "test message 3"),
                                 JMESPathCheckExists('expirationTime'),
                                 JMESPathCheckExists('timeNextVisible')])

        # peek message
        self.storage_cmd('storage message peek -q {}', account_info, queue) \
            .assert_with_checks(JMESPathCheck('length(@)', 1))

        # peek message, test `num_messages`
        self.cmd('storage message peek -q {} --num-messages 5 --connection-string {}'
                 .format(queue, connection_string)).assert_with_checks(JMESPathCheck('length(@)', 2))

        # get message
        result = self.storage_cmd('storage message get -q {}', account_info, queue).get_output_in_json()
        self.assertEqual(len(result), 1)
        self.assertEqual(result[0]['content'], 'test message 1')
        self.assertEqual(result[0]['dequeueCount'], 1)
        self.assertIsNotNone(result[0]['id'])
        self.assertIsNotNone(result[0]['popReceipt'])

        # get message, test `visibility_timeout`
        result = self.storage_cmd('storage message get -q {} --visibility-timeout 30',
                                  account_info, queue).get_output_in_json()
        self.assertEqual(len(result), 1)
        self.assertEqual(result[0]['content'], 'test message 3')
        self.assertEqual(result[0]['dequeueCount'], 1)
        self.assertIsNotNone(result[0]['id'])
        self.assertIsNotNone(result[0]['popReceipt'])

        # get message, test `num_messages`
        import time
        time.sleep(35)
        result = self.storage_cmd('storage message get -q {} --num-messages 2', account_info,
                                  queue).get_output_in_json()
        self.assertEqual(len(result), 2)
        self.assertEqual(result[0]['content'], 'test message 1')
        self.assertEqual(result[0]['dequeueCount'], 2)
        self.assertEqual(result[1]['content'], 'test message 3')
        self.assertEqual(result[1]['dequeueCount'], 2)

        # update message, test `visibility_timeout`
        update_result = self.storage_cmd(
            'storage message update -q {} --id {} --pop-receipt {} --visibility-timeout 10',
            account_info, queue, result[0]['id'], result[0]['popReceipt']).get_output_in_json()
        self.assertIsNotNone(update_result.get('id'))
        self.assertIsNotNone(update_result.get('popReceipt'))

        # update message, test `content`
        update_result = self.storage_cmd(
            'storage message update -q {} --id {} --pop-receipt {} --content "update message"',
            account_info, queue, result[1]['id'], result[1]['popReceipt']).get_output_in_json()
        self.assertIsNotNone(update_result.get('id'))
        self.assertIsNotNone(update_result.get('popReceipt'))
        self.assertEqual(update_result.get('content'), 'update message')

        # delete message
        self.storage_cmd('storage message delete -q {} --id {} --pop-receipt {}',
                         account_info, queue, update_result.get('id'), update_result.get('popReceipt'))
        time.sleep(10)
        self.storage_cmd('storage message peek -q {} --num-messages 2', account_info, queue) \
            .assert_with_checks(JMESPathCheck('length(@)', 1))

        # clear queue messages
        self.storage_cmd('storage message clear -q {}', account_info, queue)
        self.storage_cmd('storage message peek -q {} --num-messages 2', account_info, queue) \
            .assert_with_checks(JMESPathCheck('length(@)', 0))