Projet

Général

Profil

0002-misc-tests-for-mail-redirection-36977.patch

Lauréline Guérin, 21 septembre 2021 18:44

Télécharger (2,2 ko)

Voir les différences:

Subject: [PATCH 2/4] misc: tests for mail redirection (#36977)

 tests/test_emails.py | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
tests/test_emails.py
54 54
    )
55 55

  
56 56

  
57
def test_email_recipients(emails):
58
    pub = create_temporary_pub()
59
    send_email('test', mail_body='Hello', email_rcpt='test@localhost', want_html=False)
60
    assert emails.count() == 1
61
    assert emails.emails['test']['email_rcpt'] == ['test@localhost']
62

  
63
    pub.cfg['debug'] = {'mail_redirection': 'redirection@localhost'}
64
    emails.empty()
65
    send_email('test', mail_body='Hello', email_rcpt='test@localhost', want_html=False)
66
    assert emails.count() == 1
67
    assert emails.emails['test']['email_rcpt'] == ['redirection@localhost']
68

  
69
    emails.empty()
70
    send_email(
71
        'test', mail_body='Hello', email_rcpt='test@localhost', want_html=False, ignore_mail_redirection=True
72
    )
73
    assert emails.count() == 1
74
    assert emails.emails['test']['email_rcpt'] == ['test@localhost']
75

  
76
    orig_environ = os.environ.copy()
77
    try:
78
        os.environ['QOMMON_MAIL_REDIRECTION'] = 'qommon.redirection@localhost'
79
        emails.empty()
80
        send_email('test', mail_body='Hello', email_rcpt='test@localhost', want_html=False)
81
        assert emails.count() == 1
82
        assert emails.emails['test']['email_rcpt'] == ['qommon.redirection@localhost']
83

  
84
        emails.empty()
85
        send_email(
86
            'test',
87
            mail_body='Hello',
88
            email_rcpt='test@localhost',
89
            want_html=False,
90
            ignore_mail_redirection=True,
91
        )
92
        assert emails.count() == 1
93
        assert emails.emails['test']['email_rcpt'] == ['test@localhost']
94
    finally:
95
        os.environ = orig_environ
96

  
97

  
57 98
@pytest.mark.skipif('docutils is None')
58 99
def test_email_signature_rst(emails):
59 100
    pub = create_temporary_pub()
60
-