lingo: prevent unexpected output in lingo-poll-backend (#53833)

This command is used with cron, so any output would produce unwanted
mails.
This commit is contained in:
Benjamin Dauvergne 2021-05-06 19:29:16 +02:00
parent 0853b3152a
commit 2e6b13399f
2 changed files with 22 additions and 19 deletions

View File

@ -66,21 +66,22 @@ class Command(BaseCommand):
backends = [backend]
else:
backends = [backend for backend in qs if backend.can_poll_backend()]
if not backends:
raise CommandError('no backend found.')
if not all_backends and interactive:
print('Choose backend by slug:')
while True:
for backend in backends:
print(' - %s: %s' % (backend.slug, backend))
print('> ', end=' ')
slug = input().strip()
if not slug:
continue
filtered_backends = qs.filter(slug__icontains=slug)
if filtered_backends:
backends = filtered_backends
break
if not all_backends:
if backends and interactive:
print('Choose backend by slug:')
while True:
for backend in backends:
print(' - %s: %s' % (backend.slug, backend))
print('> ', end=' ')
slug = input().strip()
if not slug:
continue
filtered_backends = qs.filter(slug__icontains=slug)
if filtered_backends:
backends = filtered_backends
break
else:
return
for backend in backends:
if verbosity >= 1:

View File

@ -2122,10 +2122,12 @@ class TestPolling:
with pytest.raises(CommandError):
call_command('lingo-poll-backend', backend='coin')
with transaction.atomic():
PaymentBackend.objects.all().delete()
with pytest.raises(CommandError):
call_command('lingo-poll-backend', all_backends=True)
def test_no_backend(self, capsys):
PaymentBackend.objects.all().delete()
call_command('lingo-poll-backend', verbosity=0, interactive=False, all_backends=True)
captured = capsys.readouterr()
assert captured.out == ''
assert captured.err == ''
class TestRecentTransactionsCell:
@pytest.fixture(autouse=True)