diff --git a/tests/test_console.py b/tests/test_console.py index 7258e9b..50efdad 100644 --- a/tests/test_console.py +++ b/tests/test_console.py @@ -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): diff --git a/toot/commands.py b/toot/commands.py index 3805589..d0f5f2a 100644 --- a/toot/commands.py +++ b/toot/commands.py @@ -304,8 +304,13 @@ def notifications(app, user, args): print_out("Cleared notifications") return + notifications = api.get_notifications(app, user) + if not notifications: + print_out("No notification") + 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):