Skip to content

Commit

Permalink
IoT command module knack conversion (#5084)
Browse files Browse the repository at this point in the history
Add CI

Re-record tests

Use actual value in checkers
  • Loading branch information
derekbekoe authored and tjprescott committed Dec 13, 2017
1 parent 262361e commit 3b64584
Show file tree
Hide file tree
Showing 15 changed files with 2,304 additions and 2,818 deletions.
1 change: 0 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ exclude =
src/command_modules/azure-cli-cosmosdb
src/command_modules/azure-cli-dla
src/command_modules/azure-cli-dls
src/command_modules/azure-cli-iot
src/command_modules/azure-cli-monitor
3 changes: 1 addition & 2 deletions scripts/ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ for name in $(ls src/command_modules | grep azure-cli-); do
if [ "$name" == "azure-cli-eventgrid" ]; then continue; fi
if [ "$name" == "azure-cli-find" ]; then continue; fi
if [ "$name" == "azure-cli-interactive" ]; then continue; fi
if [ "$name" == "azure-cli-iot" ]; then continue; fi
if [ "$name" == "azure-cli-keyvault" ]; then continue; fi
if [ "$name" == "azure-cli-keyvault" ]; then continue; fi
if [ "$name" == "azure-cli-lab" ]; then continue; fi
if [ "$name" == "azure-cli-monitor" ]; then continue; fi
if [ "$name" == "azure-cli-profile" ]; then continue; fi
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/test_static.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ run_style azure.cli.command_modules.extension
run_style azure.cli.command_modules.feedback
run_style azure.cli.command_modules.find
run_style azure.cli.command_modules.interactive
#run_style azure.cli.command_modules.iot
run_style azure.cli.command_modules.iot
run_style azure.cli.command_modules.keyvault
run_style azure.cli.command_modules.lab
#run_style azure.cli.command_modules.monitor
Expand Down
6 changes: 6 additions & 0 deletions src/azure-cli-testsdk/azure/cli/testsdk/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ def greater_than(self, query, expected_results):
expected_results = self._apply_kwargs(expected_results)
return JMESPathCheckGreaterThan(query, expected_results)

def check_pattern(self, query, expected_results):
from azure.cli.testsdk.checkers import JMESPathPatternCheck
query = self._apply_kwargs(query)
expected_results = self._apply_kwargs(expected_results)
return JMESPathPatternCheck(query, expected_results)

def is_empty(self): # pylint: disable=no-self-use
from azure.cli.testsdk.checkers import NoneCheck
return NoneCheck()
Expand Down
15 changes: 15 additions & 0 deletions src/azure-cli-testsdk/azure/cli/testsdk/checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import re
import collections
import jmespath
from .exceptions import JMESPathCheckAssertionError
Expand Down Expand Up @@ -59,6 +60,20 @@ def __call__(self, execution_result):
execution_result.output)


class JMESPathPatternCheck(object): # pylint: disable=too-few-public-methods
def __init__(self, query, expected_result):
self._query = query
self._expected_result = expected_result

def __call__(self, execution_result):
json_value = execution_result.get_output_in_json()
actual_result = jmespath.search(self._query, json_value,
jmespath.Options(collections.OrderedDict))
if not re.match(self._expected_result, str(actual_result), re.IGNORECASE):
raise JMESPathCheckAssertionError(self._query, self._expected_result, actual_result,
execution_result.output)


class NoneCheck(object): # pylint: disable=too-few-public-methods
def __call__(self, execution_result): # pylint: disable=no-self-use
none_strings = ['[]', '{}', 'false']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,28 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core import AzCommandsLoader

import azure.cli.command_modules.iot._help # pylint: disable=unused-import


def load_params(_):
import azure.cli.command_modules.iot._params # pylint: disable=redefined-outer-name, unused-variable
class IoTCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
iot_custom = CliCommandType(operations_tmpl='azure.cli.command_modules.iot.custom#{}')
super(IoTCommandsLoader, self).__init__(cli_ctx=cli_ctx,
custom_command_type=iot_custom,
min_profile='2017-03-10-profile')

def load_command_table(self, args):
from azure.cli.command_modules.iot.commands import load_command_table
load_command_table(self, args)
return self.command_table

def load_arguments(self, command):
from azure.cli.command_modules.iot._params import load_arguments
load_arguments(self, command)


def load_commands():
import azure.cli.command_modules.iot.commands # pylint: disable=redefined-outer-name, unused-variable
COMMAND_LOADER_CLS = IoTCommandsLoader
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
# --------------------------------------------------------------------------------------------


def iot_hub_service_factory(_):
def iot_hub_service_factory(cli_ctx, *_):
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azure.mgmt.iothub.iot_hub_client import IotHubClient
return get_mgmt_service_client(IotHubClient)
return get_mgmt_service_client(cli_ctx, IotHubClient)


def resource_service_factory(**_):
def resource_service_factory(cli_ctx, **_):
from azure.mgmt.resource import ResourceManagementClient
from azure.cli.core.commands.client_factory import get_mgmt_service_client
return get_mgmt_service_client(ResourceManagementClient)
return get_mgmt_service_client(cli_ctx, ResourceManagementClient)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core.decorators import Completer

from ._client_factory import iot_hub_service_factory
from .custom import iot_device_list


@Completer
def get_device_id_completion_list(cmd, prefix, namespace): # pylint: disable=unused-argument
client = iot_hub_service_factory(cmd.cli_ctx)
return [d.device_id for d in iot_device_list(client, namespace.hub_name, top=100)] if namespace.hub_name else []
Loading

0 comments on commit 3b64584

Please sign in to comment.