示例#1
0
def sample_config_adm(set_cwd, request):
    path_device = "test_adm_device_content.json"
    path_module = "test_adm_module_content.json"

    payload = None
    if request.param == "moduleFile":
        payload = get_context_path(__file__, path_module)
    elif request.param == "moduleInline":
        payload = json.dumps(json.loads(read_file_content(path_module)))
    elif request.param == "deviceFile":
        payload = get_context_path(__file__, path_device)
    elif request.param == "deviceInline":
        payload = json.dumps(json.loads(read_file_content(path_device)))

    return (request.param, payload)
示例#2
0
def sample_config_edge(set_cwd, request):
    path = "test_edge_deployment.json"
    layered_path = "test_edge_deployment_layered.json"
    v1_path = "test_edge_deployment_v1.json"
    v11_path = "test_edge_deployment_v11.json"
    ea_v11_eh_v12_path = "test_edge_deployment_ea_v11_eh_v12.json"
    ea_v90_eh_v91_path = "test_edge_deployment_ea_v90_eh_v91.json"

    payload = None
    if request.param == "inlineA":
        payload = json.dumps(json.loads(read_file_content(path)))
    elif request.param == "inlineB":
        payload = json.dumps(json.loads(read_file_content(path))["content"])
    elif request.param == "file":
        payload = get_context_path(__file__, path)
    elif request.param == "layered":
        payload = json.dumps(json.loads(read_file_content(layered_path)))
    elif request.param == "v1":
        payload = json.dumps(json.loads(read_file_content(v1_path)))
    elif request.param == "v11":
        payload = json.dumps(json.loads(read_file_content(v11_path)))
    elif request.param == "ea_v11_eh_v12":
        payload = json.dumps(json.loads(read_file_content(ea_v11_eh_v12_path)))
    elif request.param == "ea_v90_eh_v91":
        payload = json.dumps(json.loads(read_file_content(ea_v90_eh_v91_path)))

    return (request.param, payload)
示例#3
0
    def test_config_create_adm_invalid(
        self,
        fixture_cmd,
        serviceclient,
        config_id,
        hub_name,
        target_condition,
        priority,
        labels,
    ):
        with pytest.raises(CLIError) as exc1:
            subject.iot_hub_configuration_create(
                cmd=fixture_cmd,
                config_id=config_id,
                hub_name=hub_name,
                content=get_context_path(__file__,
                                         "test_edge_deployment.json"),
                target_condition=target_condition,
                priority=priority,
                labels=labels,
            )

        # API does not support both deviceContent and moduleContent at the same time.
        content = json.dumps({"deviceContent": {}, "moduleContent": {}})
        with pytest.raises(CLIError) as exc2:
            subject.iot_hub_configuration_create(
                cmd=fixture_cmd,
                config_id=config_id,
                hub_name=hub_name,
                content=content,
                target_condition=target_condition,
                priority=priority,
                labels=labels,
            )

        for exc in [exc1, exc2]:
            assert (
                str(exc.value) ==
                "Automatic device configuration payloads require property: deviceContent or moduleContent"
            )

        # Module configurations target condition needs to start with 'from devices.modules where'
        content = json.dumps({"moduleContent": {"key": "value"}})
        with pytest.raises(CLIError) as exc3:
            subject.iot_hub_configuration_create(
                cmd=fixture_cmd,
                config_id=config_id,
                hub_name=hub_name,
                content=content,
                target_condition=target_condition,
                priority=priority,
                labels=labels,
            )

        assert (
            str(exc3.value) ==
            "The target condition for a module configuration must start with 'from devices.modules where'"
        )
示例#4
0
def sample_config_metrics(set_cwd, request):
    path = "test_config_generic_metrics.json"

    payload = None
    if request.param == "inlineA":
        payload = json.dumps(json.loads(read_file_content(path)))
    elif request.param == "inlineB":
        payload = json.dumps(json.loads(read_file_content(path))["metrics"])
    elif request.param == "file":
        payload = get_context_path(__file__, path)

    return (request.param, payload)
import time
import pytest

from azext_iot.tests.conftest import get_context_path

from azure.iot.device import Message
from azext_iot.common import utility
from azext_iot.central.models.enum import DeviceStatus, Role
from azext_iot.monitor.parsers import strings

from azext_iot.tests import CaptureOutputLiveScenarioTest, helpers

APP_ID = os.environ.get("azext_iot_central_app_id")
APP_PRIMARY_KEY = os.environ.get("azext_iot_central_primarykey")
APP_SCOPE_ID = os.environ.get("azext_iot_central_scope_id")
device_template_path = get_context_path(__file__,
                                        "json/device_template_int_test.json")
sync_command_params = get_context_path(__file__, "json/sync_command_args.json")

if not all([APP_ID]):
    raise ValueError(
        "Set azext_iot_central_app_id to run central integration tests.")


class TestIotCentral(CaptureOutputLiveScenarioTest):
    def __init__(self, test_scenario):
        super(TestIotCentral, self).__init__(test_scenario=test_scenario)

    def test_central_device_twin_show_fail(self):
        (device_id, _) = self._create_device()

        # Verify incorrect app-id throws error
示例#6
0
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import random
import json

from azext_iot.tests import IoTLiveScenarioTest
from azext_iot.tests.conftest import get_context_path
from azext_iot.tests.settings import DynamoSettings, ENV_SET_TEST_IOTHUB_BASIC
from azext_iot.common.utility import read_file_content

settings = DynamoSettings(ENV_SET_TEST_IOTHUB_BASIC)
LIVE_HUB = settings.env.azext_iot_testhub
LIVE_RG = settings.env.azext_iot_testrg

edge_content_path = get_context_path(__file__, "test_edge_deployment.json")
edge_content_layered_path = get_context_path(
    __file__, "test_edge_deployment_layered.json")
edge_content_v11_path = get_context_path(__file__,
                                         "test_edge_deployment_v11.json")
edge_content_v1_path = get_context_path(__file__,
                                        "test_edge_deployment_v1.json")
edge_content_malformed_path = get_context_path(
    __file__, "test_edge_deployment_malformed.json")
generic_metrics_path = get_context_path(__file__,
                                        "test_config_generic_metrics.json")
adm_content_module_path = get_context_path(__file__,
                                           "test_adm_module_content.json")
adm_content_device_path = get_context_path(__file__,
                                           "test_adm_device_content.json")