Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

1.2 KB
Raw Blame
from django.test import SimpleTestCase

from parameterized import parameterized

from products.tasks.backend.mentions import extract_mention_emails


class ExtractMentionEmailsTest(SimpleTestCase):
    @parameterized.expand(
        [
            ("single_mention", "hey @[Ann]([email protected]), thoughts?", {"[email protected]"}),
            (
                "multiple_mentions",
                "@[Ann]([email protected]) and @[Bob Two]([email protected])",
                {"[email protected]", "[email protected]"},
            ),
            ("lowercased_and_deduped", "@[Ann]([email protected]) again @[Ann]([email protected])", {"[email protected]"}),
            ("plain_email_is_not_a_mention", "mail [email protected] directly", set()),
            ("invalid_email_in_token", "@[Ann](not-an-email)", set()),
            ("whitespace_in_email", "@[Ann](ann @example.com)", set()),
            ("bracket_in_name_breaks_token", "@[An[n]([email protected])", set()),
            ("newline_in_name_breaks_token", "@[An\nn]([email protected])", set()),
            ("empty_content", "", set()),
        ]
    )
    def test_extract_mention_emails(self, _name, content, expected):
        assert extract_mention_emails(content) == expected