def test_config_device_key_too_long(self, device_id):
     client = devices_api_with_params(device_id=device_id,
                                      tenant_id="tenant-id")
     configuration = {
         "k" * 4097: "value",
     }
     with pytest.raises(DevicesApiException) as excinfo:
         client.report_device_configuration(request_body=configuration,
                                            _preload_content=False)
     assert excinfo.value.status == 400
 def test_config_device_value_boolean(self, device_id):
     client = devices_api_with_params(device_id=device_id,
                                      tenant_id="tenant-id")
     configuration = {
         "key": "value",
         "another-key": False,
     }
     with pytest.raises(DevicesApiException) as excinfo:
         client.report_device_configuration(request_body=configuration,
                                            _preload_content=False)
     assert excinfo.value.status == 400
 def test_config_device_get(self, device_id):
     user_id = str(uuid.uuid4())
     management_client = management_api_with_params(user_id=user_id,
                                                    tenant_id="tenant-id")
     client = devices_api_with_params(device_id=device_id,
                                      tenant_id="tenant-id")
     #
     # set the initial configuration
     configuration = {
         "key": "value",
         "another-key": "another-value",
         "dollar-key": "$",
     }
     r = management_client.set_device_configuration(
         device_id, request_body=configuration, _preload_content=False)
     assert r.status == 204
     #
     # get the configuration
     data = client.get_device_configuration()
     assert data == {
         "key": "value",
         "another-key": "another-value",
         "dollar-key": "$",
     }
 def test_config_device_set_get_remove(self, device_id):
     user_id = str(uuid.uuid4())
     management_client = management_api_with_params(user_id=user_id,
                                                    tenant_id="tenant-id")
     client = devices_api_with_params(device_id=device_id,
                                      tenant_id="tenant-id")
     #
     # get the configuration (empty)
     r = management_client.get_device_configuration(device_id)
     data = r.to_dict()
     assert {
         "id": device_id,
         "reported": {},
         "configured": {}
     } == {k: data[k]
           for k in ("id", "reported", "configured")}
     assert "reported_ts" in data.keys()
     #
     # set the initial configuration
     configuration = {
         "key": "value",
         "another-key": "another-value",
         "dollar-key": "$",
     }
     r = client.report_device_configuration(request_body=configuration,
                                            _preload_content=False)
     assert r.status == 204
     #
     # get the configuration
     r = management_client.get_device_configuration(device_id)
     data = r.to_dict()
     assert {
         "id": device_id,
         "configured": {},
         "reported": {
             "key": "value",
             "another-key": "another-value",
             "dollar-key": "$",
         },
     } == {k: data[k]
           for k in ("id", "reported", "configured")}
     assert "reported_ts" in data.keys()
     #
     # replace the configuration
     configuration = {
         "key": "update-value",
         "additional-key": "",
     }
     r = client.report_device_configuration(request_body=configuration,
                                            _preload_content=False)
     assert r.status == 204
     #
     # get the configuration
     r = management_client.get_device_configuration(device_id)
     data = r.to_dict()
     assert {
         "id": device_id,
         "configured": {},
         "reported": {
             "key": "update-value",
             "additional-key": ""
         },
     } == {k: data[k]
           for k in ("id", "reported", "configured")}
     assert "reported_ts" in data.keys()
     #
     # remove the configuration
     configuration = {}
     r = client.report_device_configuration(request_body=configuration,
                                            _preload_content=False)
     assert r.status == 204
     #
     # get the configuration
     r = management_client.get_device_configuration(device_id)
     data = r.to_dict()
     assert {
         "id": device_id,
         "reported": {},
         "configured": {}
     } == {k: data[k]
           for k in ("id", "reported", "configured")}
     assert "reported_ts" in data.keys()