# Path: microcosm_pubsub/tests/fixtures.py
# class DerivedSchema(PubSubMessageSchema):
#     """
#     A schema that is derived from `PubSubMessageSchema`
# 
#     """
#     MEDIA_TYPE = "application/vnd.microcosm.derived"
# 
#     data = fields.String(required=True)


from json import dumps, loads
from hamcrest import (
    assert_that,
    calling,
    equal_to,
    instance_of,
    is_,
    raises,
)
from marshmallow import ValidationError
from microcosm.api import create_object_graph
from microcosm_pubsub.tests.fixtures import DerivedSchema
    codec = graph.pubsub_message_schema_registry.find(DerivedSchema.MEDIA_TYPE)
    message = dumps({
        "data": "data",
        "mediaType": DerivedSchema.MEDIA_TYPE,
    })
    assert_that(codec.decode(message), is_(equal_to({
        "data": "data",
        "media_type": DerivedSchema.MEDIA_TYPE,
    })))


def test_decode_missing_media_type():
    """
    An invalid message will raise errors.

    """
    graph = create_object_graph("example", testing=True)
    codec = graph.pubsub_message_schema_registry.find(DerivedSchema.MEDIA_TYPE)
    message = dumps({
        "bar": "baz",
    })
    assert_that(calling(codec.decode).with_args(message), raises(ValidationError))


def test_decode_missing_field():
    """
    An invalid message will raise errors.

    """
    graph = create_object_graph("example", testing=True)

# Path: microcosm_pubsub/tests/fixtures.py
# class DerivedSchema(PubSubMessageSchema):
#     """
#     A schema that is derived from `PubSubMessageSchema`
# 
#     """
#     MEDIA_TYPE = "application/vnd.microcosm.derived"
# 
#     data = fields.String(required=True)


# Path: microcosm_pubsub/tests/test_codecs.py
from json import dumps, loads
from hamcrest import (
    assert_that,
    calling,
    equal_to,
    instance_of,
    is_,
    raises,
)
from marshmallow import ValidationError
from microcosm.api import create_object_graph
from microcosm_pubsub.tests.fixtures import DerivedSchema

    codec = graph.pubsub_message_schema_registry.find(DerivedSchema.MEDIA_TYPE)
    message = dumps({
        "data": "data",
        "mediaType": DerivedSchema.MEDIA_TYPE,
    })
    assert_that(codec.decode(message), is_(equal_to({
        "data": "data",
        "media_type": DerivedSchema.MEDIA_TYPE,
    })))


def test_decode_missing_media_type():
    """
    An invalid message will raise errors.

    """
    graph = create_object_graph("example", testing=True)
    codec = graph.pubsub_message_schema_registry.find(DerivedSchema.MEDIA_TYPE)
    message = dumps({
        "bar": "baz",
    })
    assert_that(calling(codec.decode).with_args(message), raises(ValidationError))


def test_decode_missing_field():
    """
    An invalid message will raise errors.

    """
    graph = create_object_graph("example", testing=True)

    codec = graph.pubsub_message_schema_registry.find(DerivedSchema.MEDIA_TYPE)