File: test_esmtp_utils.py

package info (click to toggle)
aiosmtplib 4.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 572 kB
  • sloc: python: 5,516; makefile: 20; sh: 6
file content (73 lines) | stat: -rw-r--r-- 1,556 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
Tests for ESMTP extension parsing.
"""

from aiosmtplib.esmtp import parse_esmtp_extensions


def test_basic_extension_parsing() -> None:
    response = """size.does.matter.af.MIL offers FIFTEEN extensions:
8BITMIME
PIPELINING
DSN
ENHANCEDSTATUSCODES
EXPN
HELP
SAML
SEND
SOML
TURN
XADR
XSTA
ETRN
XGEN
SIZE 51200000
    """
    extensions, auth_types = parse_esmtp_extensions(response)

    assert "size" in extensions
    assert extensions["size"] == "51200000"
    assert "saml" in extensions
    assert "size.does.matter.af.mil" not in extensions
    assert auth_types == []


def test_no_extension_parsing() -> None:
    response = """size.does.matter.af.MIL offers ZERO extensions:
    """
    extensions, auth_types = parse_esmtp_extensions(response)

    assert extensions == {}
    assert auth_types == []


def test_auth_type_parsing() -> None:
    response = """blah blah blah
AUTH FOO BAR
    """
    extensions, auth_types = parse_esmtp_extensions(response)

    assert "foo" in auth_types
    assert "bar" in auth_types
    assert "bogus" not in auth_types


def test_old_school_auth_type_parsing() -> None:
    response = """blah blah blah
AUTH=PLAIN
    """
    extensions, auth_types = parse_esmtp_extensions(response)

    assert "plain" in auth_types
    assert "cram-md5" not in auth_types


def test_mixed_auth_type_parsing() -> None:
    response = """blah blah blah
AUTH=PLAIN
AUTH CRAM-MD5
    """
    extensions, auth_types = parse_esmtp_extensions(response)

    assert "plain" in auth_types
    assert "cram-md5" in auth_types