Ejemplo n.º 1
0
    def test_deleted(self):
        assert_that(
            deleted("Foo.Bar"),
            is_(equal_to(
                "application/vnd.globality.pubsub._.deleted.foo.bar")),
        )

        assert_that(
            self.graph.pubsub_message_schema_registry.find(
                "application/vnd.globality.pubsub._.deleted.foo.bar", ).schema,
            is_(instance_of(IdentityMessageSchema)),
        )
    def test_deleted(self):
        assert_that(
            deleted("Foo.Bar"),
            is_(equal_to("application/vnd.globality.pubsub._.deleted.foo.bar")),
        )

        assert_that(
            self.graph.pubsub_message_schema_registry.find(
                "application/vnd.globality.pubsub._.deleted.foo.bar",
            ).schema,
            is_(instance_of(IdentityMessageSchema)),
        )
Ejemplo n.º 3
0
def test_dispatch_by_identity_convention():
    """
    Message dispatch can use this convention.

    """
    daemon = ExampleDaemon.create_for_testing()
    graph = daemon.graph

    media_type = deleted(Foo)

    assert_that(
        graph.pubsub_message_schema_registry.find(media_type).schema,
        is_(instance_of(IdentityMessageSchema)),
    )

    assert_that(
        graph.sqs_message_handler_registry.find(media_type, daemon.bound_handlers),
        is_(equal_to(noop_handler)),
    )
Ejemplo n.º 4
0
def test_publish_by_identity_convention():
    """
    Message publishing can use this convention.

    """
    def loader(metadata):
        return dict(sns_topic_arns=dict(default="default", ))

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

    published_time = time()
    with patch("microcosm_pubsub.producer.time") as mocked_time:
        mocked_time.return_value = published_time
        graph.sns_producer.produce(deleted("foo"), id="1", opaque_data=dict())

    assert_that(graph.sns_producer.sns_client.publish.call_count,
                is_(equal_to(1)))
    assert_that(graph.sns_producer.sns_client.publish.call_args[1]["TopicArn"],
                is_(equal_to("default")))
    assert_that(
        loads(graph.sns_producer.sns_client.publish.call_args[1]["Message"]),
        is_(
            equal_to({
                "mediaType": "application/vnd.globality.pubsub._.deleted.foo",
                "id": "1",
                "opaqueData": {
                    "X-Request-Published": str(published_time),
                },
            })))
    assert_that(
        graph.sns_producer.sns_client.publish.call_args[1]
        ["MessageAttributes"],
        is_(
            equal_to({
                "media_type": {
                    "DataType": "String",
                    "StringValue":
                    "application/vnd.globality.pubsub._.deleted.foo"
                },
            })))
Ejemplo n.º 5
0
def test_publish_by_identity_convention():
    """
    Message publishing can use this convention.

    """
    def loader(metadata):
        return dict(
            sns_topic_arns=dict(
                default="default",
            )
        )

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

    graph.sns_producer.produce(deleted("foo"), id="1", opaque_data=dict())

    assert_that(graph.sns_producer.sns_client.publish.call_count, is_(equal_to(1)))
    assert_that(graph.sns_producer.sns_client.publish.call_args[1]["TopicArn"], is_(equal_to("default")))
    assert_that(loads(graph.sns_producer.sns_client.publish.call_args[1]["Message"]), is_(equal_to({
        "mediaType": "application/vnd.globality.pubsub._.deleted.foo",
        "id": "1",
        "opaqueData": {},
    })))
Ejemplo n.º 6
0

@schema
class DuckTypeSchema(Schema):
    """
    A duck typed schema

    """
    MEDIA_TYPE = "application/vnd.microcosm.duck"

    quack = fields.String()


@handles(DuckTypeSchema)
@handles(created("foo"))
@handles(deleted("foo"))
@handles(DerivedSchema.MEDIA_TYPE)
def noop_handler(message):
    return True


@handles(created("IgnoredResource"))
def skipping_handler(message):
    raise SkipMessage("Failed")


class ExampleDaemon(ConsumerDaemon):
    @property
    def name(self):
        return "example"
Ejemplo n.º 7
0

@schema
class DuckTypeSchema(Schema):
    """
    A duck typed schema

    """
    MEDIA_TYPE = "application/vnd.microcosm.duck"

    quack = fields.String()


@handles(DuckTypeSchema)
@handles(created("foo"))
@handles(deleted("foo"))
@handles(DerivedSchema.MEDIA_TYPE)
def noop_handler(message):
    return True


@handles(created("IgnoredResource"))
def skipping_handler(message):
    raise SkipMessage("Failed")


class ExampleDaemon(ConsumerDaemon):

    @property
    def name(self):
        return "example"
Ejemplo n.º 8
0

@schema
class DuckTypeSchema(Schema):
    """
    A duck typed schema

    """
    MEDIA_TYPE = "application/vnd.microcosm.duck"

    quack = fields.String()


@handles(DuckTypeSchema)
@handles(created("Foo"))
@handles(deleted("Foo"))
@handles(DerivedSchema.MEDIA_TYPE)
def noop_handler(message):
    return True


@handles(created("IgnoredResource"))
def skipping_handler(message):
    raise SkipMessage("Failed")


class ExampleDaemon(ConsumerDaemon):
    @property
    def name(self):
        return "example"