mirror of
https://github.com/ihabunek/toot
synced 2025-01-27 09:41:26 +01:00
Handle absence of notification in 'notifications' command
This commit is contained in:
parent
6360e4d07d
commit
204d4d4138
@ -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')
|
@mock.patch('toot.http.post')
|
||||||
def test_notifications_clear(mock_post, capsys):
|
def test_notifications_clear(mock_post, capsys):
|
||||||
|
@ -304,8 +304,13 @@ def notifications(app, user, args):
|
|||||||
print_out("<green>Cleared notifications</green>")
|
print_out("<green>Cleared notifications</green>")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
notifications = api.get_notifications(app, user)
|
||||||
|
if not notifications:
|
||||||
|
print_out("<yellow>No notification</yellow>")
|
||||||
|
return
|
||||||
|
|
||||||
width = 100
|
width = 100
|
||||||
for notification in sorted(api.get_notifications(app, user),
|
for notification in sorted(notifications,
|
||||||
key=lambda n: datetime.strptime(
|
key=lambda n: datetime.strptime(
|
||||||
n["created_at"], "%Y-%m-%dT%H:%M:%S.%fZ"),
|
n["created_at"], "%Y-%m-%dT%H:%M:%S.%fZ"),
|
||||||
reverse=True):
|
reverse=True):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user