def test_proto_serialization() -> None: """Tests that default Address serialization works as expected - to Protobuf""" uid = UID(value=uuid.UUID(int=333779996850170035686993356951732753684)) loc = SpecificLocation(id=uid, name="Test Location") obj = Address( name="Test Address", network=loc, domain=loc, device=loc, vm=loc, ) blob = Address.get_protobuf_schema()( name="Test Address", has_network=True, has_domain=True, has_device=True, has_vm=True, network=loc.serialize(), domain=loc.serialize(), device=loc.serialize(), vm=loc.serialize(), ) assert obj.proto() == blob assert obj.to_proto() == blob assert obj.serialize(to_proto=True) == blob
def test_partial_serialization_and_deserialization() -> None: """Test that addresses with only some attributes serialize and deserialize correctly/""" an_id = UID(value=uuid.UUID(int=333779996850170035686993356951732753684)) obj = Address( # network=SpecificLocation(id=an_id), domain=SpecificLocation(id=an_id), device=SpecificLocation(id=an_id), vm=SpecificLocation(id=an_id), ) assert obj == sy.deserialize(blob=obj.serialize()) obj = Address( network=SpecificLocation(id=an_id), # domain=SpecificLocation(id=an_id), device=SpecificLocation(id=an_id), vm=SpecificLocation(id=an_id), ) blob = obj.to_proto() assert obj == sy.deserialize(blob=blob) obj = Address( network=SpecificLocation(id=an_id), domain=SpecificLocation(id=an_id), # device=SpecificLocation(id=an_id), vm=SpecificLocation(id=an_id), ) blob = obj.to_proto() assert obj == sy.deserialize(blob=blob) obj = Address( network=SpecificLocation(id=an_id), domain=SpecificLocation(id=an_id), device=SpecificLocation(id=an_id), # vm=SpecificLocation(id=an_id) ) blob = obj.to_proto() assert obj == sy.deserialize(blob=blob)
def test_default_serialization_and_deserialization() -> None: """Tests that default Address serde works as expected - to Protobuf""" an_id = UID(value=uuid.UUID(int=333779996850170035686993356951732753684)) obj = Address( network=SpecificLocation(id=an_id), domain=SpecificLocation(id=an_id), device=SpecificLocation(id=an_id), vm=SpecificLocation(id=an_id), ) blob = obj.to_proto() assert obj.serialize() == blob assert obj == sy.deserialize(blob=blob)