From d6f57284867e7d333ab5205ab741fc1501bbf14b Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Wed, 7 Dec 2022 14:59:06 +0100 Subject: [PATCH] Don't send null parameters when posting fixes #250 --- tests/test_console.py | 9 ++------- toot/api.py | 12 +++++++----- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/tests/test_console.py b/tests/test_console.py index 56e127c..d912033 100644 --- a/tests/test_console.py +++ b/tests/test_console.py @@ -42,11 +42,7 @@ def test_post_defaults(mock_post, mock_uuid, capsys): 'status': 'Hello world', 'visibility': 'public', 'media_ids': [], - 'sensitive': "false", - 'spoiler_text': None, - 'in_reply_to_id': None, - 'language': None, - 'scheduled_at': None, + 'sensitive': False, }, headers={"Idempotency-Key": "rock-on"}) out, err = capsys.readouterr() @@ -78,11 +74,10 @@ def test_post_with_options(mock_post, mock_uuid, capsys): 'status': 'Hello world', 'media_ids': [], 'visibility': 'unlisted', - 'sensitive': "true", + 'sensitive': True, 'spoiler_text': "Spoiler!", 'in_reply_to_id': '123a', 'language': 'hrv', - 'scheduled_at': None, }, headers={"Idempotency-Key": "up-the-irons"}) out, err = capsys.readouterr() diff --git a/toot/api.py b/toot/api.py index 5868430..883900b 100644 --- a/toot/api.py +++ b/toot/api.py @@ -140,15 +140,17 @@ def post_status( 'status': status, 'media_ids': media_ids, 'visibility': visibility, - 'sensitive': str_bool(sensitive), - 'spoiler_text': spoiler_text, + 'sensitive': sensitive, 'in_reply_to_id': in_reply_to_id, 'language': language, - 'scheduled_at': scheduled_at + 'scheduled_at': scheduled_at, + 'content_type': content_type, + 'spoiler_text': spoiler_text } - if content_type: - json['content_type'] = content_type + # Strip keys for which value is None + # Sending null values doesn't bother Mastodon, but it breaks Pleroma + json = {k: v for k, v in json.items() if v is not None} return http.post(app, user, '/api/v1/statuses', json=json, headers=headers).json()