Example #1
0
def test_name_email():
    class Model(BaseModel):
        v: NameEmail

    assert str(Model(v=NameEmail('foo bar', '*****@*****.**')).v) == 'foo bar <*****@*****.**>'
    assert str(Model(v='foo bar  <*****@*****.**>').v) == 'foo bar <*****@*****.**>'
    assert NameEmail('foo bar', '*****@*****.**') == NameEmail('foo bar', '*****@*****.**')
    assert NameEmail('foo bar', '*****@*****.**') != NameEmail('foo bar', '*****@*****.**')
Example #2
0
def compose(
    *,
    content: str,
    subject: str,
    recipients: NameEmail,
    sender: NameEmail,
    reply_to: NameEmail,
) -> EmailMessage:
    email = EmailMessage()
    email.set_content(content)

    email["Subject"] = subject
    email["From"] = NameEmail(name=reply_to.name, email=sender.email)
    email["To"] = str(recipients)
    email["Reply-To"] = str(reply_to)

    return email
Example #3
0
    snap = 'crackle'


@pytest.mark.parametrize(
    'input,output',
    [
        (UUID('ebcdab58-6eb8-46fb-a190-d07a33e9eac8'),
         '"ebcdab58-6eb8-46fb-a190-d07a33e9eac8"'),
        (IPv4Address('192.168.0.1'), '"192.168.0.1"'),
        (Color('#000'), '"black"'),
        (Color((1, 12, 123)), '"#010c7b"'),
        (SecretStr('abcd'), '"**********"'),
        (SecretStr(''), '""'),
        (SecretBytes(b'xyz'), '"**********"'),
        (SecretBytes(b''), '""'),
        (NameEmail('foo bar',
                   '*****@*****.**'), '"foo bar <*****@*****.**>"'),
        (IPv6Address('::1:0:1'), '"::1:0:1"'),
        (IPv4Interface('192.168.0.0/24'), '"192.168.0.0/24"'),
        (IPv6Interface('2001:db00::/120'), '"2001:db00::/120"'),
        (IPv4Network('192.168.0.0/24'), '"192.168.0.0/24"'),
        (IPv6Network('2001:db00::/120'), '"2001:db00::/120"'),
        (datetime.datetime(2032, 1, 1, 1, 1), '"2032-01-01T01:01:00"'),
        (datetime.datetime(2032, 1, 1, 1, 1, tzinfo=datetime.timezone.utc),
         '"2032-01-01T01:01:00+00:00"'),
        (datetime.datetime(2032, 1, 1), '"2032-01-01T00:00:00"'),
        (datetime.time(12, 34, 56), '"12:34:56"'),
        (datetime.timedelta(days=12, seconds=34,
                            microseconds=56), '1036834.000056'),
        ({1, 2, 3}, '[1, 2, 3]'),
        (frozenset([1, 2, 3]), '[1, 2, 3]'),
        ((v for v in range(4)), '[0, 1, 2, 3]'),
Example #4
0
 def recipient(self) -> NameEmail:
     return NameEmail(self.name, self.email)