# Path: microcosm_pubsub/message.py
# class SQSMessage:
#     """
#     SQS message wrapper.
# 
#     """
#     def __init__(self,
#                  consumer,
#                  content,
#                  media_type,
#                  message_id,
#                  receipt_handle,
#                  topic_arn=None,
#                  approximate_receive_count=None,
#                  handler=None):
#         self.consumer = consumer
#         self.content = content
#         self.media_type = media_type
#         self.message_id = message_id
#         self.receipt_handle = receipt_handle
#         self.topic_arn = topic_arn
#         self.approximate_receive_count = approximate_receive_count
#         self.handler = handler
# 
#     def ack(self):
#         """
#         Acknowledge this message was processed successfully.
# 
#         """
#         self.consumer.ack(self)
# 
#     def nack(self, visibility_timeout_seconds=None):
#         """
#         Acknowledge this message was NOT processed successfully.
# 
#         """
#         self.consumer.nack(self, visibility_timeout_seconds)
# 
#     @property
#     def opaque_data(self):
#         if not self.content:
#             return dict()
#         return self.content.get("opaque_data", {})
# 
#     @property
#     def ttl(self):
#         if TTL_KEY not in self.opaque_data:
#             return None
#         return int(self.opaque_data[TTL_KEY])
# 
#     @property
#     def uri(self):
#         if not self.content:
#             return None
#         return self.content.get("uri")
# 
# Path: microcosm_pubsub/tests/fixtures.py
# class ExampleDaemon(ConsumerDaemon):
# 
#     @property
#     def name(self):
#         return "example"
# 
#     @property
#     def components(self):
#         return super().components + [
#             "noop_handler",
#         ]


from hamcrest import assert_that, has_entries
from microcosm_pubsub.message import SQSMessage
from microcosm_pubsub.tests.fixtures import ExampleDaemon
    def test_includes_message_uri(self):
        with self.graph.opaque.initialize(self.graph.sqs_message_context, self.message):
            assert_that(
                self.graph.opaque.as_dict(),
                has_entries(
                    uri=MESSAGE_URI,
                ),
            )

    def test_sets_initial_ttl(self):
        with self.graph.opaque.initialize(self.graph.sqs_message_context, self.message):
            assert_that(
                self.graph.opaque.as_dict(),
                has_entries({
                    "X-Request-Ttl": "31",
                }),
            )

    def test_updates_existing_ttl(self):
        self.message.opaque_data["X-Request-Ttl"] = "10"

        with self.graph.opaque.initialize(self.graph.sqs_message_context, self.message):
            assert_that(
                self.graph.opaque.as_dict(),
                has_entries({
                    "X-Request-Ttl": "9",
                }),
            )

    def test_handle_existing_opaque_message_id(self):

# Path: microcosm_pubsub/message.py
# class SQSMessage:
#     """
#     SQS message wrapper.
# 
#     """
#     def __init__(self,
#                  consumer,
#                  content,
#                  media_type,
#                  message_id,
#                  receipt_handle,
#                  topic_arn=None,
#                  approximate_receive_count=None,
#                  handler=None):
#         self.consumer = consumer
#         self.content = content
#         self.media_type = media_type
#         self.message_id = message_id
#         self.receipt_handle = receipt_handle
#         self.topic_arn = topic_arn
#         self.approximate_receive_count = approximate_receive_count
#         self.handler = handler
# 
#     def ack(self):
#         """
#         Acknowledge this message was processed successfully.
# 
#         """
#         self.consumer.ack(self)
# 
#     def nack(self, visibility_timeout_seconds=None):
#         """
#         Acknowledge this message was NOT processed successfully.
# 
#         """
#         self.consumer.nack(self, visibility_timeout_seconds)
# 
#     @property
#     def opaque_data(self):
#         if not self.content:
#             return dict()
#         return self.content.get("opaque_data", {})
# 
#     @property
#     def ttl(self):
#         if TTL_KEY not in self.opaque_data:
#             return None
#         return int(self.opaque_data[TTL_KEY])
# 
#     @property
#     def uri(self):
#         if not self.content:
#             return None
#         return self.content.get("uri")
# 
# Path: microcosm_pubsub/tests/fixtures.py
# class ExampleDaemon(ConsumerDaemon):
# 
#     @property
#     def name(self):
#         return "example"
# 
#     @property
#     def components(self):
#         return super().components + [
#             "noop_handler",
#         ]


# Path: microcosm_pubsub/tests/test_context.py
from hamcrest import assert_that, has_entries
from microcosm_pubsub.message import SQSMessage
from microcosm_pubsub.tests.fixtures import ExampleDaemon

    def test_includes_message_uri(self):
        with self.graph.opaque.initialize(self.graph.sqs_message_context, self.message):
            assert_that(
                self.graph.opaque.as_dict(),
                has_entries(
                    uri=MESSAGE_URI,
                ),
            )

    def test_sets_initial_ttl(self):
        with self.graph.opaque.initialize(self.graph.sqs_message_context, self.message):
            assert_that(
                self.graph.opaque.as_dict(),
                has_entries({
                    "X-Request-Ttl": "31",
                }),
            )

    def test_updates_existing_ttl(self):
        self.message.opaque_data["X-Request-Ttl"] = "10"

        with self.graph.opaque.initialize(self.graph.sqs_message_context, self.message):
            assert_that(
                self.graph.opaque.as_dict(),
                has_entries({
                    "X-Request-Ttl": "9",
                }),
            )

    def test_handle_existing_opaque_message_id(self):

        self.message = SQSMessage(