Handle absence of notification in 'notifications' command

pull/96/head
Denis Laxalde 2019-02-17 15:02:05 +01:00
rodzic 6360e4d07d
commit 204d4d4138
2 zmienionych plików z 20 dodań i 1 usunięć

Wyświetl plik

@ -545,6 +545,20 @@ def test_notifications(mock_get, capsys):
"",
])
@mock.patch('toot.http.get')
def test_notifications_empty(mock_get, capsys):
mock_get.return_value = MockResponse([])
console.run_command(app, user, 'notifications', [])
mock_get.assert_called_once_with(app, user, '/api/v1/notifications')
out, err = capsys.readouterr()
out = uncolorize(out)
assert not err
assert out == "No notification\n"
@mock.patch('toot.http.post')
def test_notifications_clear(mock_post, capsys):

Wyświetl plik

@ -304,8 +304,13 @@ def notifications(app, user, args):
print_out("<green>Cleared notifications</green>")
return
notifications = api.get_notifications(app, user)
if not notifications:
print_out("<yellow>No notification</yellow>")
return
width = 100
for notification in sorted(api.get_notifications(app, user),
for notification in sorted(notifications,
key=lambda n: datetime.strptime(
n["created_at"], "%Y-%m-%dT%H:%M:%S.%fZ"),
reverse=True):