From 1800a9b2c176cc5f8f3b34d36233206e49d088d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Le=20Calvar?= Date: Sun, 20 May 2018 12:53:19 +0200 Subject: Fix typo in account_update_credentials Mime type of avatar was used to guess extension of header. --- mastodon/Mastodon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 5171d9b..527f1ac 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -1252,7 +1252,7 @@ class Mastodon: avatar_file_name = "mastodonpyupload_" + mimetypes.guess_extension(avatar_mime_type) files["avatar"] = (avatar_file_name, avatar, avatar_mime_type) if not header is None: - header_file_name = "mastodonpyupload_" + mimetypes.guess_extension(avatar_mime_type) + header_file_name = "mastodonpyupload_" + mimetypes.guess_extension(header_mime_type) files["header"] = (header_file_name, header, header_mime_type) params = self.__generate_params(params_initial) -- cgit v1.2.3 From 1090d7476f08313202c82d4f6f3ea2ee81231a37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Le=20Calvar?= Date: Sun, 20 May 2018 12:55:25 +0200 Subject: Fix optional args in account_update_credentials avatar and header are now correctly ignored if not specified. --- mastodon/Mastodon.py | 26 ++++++++++++++------------ tests/test_account.py | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 527f1ac..e616aa3 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -1226,20 +1226,22 @@ class Mastodon: params_initial = locals() # Load avatar, if specified - if avatar_mime_type is None and os.path.isfile(avatar): - avatar_mime_type = mimetypes.guess_type(avatar)[0] - avatar = open(avatar, 'rb') - - if (not avatar is None and avatar_mime_type is None): - raise MastodonIllegalArgumentError('Could not determine mime type or data passed directly without mime type.') + if not avatar is None: + if avatar_mime_type is None and os.path.isfile(avatar): + avatar_mime_type = mimetypes.guess_type(avatar)[0] + avatar = open(avatar, 'rb') + + if avatar_mime_type is None: + raise MastodonIllegalArgumentError('Could not determine mime type or data passed directly without mime type.') # Load header, if specified - if header_mime_type is None and os.path.isfile(header): - header_mime_type = mimetypes.guess_type(header)[0] - header = open(header, 'rb') - - if (not header is None and header_mime_type is None): - raise MastodonIllegalArgumentError('Could not determine mime type or data passed directly without mime type.') + if not header is None: + if header_mime_type is None and os.path.isfile(header): + header_mime_type = mimetypes.guess_type(header)[0] + header = open(header, 'rb') + + if header_mime_type is None: + raise MastodonIllegalArgumentError('Could not determine mime type or data passed directly without mime type.') # Clean up params for param in ["avatar", "avatar_mime_type", "header", "header_mime_type"]: diff --git a/tests/test_account.py b/tests/test_account.py index 240abca..2716ad1 100644 --- a/tests/test_account.py +++ b/tests/test_account.py @@ -92,3 +92,23 @@ def test_account_update_credentials(api): header = image, header_mime_type = "image/jpeg") assert account + +@pytest.mark.vcr(match_on=['path']) +def test_account_update_credentials_no_header(api): + account = api.account_update_credentials( + display_name='John Lennon', + note='I walk funny', + avatar = "tests/image.jpg") + assert account + +@pytest.mark.vcr(match_on=['path']) +def test_account_update_credentials_no_avatar(api): + with open('tests/image.jpg', 'rb') as f: + image = f.read() + + account = api.account_update_credentials( + display_name='John Lennon', + note='I walk funny', + header = image, + header_mime_type = "image/jpeg") + assert account -- cgit v1.2.3