def test_json_encoding_basic(self): x = DeviceInfo("123abc", ["192.168.0.121"]) data = x.to_json() info = DeviceInfo.from_json(data) self.assertEqual(info.wwn, "123abc") self.assertEqual(info.addresses, ["192.168.0.121"]) self.assertEqual(info.port, 8123)
def test_json_decoding_basic(self): data = '{ "wwn": "123abc", "addresses": [ "192.168.0.121" ] }' info = DeviceInfo.from_json(data) self.assertEqual(info.wwn, "123abc") self.assertEqual(info.addresses, ["192.168.0.121"]) self.assertEqual(info.port, 8123)
def test_json_decoding_full(self): data = '{ "wwn": "123abc", "addresses": [ "192.168.0.121", "192.168.1.121" ], "port": 9999 }' info = DeviceInfo.from_json(data) self.assertEqual(info.wwn, "123abc") self.assertEqual(info.addresses, ["192.168.0.121", "192.168.1.121"]) self.assertEqual(info.port, 9999)
def test_json_decoding_wwn_missing(self): data = '{ "addresses": [ "192.168.0.121" ] }' with self.assertRaises(ValueError): DeviceInfo.from_json(data)
def test_json_decoding_addresses_missing(self): data = '{ "wwn": "123abc" }' with self.assertRaises(ValueError): DeviceInfo.from_json(data)
def test_json_decoding_addresses_empty(self): data = '{ "wwn": "123abc", "addresses": [] }' with self.assertRaises(ValueError): DeviceInfo.from_json(data)