Exemplo n.º 1
0
 def test_config_apply_edge_error(
     self,
     fixture_cmd2,
     serviceclient_generic_error,
     device_id,
     hub_name,
     sample_config_edge_malformed,
 ):
     with pytest.raises(CLIError):
         subject.iot_edge_set_modules(
             cmd=fixture_cmd2,
             device_id=device_id,
             hub_name=mock_target["entity"],
             content=sample_config_edge_malformed,
         )
Exemplo n.º 2
0
    def test_config_apply_edge(
        self, fixture_cmd, serviceclient, device_id, hub_name, sample_config_edge
    ):
        # Not yet supporting layered deployments
        if sample_config_edge[0] == "layered":
            return

        result = subject.iot_edge_set_modules(
            cmd=fixture_cmd,
            device_id=device_id,
            hub_name=mock_target["entity"],
            content=sample_config_edge[1],
        )

        # For the actual apply configuration call
        args = serviceclient.call_args_list[0]
        url = args[0][0].url
        method = args[0][0].method
        body = json.loads(args[0][0].body)

        assert method == "POST"
        assert (
            "{}/devices/{}/applyConfigurationContent?".format(
                mock_target["entity"], device_id
            )
            in url
        )

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

        # For returning the set of module identities applied to the device
        args = serviceclient.call_args_list[1]
        url = args[0][0].url
        method = args[0][0].method

        assert method == "GET"
        assert "{}/devices/{}/modules?".format(mock_target["entity"], device_id) in url
        assert result is not None
Exemplo n.º 3
0
    def test_config_apply_edge_malformed(
        self,
        fixture_cmd2,
        serviceclient,
        device_id,
        hub_name,
        sample_config_edge_malformed,
    ):
        with pytest.raises(CLIError) as exc:
            subject.iot_edge_set_modules(
                cmd=fixture_cmd2,
                device_id=device_id,
                hub_name=mock_target["entity"],
                content=sample_config_edge_malformed,
            )

        exception_obj = json.loads(str(exc.value))
        assert "validationErrors" in exception_obj
        for error_element in exception_obj["validationErrors"]:
            assert "description" in error_element
            assert "contentPath" in error_element
            assert "schemaPath" in error_element