Ejemplo n.º 1
0
    def test_config_create_adm(
        self,
        fixture_cmd,
        serviceclient,
        sample_config_adm,
        sample_config_metrics,
        config_id,
        hub_name,
        target_condition,
        priority,
        labels,
    ):

        contentKey = (
            "moduleContent"
            if sample_config_adm[0].startswith("module")
            else "deviceContent"
        )

        if contentKey == "moduleContent":
            # Enforce the query prefix for success the case
            target_condition = "FROM devices.modules WHERE {}".format(target_condition)

        subject.iot_hub_configuration_create(
            cmd=fixture_cmd,
            config_id=config_id,
            hub_name=hub_name,
            content=sample_config_adm[1],
            target_condition=target_condition,
            priority=priority,
            labels=labels,
            metrics=sample_config_metrics[1],
        )

        args = serviceclient.call_args
        url = args[0][0].url
        method = args[0][0].method
        body = json.loads(args[0][0].body)

        assert "{}/configurations/{}?".format(hub_name, config_id.lower()) in url
        assert method == "PUT"
        assert body["id"] == config_id.lower()
        assert body.get("targetCondition") == target_condition
        assert body.get("priority") == priority
        assert body.get("labels") == evaluate_literal(labels, dict)

        if sample_config_adm[0].endswith("Inline"):
            assert (
                body["content"][contentKey]
                == json.loads(sample_config_adm[1])["content"][contentKey]
            )
        elif sample_config_adm[0].endswith("File"):
            assert (
                body["content"][contentKey]
                == json.loads(read_file_content(sample_config_adm[1]))["content"][
                    contentKey
                ]
            )

        self._assert_config_metrics_request(sample_config_metrics, body)
Ejemplo n.º 2
0
    def test_config_create_edge(
        self,
        fixture_cmd,
        serviceclient,
        sample_config_edge,
        sample_config_metrics,
        config_id,
        hub_name,
        target_condition,
        priority,
        labels,
    ):
        subject.iot_edge_deployment_create(
            cmd=fixture_cmd,
            config_id=config_id,
            hub_name=hub_name,
            content=sample_config_edge[1],
            target_condition=target_condition,
            priority=priority,
            labels=labels,
            metrics=sample_config_metrics[1],
            layered=(sample_config_edge[0] == "layered"),
        )

        args = serviceclient.call_args
        url = args[0][0].url
        method = args[0][0].method
        body = json.loads(args[0][0].body)

        assert "{}/configurations/{}?".format(hub_name, config_id.lower()) in url
        assert method == "PUT"
        assert body["id"] == config_id.lower()
        assert body.get("targetCondition") == target_condition
        assert body.get("priority") == priority
        assert body.get("labels") == evaluate_literal(labels, dict)

        if sample_config_edge[0] == "inlineB":
            assert (
                body["content"]["modulesContent"]
                == json.loads(sample_config_edge[1])["modulesContent"]
            )
        elif sample_config_edge[0] == "file":
            assert (
                body["content"]["modulesContent"]
                == json.loads(read_file_content(sample_config_edge[1]))["content"][
                    "modulesContent"
                ]
            )
        elif sample_config_edge[0] == "v1":
            assert (
                body["content"]["modulesContent"]
                == json.loads(sample_config_edge[1])["content"]["moduleContent"]
            )
        else:
            assert (
                body["content"]["modulesContent"]
                == json.loads(sample_config_edge[1])["content"]["modulesContent"]
            )

        self._assert_config_metrics_request(sample_config_metrics, body)