# Path: microcosm_pubsub/sentry.py
# def default_before_send(event: Dict[str, Any], hint) -> Dict[str, Any]:
#     """
#     Before sending a event to sentry scrub all values that are non-uuid data from the event.
#     Allow python internals such as <method >, <func > etc. and self, cls.
# 
#     """
#     for exception in event["exception"]["values"]:
#         for frame in exception["stacktrace"]["frames"]:
#             for var_name, value in frame["vars"].items():
#                 if not value:
#                     continue
#                 if var_name in ["self", "cls"]:
#                     continue
#                 elif isinstance(value, str):
#                     if value.startswith("<") and value.endswith(">"):
#                         continue
#                     elif var_name.endswith("_id"):
#                         continue
#                     elif value.startswith("http"):
#                         continue
#                 elif isinstance(value, dict):
#                     for key in value.keys():
#                         if key.endswith("_id"):
#                             continue
#                         value[key] = "<redacted>"
#                     continue
#                 frame["vars"][var_name] = "<redacted>"
#     return event
# 
# Path: microcosm_pubsub/tests/sentry_fixture.py



from hamcrest import assert_that, equal_to, is_
from microcosm.api import create_object_graph
from microcosm.decorators import binding
from microcosm_pubsub.sentry import default_before_send
from microcosm_pubsub.tests.sentry_fixture import sample_event
                    "self": "<test.daemon.test_daemon.handlers.test_handler.TestHandler object at 0x10953cbd0>",
                    "something_id": "'1f40066c-f457-41b3-aa4c-72cdac5146e4'",
                    "project_description": "<redacted>",
                    "other_id": "'70375dff-2d46-40c4-a1d1-f5d49a25698d'",
                },
            ),
        ),
    )


def test_custom_before_send():
    @binding("sentry_before_send")
    def custom_before_send_factory(graph):
        def before_send(event, hint):
            return "TESTING"
        return before_send

    def loader(metadata):
        return dict(
            sentry_logging_pubsub=dict(
                dsn="topic",
                enabled=True,
                custom_before_send_func="microcosm_pubsub.tests.test_sentry._test_custom_before_send",
            ),
        )

    graph = create_object_graph("example", testing=True, loader=loader)
    graph.use("sentry_before_send")

    client = graph.sentry_logging_pubsub.client

# Path: microcosm_pubsub/sentry.py
# def default_before_send(event: Dict[str, Any], hint) -> Dict[str, Any]:
#     """
#     Before sending a event to sentry scrub all values that are non-uuid data from the event.
#     Allow python internals such as <method >, <func > etc. and self, cls.
# 
#     """
#     for exception in event["exception"]["values"]:
#         for frame in exception["stacktrace"]["frames"]:
#             for var_name, value in frame["vars"].items():
#                 if not value:
#                     continue
#                 if var_name in ["self", "cls"]:
#                     continue
#                 elif isinstance(value, str):
#                     if value.startswith("<") and value.endswith(">"):
#                         continue
#                     elif var_name.endswith("_id"):
#                         continue
#                     elif value.startswith("http"):
#                         continue
#                 elif isinstance(value, dict):
#                     for key in value.keys():
#                         if key.endswith("_id"):
#                             continue
#                         value[key] = "<redacted>"
#                     continue
#                 frame["vars"][var_name] = "<redacted>"
#     return event
# 
# Path: microcosm_pubsub/tests/sentry_fixture.py



# Path: microcosm_pubsub/tests/test_sentry.py
from hamcrest import assert_that, equal_to, is_
from microcosm.api import create_object_graph
from microcosm.decorators import binding
from microcosm_pubsub.sentry import default_before_send
from microcosm_pubsub.tests.sentry_fixture import sample_event

                    "self": "<test.daemon.test_daemon.handlers.test_handler.TestHandler object at 0x10953cbd0>",
                    "something_id": "'1f40066c-f457-41b3-aa4c-72cdac5146e4'",
                    "project_description": "<redacted>",
                    "other_id": "'70375dff-2d46-40c4-a1d1-f5d49a25698d'",
                },
            ),
        ),
    )


def test_custom_before_send():
    @binding("sentry_before_send")
    def custom_before_send_factory(graph):
        def before_send(event, hint):
            return "TESTING"
        return before_send

    def loader(metadata):
        return dict(
            sentry_logging_pubsub=dict(
                dsn="topic",
                enabled=True,
                custom_before_send_func="microcosm_pubsub.tests.test_sentry._test_custom_before_send",
            ),
        )

    graph = create_object_graph("example", testing=True, loader=loader)
    graph.use("sentry_before_send")

    client = graph.sentry_logging_pubsub.client

    assert_that(client.default_before_send(1, 1), "TESTING")