@@ -199,7 +199,7 @@ def test_should_not_convert_from_json_with_wrong_data_type_in_metric(self):
199199 name = "v1" ,
200200 metric = MetricDataItem (
201201 data_type = MetricDataTypes .DECIMALS_LIST ,
202- value = "-2+3-1" ,
202+ value = [ - 2.0 , 3.0 , - 1.0 ] ,
203203 ),
204204 ),
205205 ],
@@ -214,13 +214,13 @@ def test_should_not_convert_from_json_with_wrong_data_type_in_metric(self):
214214 name = "v1" ,
215215 metric = MetricDataItem (
216216 data_type = MetricDataTypes .BOOLS_LIST ,
217- value = "10010" ,
217+ value = [ True , False , False , True , False ] ,
218218 ),
219219 ),
220220 ],
221221 ),
222222 # (
223- # '[{"t": "123123123"}, {"d": "D1"}, {"m": "v1", "v": ["a", "b", "c"] , "t": "T"}]',
223+ # '[{"t": "123123123"}, {"d": "D1"}, {"m": "v1", "v": "YWJjCg" , "t": "T"}]',
224224 # [
225225 # Item(kind=ItemTypes.TIMESTAMP_MILIS, name="123123123", metric=None),
226226 # Item(kind=ItemTypes.DEVICE_ID, name="D1", metric=None),
@@ -229,7 +229,7 @@ def test_should_not_convert_from_json_with_wrong_data_type_in_metric(self):
229229 # name="v1",
230230 # metric=MetricDataItem(
231231 # data_type=MetricDataTypes.TEXTS_LIST,
232- # value="YWJjCg" ,
232+ # value=["a", "b", "c"] ,
233233 # ),
234234 # ),
235235 # ],
@@ -240,4 +240,17 @@ def test_should_convert_from_json_with_data_type_in_metric(
240240 self , iotext_msg_as_json , expected_result
241241 ):
242242 result = IoTextItemDataBuilder .from_json (iotext_msg_as_json )
243- self .assertTrue (result , expected_result )
243+ self .assertEqual (result , expected_result )
244+
245+ def test_should_iotext_to_json (self ):
246+ expected_json = """[{"t": "1712829010000"}, {"d": "DEV_NAME_003"}, {"m": "xb", "v": false, "t": "b"}, {"m": "xds", "v": [-547, -542, -553, -540, -542, -522, -539, -522, -549, -539, -542, -556, -539, -555, -529, -561, -548, -567, -532, -554, -540, -521, -568, -541, -542], "t": "I"}, {"m": "battery_lvl", "v": 81, "t": "i"}]"""
247+
248+ iotext_example = (
249+ "t|1712829010000,d|DEV_NAME_003,m|xb=b:0,"
250+ "m|xds=I:-547-542-553-540-542-522-539-522-549-539-542-556-539-555"
251+ "-529-561-548-567-532-554-540-521-568-541-542,m|battery_lvl=i:81"
252+ )
253+
254+ result = IoTextItemDataBuilder .iotext_to_json (iotext_example )
255+
256+ self .assertEqual (result , expected_json )
0 commit comments