def test_list_payload(self, mocker: MockerFixture) -> None:
     data = [{"field1": 5.6, "field2": True}, {"field1": "ab cd", "field2": 42}]
     message = mocker.Mock(node_id='"list"."node"', payload=data)
     assert to_influx(message) == "{0}\n{1}".format(
         "list.node,node_index=0 field1=5.6,field2=True ",
         'list.node,node_index=1 field1="ab cd",field2=42i ',
     )
Esempio n. 2
0
 def test_dict_payload(self, mocker: MockerFixture) -> None:
     data = {
         "field1": 1,
         "field2": "value 2",
         "field3": 1.0,
         "field4": False
     }
     message = mocker.Mock(node_id='"dict"."node"', payload=data)
     expected = 'dict.node field1=1i,field2="value 2",field3=1.0,field4=False '
     assert to_influx(message) == expected
Esempio n. 3
0
 def test_field_value_error(self, mocker: MockerFixture) -> None:
     data = {"field1": 1, "field2": None}
     message = mocker.Mock(node_id='"error"."node"', payload=data)
     with pytest.raises(ValueError, match="None"):
         to_influx(message)
Esempio n. 4
0
 def test_scalar_array_payload(self, mocker: MockerFixture) -> None:
     data = [1, 2, 3]
     message = mocker.Mock(node_id="ScalarArrayNode", payload=data)
     with pytest.raises(UnexpextedScalarError, match=r"ScalarArrayNode"):
         to_influx(message)
Esempio n. 5
0
 def test_scalar_payload(self, mocker: MockerFixture, payload: Any) -> None:
     message = mocker.Mock(node_id="ScalarNode", payload=payload)
     with pytest.raises(UnexpextedScalarError, match=r"ScalarNode"):
         to_influx(message)