Add a --clear option to "notifications" command
This commit is contained in:
parent
5174a751f2
commit
6360e4d07d
4 changed files with 27 additions and 1 deletions
|
@ -546,6 +546,17 @@ def test_notifications(mock_get, capsys):
|
|||
])
|
||||
|
||||
|
||||
@mock.patch('toot.http.post')
|
||||
def test_notifications_clear(mock_post, capsys):
|
||||
console.run_command(app, user, 'notifications', ['--clear'])
|
||||
out, err = capsys.readouterr()
|
||||
out = uncolorize(out)
|
||||
|
||||
mock_post.assert_called_once_with(app, user, '/api/v1/notifications/clear')
|
||||
assert not err
|
||||
assert out == 'Cleared notifications\n'
|
||||
|
||||
|
||||
def u(user_id, access_token="abc"):
|
||||
username, instance = user_id.split("@")
|
||||
return {
|
||||
|
|
|
@ -260,6 +260,10 @@ def get_notifications(app, user):
|
|||
return http.get(app, user, '/api/v1/notifications').json()
|
||||
|
||||
|
||||
def clear_notifications(app, user):
|
||||
http.post(app, user, '/api/v1/notifications/clear')
|
||||
|
||||
|
||||
def get_instance(domain, scheme="https"):
|
||||
url = "{}://{}/api/v1/instance".format(scheme, domain)
|
||||
return http.anon_get(url).json()
|
||||
|
|
|
@ -299,6 +299,11 @@ def instance(app, user, args):
|
|||
|
||||
|
||||
def notifications(app, user, args):
|
||||
if args.clear:
|
||||
api.clear_notifications(app, user)
|
||||
print_out("<green>Cleared notifications</green>")
|
||||
return
|
||||
|
||||
width = 100
|
||||
for notification in sorted(api.get_notifications(app, user),
|
||||
key=lambda n: datetime.strptime(
|
||||
|
|
|
@ -170,7 +170,13 @@ READ_COMMANDS = [
|
|||
Command(
|
||||
name="notifications",
|
||||
description="Notifications for logged in user",
|
||||
arguments=[],
|
||||
arguments=[
|
||||
(["--clear"], {
|
||||
"help": "delete all notifications from the server",
|
||||
"action": 'store_true',
|
||||
"default": False,
|
||||
}),
|
||||
],
|
||||
require_auth=True,
|
||||
),
|
||||
Command(
|
||||
|
|
Loading…
Reference in a new issue