-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mq-sendmail
: ability to enqueue message which could not be sent imm…
…ediately
- Loading branch information
1 parent
ba25886
commit 20b5e06
Showing
3 changed files
with
45 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,12 +47,14 @@ def inject_example_message(queue_path, sender=b'[email protected]', recipient=Non | |
msg_path = move_message(msg_path, target_folder=target_folder, open_file=False) | ||
return MaildirBackedMsg(msg_path) | ||
|
||
def create_ini(hostname, port, dir_path): | ||
def create_ini(hostname, port, dir_path, *, queue_dir=None): | ||
config_str = '\n'.join([ | ||
'[mqrunner]', | ||
'smtp_hostname = %s' % hostname, | ||
'smtp_port = %d' % port, | ||
]) | ||
if queue_dir: | ||
config_str += f'\nqueue_dir = {queue_dir}' | ||
if not dir_path: | ||
return config_str | ||
config_path = os.path.join(dir_path, 'config.ini') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,9 @@ | |
import pytest | ||
from dotmap import DotMap | ||
from pymta.test_util import SMTPTestHelper | ||
from schwarz.log_utils import l_ | ||
|
||
from schwarz.mailqueue.queue_runner import MaildirBackedMsg, assemble_queue_with_new_messages | ||
from schwarz.mailqueue.testutils import create_ini | ||
|
||
|
||
|
@@ -110,9 +112,35 @@ def _create_alias_file(aliases, dir_path) -> str: | |
return str(aliases_path) | ||
|
||
|
||
def _mq_sendmail(cli_params, msg, *, ctx): | ||
cfg_dir = str(ctx.tmp_path) | ||
config_path = create_ini(ctx.hostname, ctx.listen_port, dir_path=cfg_dir) | ||
def test_mq_sendmail_with_queueing(ctx): | ||
rfc_msg = _example_message(to='[email protected]') | ||
unused_port = ctx.listen_port + 1 | ||
queue_dir = ctx.tmp_path / 'queue' | ||
config_path = create_ini( | ||
ctx.hostname, | ||
port = unused_port, | ||
dir_path = ctx.tmp_path, | ||
queue_dir = queue_dir, | ||
) | ||
_mq_sendmail(['[email protected]'], msg=rfc_msg, config_path=config_path) | ||
|
||
received_queue = ctx.mta.get_received_messages() | ||
assert received_queue.qsize() == 0 | ||
|
||
fs_queue = assemble_queue_with_new_messages(queue_dir, log=l_(None)) | ||
assert fs_queue.qsize() == 1 | ||
path_queued_msg = fs_queue.get() | ||
msg = MaildirBackedMsg(path_queued_msg) | ||
assert msg.to_addrs == ('[email protected]',) | ||
assert msg.msg_id is None # not added automatically | ||
assert msg.retries == 0 | ||
assert msg.msg_bytes == rfc_msg.encode('utf-8') | ||
|
||
|
||
def _mq_sendmail(cli_params, msg, *, ctx=None, config_path=None): | ||
if config_path is None: | ||
cfg_dir = str(ctx.tmp_path) | ||
config_path = create_ini(ctx.hostname, ctx.listen_port, dir_path=cfg_dir) | ||
|
||
cli_params = [f'--config={config_path}'] + cli_params | ||
cmd = [sys.executable, '-m', 'schwarz.mailqueue.mq_sendmail'] + cli_params | ||
|