def test_message_serialization():
    """Test deserializing and serializing a message"""
    msg = Message.deserialize(json.dumps({"@type": TEST_TYPE}),
                              mtc=MessageTrustContext())
    assert msg.type == TEST_TYPE
    assert msg.id is not None
    assert msg.mtc

    assert msg.serialize() == json.dumps({"@type": TEST_TYPE, "@id": msg.id})
def test_message_serialization():
    """ Test deserializing and serializing a message """
    msg = Message.deserialize('{"@type": "%s"}' % TEST_TYPE)
    assert msg.type == TEST_TYPE
    assert msg.id is not None
    assert msg.doc_uri == 'test_type/'
    assert msg.protocol == 'protocol'
    assert msg.version == '1.0'
    assert msg.name == 'test'
    assert msg.version_info == Semver(1, 0, 0)

    assert msg.serialize() == \
        '{"@type": "%s", "@id": "%s"}' % (TEST_TYPE, msg.id)
def test_bad_serialized_message():
    """ Test bad serialized message raises an error on deserialze. """
    with pytest.raises(InvalidMessage):
        Message.deserialize('asdf')
def test_bad_serialized_message():
    """Test bad serialized message raises an error on deserialze."""
    with pytest.raises(ValueError):
        Message.deserialize("asdf")