parent
3cba9680f5
commit
2a5d903eba
@ -0,0 +1,29 @@ |
||||
import click |
||||
|
||||
from ..utils import http_post, http_delete |
||||
from .utils import handle_sync_response |
||||
|
||||
|
||||
@click.group(short_help='Manage mailing list subscriptions') |
||||
def mailman(): |
||||
pass |
||||
|
||||
|
||||
@mailman.command(short_help='Subscribe a member to a mailing list') |
||||
@click.argument('username') |
||||
@click.argument('mailing_list') |
||||
def subscribe(username, mailing_list): |
||||
click.confirm(f'Are you sure you want to subscribe {username} to {mailing_list}?', abort=True) |
||||
resp = http_post(f'/api/mailman/{mailing_list}/{username}') |
||||
handle_sync_response(resp) |
||||
click.echo('Done.') |
||||
|
||||
|
||||
@mailman.command(short_help='Unsubscribe a member from a mailing list') |
||||
@click.argument('username') |
||||
@click.argument('mailing_list') |
||||
def unsubscribe(username, mailing_list): |
||||
click.confirm(f'Are you sure you want to unsubscribe {username} from {mailing_list}?', abort=True) |
||||
resp = http_delete(f'/api/mailman/{mailing_list}/{username}') |
||||
handle_sync_response(resp) |
||||
click.echo('Done.') |
@ -0,0 +1,23 @@ |
||||
from click.testing import CliRunner |
||||
|
||||
from ceo.cli import cli |
||||
|
||||
|
||||
def test_mailman_subscribe(cli_setup, mock_mailman_server): |
||||
mock_mailman_server.clear() |
||||
runner = CliRunner() |
||||
result = runner.invoke(cli, ['mailman', 'subscribe', 'test_1', 'exec'], input='y\n') |
||||
expected = ( |
||||
"Are you sure you want to subscribe test_1 to exec? [y/N]: y\n" |
||||
"Done.\n" |
||||
) |
||||
assert result.exit_code == 0 |
||||
assert result.output == expected |
||||
|
||||
result = runner.invoke(cli, ['mailman', 'unsubscribe', 'test_1', 'exec'], input='y\n') |
||||
expected = ( |
||||
"Are you sure you want to unsubscribe test_1 from exec? [y/N]: y\n" |
||||
"Done.\n" |
||||
) |
||||
assert result.exit_code == 0 |
||||
assert result.output == expected |
Loading…
Reference in new issue