22import os
33import re
44import sys
5+ import pytest
56
67from io import StringIO
78from pathlib import Path
89from subprocess import Popen , PIPE
910from email import message_from_string
1011
11- import dkim
1212
1313from aiosmtpd .controller import Controller
1414
15- from .communications import dkim_message , send_message , matchaddr , AutoResponder
15+ try :
16+ import dkim
17+ from .communications import dkim_message , send_message , matchaddr , AutoResponder
18+ except ImportError :
19+ dkim = None
20+
1621from .defaults import SMTP_TO , SMTP_FROM
1722
1823log = logging .getLogger ( __package__ )
6166""" )
6267
6368
69+ @pytest .mark .skipif ( not dkim ,
70+ reason = "DKIM support unavailable; install w/ [invoice] option" )
6471def test_communications_matchaddr ():
6572 assert matchaddr ( "abc+def@xyz" , mailbox = "abc" , domain = "xyz" ) == ("abc" , "def" , "xyz" )
6673 assert matchaddr ( "abc+def@xyz" , domain = "xYz" ) == ("abc" , "def" , "xyz" )
@@ -73,6 +80,8 @@ def test_communications_matchaddr():
7380 assert matchaddr ( "abc+def@xyz" , mailbox = "xxx" ) is None
7481
7582
83+ @pytest .mark .skipif ( not dkim ,
84+ reason = "DKIM support unavailable; install w/ [invoice] option" )
7685def test_communications_dkim ():
7786 log .info ( f"Using DKIM: { dkim_selector } : { dkim_key } " )
7887 if dkim_key :
@@ -135,6 +144,8 @@ def test_communications_dkim():
135144 pass
136145
137146
147+ @pytest .mark .skipif ( not dkim ,
148+ reason = "DKIM support unavailable; install w/ [invoice] option" )
138149def test_communications_autoresponder ( monkeypatch ):
139150 """The Postfix-compatible auto-responder takes an email.Message from stdin, and auto-forwards it
140151 (via a relay; normally the same Postfix installation that it is running within).
@@ -183,8 +194,8 @@ async def handle_DATA(self, server, session, envelope):
183194 controller = Controller ( handler , hostname = 'localhost' , port = 11111 )
184195 controller .start ()
185196
186- # Send the email.Message directly our SMTP daemon, w/ RCTP TO: licensing@dominionrnd.com (taken
187- # from the To: header)
197+ # Send the email.Message directly to our SMTP daemon, w/ RCTP TO: licensing@dominionrnd.com
198+ # (taken from the To: header)
188199 send_message (
189200 msg ,
190201 relay = controller .hostname ,
0 commit comments