def from_json(cls, json_obj): if type(json_obj) == str: dct = json.loads(json_obj) elif type(json_obj) == dict: dct = json_obj return cls( operation=Operation.from_json(dct['operation']), usb_device=UsbDevice.from_json(dct['usb_device']) )
def test_serialize_deserialize(self): """Operation serialized and deserialized results in the same operation""" operation = Operation('add') new_operation = Operation.deserialize(operation.serialize()) self.assertEqual(operation, new_operation)