Ejemplo n.º 1
0
    def test_config_update(self, fixture_cmd2, serviceclient,
                           sample_config_show):
        subject.iot_hub_configuration_update(
            cmd=fixture_cmd2,
            config_id=config_id,
            hub_name=mock_target["entity"],
            parameters=sample_config_show,
        )
        args = serviceclient.call_args
        url = args[0][0].url
        method = args[0][0].method
        body = json.loads(args[0][0].body)
        headers = args[0][0].headers

        assert "{}/configurations/{}?".format(mock_target["entity"],
                                              config_id) in url
        assert method == "PUT"

        assert headers["If-Match"] == '"{}"'.format(sample_config_show["etag"])

        assert body["id"] == sample_config_show["id"]
        assert body["contentType"] == "assignment"
        assert body.get("metrics") == sample_config_show.get("metrics")
        assert body.get("targetCondition") == sample_config_show.get(
            "targetCondition")
        assert body.get("priority") == sample_config_show.get("priority")
        assert body.get("labels") == sample_config_show.get("labels")
Ejemplo n.º 2
0
    def test_config_update_invalid_args(self, fixture_cmd2, serviceclient,
                                        sample_config_show):
        from copy import deepcopy

        request = deepcopy(sample_config_show)
        request["etag"] = None

        with pytest.raises(CLIError):
            subject.iot_hub_configuration_update(
                cmd=fixture_cmd2,
                config_id=config_id,
                hub_name=mock_target["entity"],
                parameters=request,
            )

        request = deepcopy(sample_config_show)
        request["labels"] = "not a dictionary"

        with pytest.raises(CLIError) as exc_label:
            subject.iot_hub_configuration_update(
                cmd=fixture_cmd2,
                config_id=config_id,
                hub_name=mock_target["entity"],
                parameters=request,
            )

        type_name = "class" if "class" in str(type) else "type"
        assert str(exc_label.value) == (
            "The property \"labels\" must be of <{0} 'dict'> but is <{0} 'str'>. "
            "Input: not a dictionary. Review inline JSON examples here --> "
            "https://github.com/Azure/azure-iot-cli-extension/wiki/Tips".
            format(type_name))
Ejemplo n.º 3
0
 def test_config_update_error(self, fixture_cmd, serviceclient_generic_error):
     with pytest.raises(CLIError):
         subject.iot_hub_configuration_update(
             cmd=fixture_cmd,
             config_id=config_id,
             hub_name=mock_target["entity"],
             parameters={},
         )