MCPcopy
hub / github.com/django/django / test_sanitize_address

Method test_sanitize_address

tests/mail/tests.py:2782–2874  ·  view source on GitHub ↗

Email addresses are properly sanitized.

(self)

Source from the content-addressed store, hash-verified

2780
2781 @ignore_warnings(category=RemovedInDjango70Warning)
2782 def test_sanitize_address(self):
2783 """Email addresses are properly sanitized."""
2784 # Tests the internal sanitize_address() function. Many of these cases
2785 # are duplicated in test_address_header_handling(), which verifies
2786 # headers in the generated message.
2787 from django.core.mail.message import sanitize_address
2788
2789 for email_address, encoding, expected_result in (
2790 # ASCII addresses.
2791 ("to@example.com", "ascii", "to@example.com"),
2792 ("to@example.com", "utf-8", "to@example.com"),
2793 (("A name", "to@example.com"), "ascii", "A name <to@example.com>"),
2794 (
2795 ("A name", "to@example.com"),
2796 "utf-8",
2797 "A name <to@example.com>",
2798 ),
2799 ("localpartonly", "ascii", "localpartonly"),
2800 # ASCII addresses with display names.
2801 ("A name <to@example.com>", "ascii", "A name <to@example.com>"),
2802 ("A name <to@example.com>", "utf-8", "A name <to@example.com>"),
2803 ('"A name" <to@example.com>', "ascii", "A name <to@example.com>"),
2804 ('"A name" <to@example.com>', "utf-8", "A name <to@example.com>"),
2805 # Unicode addresses: IDNA encoded domain supported per RFC-5890.
2806 ("to@éxample.com", "utf-8", "to@xn--xample-9ua.com"),
2807 # The next three cases should be removed when fixing #35713.
2808 # (An 'encoded-word' localpart is prohibited by RFC-2047, and not
2809 # supported by any known mail service.)
2810 ("tó@example.com", "utf-8", "=?utf-8?b?dMOz?=@example.com"),
2811 (
2812 ("Tó Example", "tó@example.com"),
2813 "utf-8",
2814 "=?utf-8?q?T=C3=B3_Example?= <=?utf-8?b?dMOz?=@example.com>",
2815 ),
2816 (
2817 "Tó Example <tó@example.com>",
2818 "utf-8",
2819 # (Not RFC-2047 compliant.)
2820 "=?utf-8?q?T=C3=B3_Example?= <=?utf-8?b?dMOz?=@example.com>",
2821 ),
2822 # IDNA addresses with display names.
2823 (
2824 "To Example <to@éxample.com>",
2825 "ascii",
2826 "To Example <to@xn--xample-9ua.com>",
2827 ),
2828 (
2829 "To Example <to@éxample.com>",
2830 "utf-8",
2831 "To Example <to@xn--xample-9ua.com>",
2832 ),
2833 # Addresses with two @ signs.
2834 ('"to@other.com"@example.com', "utf-8", r'"to@other.com"@example.com'),
2835 (
2836 '"to@other.com" <to@example.com>',
2837 "utf-8",
2838 '"to@other.com" <to@example.com>',
2839 ),

Callers

nothing calls this directly

Calls 1

sanitize_addressFunction · 0.90

Tested by

no test coverage detected