Skip to content

Commit

Permalink
Fix linter issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
digimaun committed Nov 22, 2018
1 parent b4c107a commit 6ae09a1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
3 changes: 2 additions & 1 deletion azext_iot/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
'sys = system properties, app = application properties, anno = annotations'
)


# pylint: disable=too-many-statements
def load_arguments(self, _):
"""
Expand Down Expand Up @@ -165,7 +166,7 @@ def load_arguments(self, _):

with self.argument_context('iot device') as context:
context.argument('data', options_list=['--data', '--da'], help='Message body.')
context.argument('properties', options_list=['--properties', '--props'],
context.argument('properties', options_list=['--properties', '--props', '-p'],
help='Message property bag in key-value pairs with the '
'following format: a=b;c=d')
context.argument('msg_count', options_list=['--msg-count', '--mc'], type=int,
Expand Down
1 change: 1 addition & 0 deletions azext_iot/operations/events3/_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def _get_conn_props():
await asyncio.gather(*coroutines, return_exceptions=True)


# pylint: disable=too-many-statements
async def monitor_events(endpoint, connection, path, auth, partition, consumer_group, enqueuedtimeutc,
properties, device_id=None, timeout=0, output=None, content_type=None):
source = uamqp.address.Source('amqps://{}/{}/ConsumerGroups/{}/Partitions/{}'.format(endpoint, path,
Expand Down
4 changes: 3 additions & 1 deletion azext_iot/operations/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ def _iot_c2d_message_receive(target, device_id, lock_timeout=60):
return {
'ack': result.headers['iothub-ack'],
'correlationId': result.headers['iothub-correlationid'],
'data': result.response.content,
'data': result.response.text,
'deliveryCount': result.headers['iothub-deliverycount'],
'enqueuedTime': result.headers['iothub-enqueuedtime'],
'expiry': result.headers['iothub-expiry'],
Expand Down Expand Up @@ -1126,6 +1126,8 @@ def iot_hub_monitor_events(cmd, hub_name=None, device_id=None, consumer_group='$

config = cmd.cli_ctx.config
output = cmd.cli_ctx.invocation.data.get("output", None)
if not output:
output = 'json'
ensure_uamqp(config, yes, repair)

events3 = importlib.import_module('azext_iot.operations.events3._events')
Expand Down
16 changes: 8 additions & 8 deletions azext_iot/tests/test_iot_ext_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,17 +551,17 @@ def test_hub_modules(self):
assert len(result) == 4

self.cmd('''iot hub module-identity update -d {} -n {} -g {} -m {}
--set authentication.symmetricKey.primaryKey="" authentication.symmetricKey.secondaryKey=""'''.format(
edge_device_ids[0], LIVE_HUB, LIVE_RG, module_ids[0]),
--set authentication.symmetricKey.primaryKey="" authentication.symmetricKey.secondaryKey=""'''
.format(edge_device_ids[0], LIVE_HUB, LIVE_RG, module_ids[0]),
checks=[self.check('deviceId', edge_device_ids[0]),
self.check('moduleId', module_ids[0]),
self.exists('authentication.symmetricKey.primaryKey'),
self.exists('authentication.symmetricKey.secondaryKey')])

# With connection string
self.cmd('''iot hub module-identity update -d {} --login {} -m {}
--set authentication.symmetricKey.primaryKey="" authentication.symmetricKey.secondaryKey=""'''.format(
edge_device_ids[0], LIVE_HUB_CS, module_ids[0]),
--set authentication.symmetricKey.primaryKey="" authentication.symmetricKey.secondaryKey=""'''
.format(edge_device_ids[0], LIVE_HUB_CS, module_ids[0]),
checks=[self.check('deviceId', edge_device_ids[0]),
self.check('moduleId', module_ids[0]),
self.exists('authentication.symmetricKey.primaryKey'),
Expand Down Expand Up @@ -1201,14 +1201,14 @@ def test_hub_monitor_events(self):
'$.mid=12345;key0=value0;key1=1', 1, LIVE_RG],
max_runs=1)
# Monitor events for all devices and include sys, anno, app
self.command_execute_assert('iot hub monitor-events -n {} -g {} --cg {} --et {} -t 10 -y -p sys anno app'.format(
LIVE_HUB, LIVE_RG, LIVE_CONSUMER_GROUPS[0], enqueued_time),
self.command_execute_assert('iot hub monitor-events -n {} -g {} --cg {} --et {} -t 10 -y -p sys anno app'
.format(LIVE_HUB, LIVE_RG, LIVE_CONSUMER_GROUPS[0], enqueued_time),
device_ids + ['system', 'annotations', 'application',
'"message_id": "12345"', '"key0": "value0"', '"key1": "1"'])

# Monitor events for a single device
self.command_execute_assert('iot hub monitor-events -n {} -g {} -d {} --cg {} --et {} -t 10 -y -p sys anno app'.format(
LIVE_HUB, LIVE_RG, device_ids[0], LIVE_CONSUMER_GROUPS[1], enqueued_time),
self.command_execute_assert('iot hub monitor-events -n {} -g {} -d {} --cg {} --et {} -t 10 -y -p sys anno app'
.format(LIVE_HUB, LIVE_RG, device_ids[0], LIVE_CONSUMER_GROUPS[1], enqueued_time),
[device_ids[0], 'system', 'annotations', 'application', '"message_id": "12345"',
'"key0": "value0"', '"key1": "1"'])

Expand Down
24 changes: 16 additions & 8 deletions azext_iot/tests/test_iot_ext_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,17 @@ def mqttclient_generic_error(mocker, fixture_ghcs, fixture_sas):
return mqtt_client


def build_mock_response(mocker, status_code=200, payload=None, headers=None):
def build_mock_response(mocker, status_code=200, payload=None, headers=None, raw=False):
response = mocker.MagicMock(name='response')
response.status_code = status_code
del response.context
del response._attribute_map
response.text.return_value = json.dumps(payload)

if raw:
response.text = payload
else:
response.text.return_value = json.dumps(payload)

if headers:
response.headers = headers
return response
Expand Down Expand Up @@ -1566,14 +1571,17 @@ def serviceclient(self, mocker, fixture_ghcs, fixture_sas, request):
service_client.return_value = build_mock_response(mocker)
return service_client

def test_c2d_receive(self, serviceclient):
data = "sample data"
serviceclient.return_value.status_code = 200
serviceclient.return_value.headers = sample_c2d_receive
serviceclient.return_value.content = data
@pytest.fixture
def fixture_mocker(self, mocker, fixture_ghcs, fixture_sas, request):
return mocker

def test_c2d_receive(self, fixture_mocker):
data = '{"data": "value"}'
service_client = fixture_mocker.patch(path_service_client)
service_client.return_value = build_mock_response(fixture_mocker, 200, data, sample_c2d_receive, raw=True)
timeout = 120
result = subject.iot_c2d_message_receive(fixture_cmd, device_id, mock_target['entity'], timeout)
args = serviceclient.call_args
args = service_client.call_args
url = args[0][0].url
method = args[0][0].method
headers = args[0][1]
Expand Down

0 comments on commit 6ae09a1

Please sign in to comment.