Skip to content

Commit

Permalink
mq-run/mq-send-test: use default config by default
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixSchwarz committed Aug 5, 2024
1 parent 4b0a632 commit d3f12be
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ was_queued = (getattr(send_result, 'queued', None) is not False)

The `mq-run` script sends all queued messages to an SMTP server:

mq-run /path/to/config.ini /path/to/queue
mq-run --config=/path/to/config.ini /path/to/queue

If you want to test your configuration you can send a test message to ensure
the mail flow is set up correctly:

mq-send-test /path/to/config.ini /path/to/queue [email protected]
mq-send-test --config=/path/to/config.ini /path/to/queue [email protected]

### Configuration (mq-run)

Expand Down
8 changes: 5 additions & 3 deletions schwarz/mailqueue/cli/one_shot_queue_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import docopt

from ..app_helpers import guess_config_path
from ..queue_runner import one_shot_queue_run


Expand All @@ -16,13 +17,14 @@ def one_shot_queue_run_main(argv=sys.argv, return_rc_code=False):
"""mq-run.
Usage:
mq-run [options] <config> <queue_dir>
mq-run [options] <queue_dir>
Options:
--verbose -v more verbose program output
-C, --config=<CFG> Path to the config file
--verbose -v more verbose program output
"""
arguments = docopt.docopt(one_shot_queue_run_main.__doc__, argv=argv[1:])
config_path = arguments['<config>']
config_path = guess_config_path(arguments['--config'])
queue_dir = arguments['<queue_dir>']
cli_options = {
'verbose': arguments['--verbose'],
Expand Down
8 changes: 5 additions & 3 deletions schwarz/mailqueue/cli/send_test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import docopt

from ..app_helpers import guess_config_path
from ..mailflow_check import send_test_message


Expand All @@ -18,15 +19,16 @@ def send_test_message_main(argv=sys.argv, return_rc_code=False):
Send a test message to ensure all SMTP credentials are correct.
Usage:
mq-send-test [options] <config> --to=EMAIL
mq-send-test [options] --to=EMAIL
Options:
--verbose -v more verbose program output
-C, --config=<CFG> Path to the config file
--quiet suppress (most) logging
--from=FROM sender email address
--verbose -v more verbose program output
"""
arguments = docopt.docopt(send_test_message_main.__doc__, argv=argv[1:])
config_path = arguments['<config>']
config_path = guess_config_path(arguments['--config'])
cli_options = {
'verbose': arguments['--verbose'],
'recipient': arguments['--to'],
Expand Down
4 changes: 2 additions & 2 deletions tests/mq_run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_mq_runner_can_load_plugins(tmp_path):
inject_plugin_into_working_set('testplugin', fake_plugin)
config_path = create_ini('host.example', port=12345, dir_path=str(tmp_path))

cmd = ['mq-run', config_path, queue_basedir]
cmd = ['mq-run', f'--config={config_path}', queue_basedir]
mailer = DebugMailer(simulate_failed_sending=True)
with mock.patch('schwarz.mailqueue.queue_runner.init_smtp_mailer', new=lambda s: mailer):
rc = one_shot_queue_run_main(argv=cmd, return_rc_code=True)
Expand All @@ -59,7 +59,7 @@ def test_mq_runner_works_without_plugins(tmp_path):
inject_example_message(queue_basedir)
config_path = create_ini('host.example', port=12345, dir_path=str(tmp_path))

cmd = ['mq-run', config_path, queue_basedir]
cmd = ['mq-run', f'--config={config_path}', queue_basedir]
mailer = DebugMailer(simulate_failed_sending=True)
with mock.patch('schwarz.mailqueue.queue_runner.init_smtp_mailer', new=lambda s: mailer):
rc = one_shot_queue_run_main(argv=cmd, return_rc_code=True)
Expand Down
8 changes: 7 additions & 1 deletion tests/mq_send_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ def ctx():
def test_mq_send_test_can_send_test_message(ctx, tmp_path):
config_path = create_ini(ctx.hostname, ctx.listen_port, dir_path=str(tmp_path))

cmd = ['mq-send-test', config_path, '--quiet', '[email protected]', '[email protected]'] # noqa: E501 (line too long)
cmd = [
'mq-send-test',
f'--config={config_path}',
'--quiet',
'[email protected]',
'[email protected]',
]
rc = send_test_message_main(argv=cmd, return_rc_code=True)
assert rc == 0

Expand Down

0 comments on commit d3f12be

Please sign in to comment.