diff options
author | Lorenz Diener <[email protected]> | 2018-06-04 10:34:36 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2018-06-04 10:34:36 +0200 |
commit | be77f4e8ab93dcfecb0fb306479a3eae3e2001cb (patch) | |
tree | 6e0dd3dc6af8f50e9b0029613a69b107056ebd06 | |
parent | f8ba37b42e529b90b10050610098cd648f3a3572 (diff) | |
parent | 1090d7476f08313202c82d4f6f3ea2ee81231a37 (diff) | |
download | mastodon.py-be77f4e8ab93dcfecb0fb306479a3eae3e2001cb.tar.gz |
Merge pull request #135 from goldensuneur/fix_update_credentials
Fix update credentials
-rw-r--r-- | mastodon/Mastodon.py | 28 | ||||
-rw-r--r-- | tests/test_account.py | 20 |
2 files changed, 35 insertions, 13 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 5171d9b..e616aa3 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -1226,20 +1226,22 @@ class Mastodon: | |||
1226 | params_initial = locals() | 1226 | params_initial = locals() |
1227 | 1227 | ||
1228 | # Load avatar, if specified | 1228 | # Load avatar, if specified |
1229 | if avatar_mime_type is None and os.path.isfile(avatar): | 1229 | if not avatar is None: |
1230 | avatar_mime_type = mimetypes.guess_type(avatar)[0] | 1230 | if avatar_mime_type is None and os.path.isfile(avatar): |
1231 | avatar = open(avatar, 'rb') | 1231 | avatar_mime_type = mimetypes.guess_type(avatar)[0] |
1232 | 1232 | avatar = open(avatar, 'rb') | |
1233 | if (not avatar is None and avatar_mime_type is None): | 1233 | |
1234 | raise MastodonIllegalArgumentError('Could not determine mime type or data passed directly without mime type.') | 1234 | if avatar_mime_type is None: |
1235 | raise MastodonIllegalArgumentError('Could not determine mime type or data passed directly without mime type.') | ||
1235 | 1236 | ||
1236 | # Load header, if specified | 1237 | # Load header, if specified |
1237 | if header_mime_type is None and os.path.isfile(header): | 1238 | if not header is None: |
1238 | header_mime_type = mimetypes.guess_type(header)[0] | 1239 | if header_mime_type is None and os.path.isfile(header): |
1239 | header = open(header, 'rb') | 1240 | header_mime_type = mimetypes.guess_type(header)[0] |
1240 | 1241 | header = open(header, 'rb') | |
1241 | if (not header is None and header_mime_type is None): | 1242 | |
1242 | raise MastodonIllegalArgumentError('Could not determine mime type or data passed directly without mime type.') | 1243 | if header_mime_type is None: |
1244 | raise MastodonIllegalArgumentError('Could not determine mime type or data passed directly without mime type.') | ||
1243 | 1245 | ||
1244 | # Clean up params | 1246 | # Clean up params |
1245 | for param in ["avatar", "avatar_mime_type", "header", "header_mime_type"]: | 1247 | for param in ["avatar", "avatar_mime_type", "header", "header_mime_type"]: |
@@ -1252,7 +1254,7 @@ class Mastodon: | |||
1252 | avatar_file_name = "mastodonpyupload_" + mimetypes.guess_extension(avatar_mime_type) | 1254 | avatar_file_name = "mastodonpyupload_" + mimetypes.guess_extension(avatar_mime_type) |
1253 | files["avatar"] = (avatar_file_name, avatar, avatar_mime_type) | 1255 | files["avatar"] = (avatar_file_name, avatar, avatar_mime_type) |
1254 | if not header is None: | 1256 | if not header is None: |
1255 | header_file_name = "mastodonpyupload_" + mimetypes.guess_extension(avatar_mime_type) | 1257 | header_file_name = "mastodonpyupload_" + mimetypes.guess_extension(header_mime_type) |
1256 | files["header"] = (header_file_name, header, header_mime_type) | 1258 | files["header"] = (header_file_name, header, header_mime_type) |
1257 | 1259 | ||
1258 | params = self.__generate_params(params_initial) | 1260 | params = self.__generate_params(params_initial) |
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): | |||
92 | header = image, | 92 | header = image, |
93 | header_mime_type = "image/jpeg") | 93 | header_mime_type = "image/jpeg") |
94 | assert account | 94 | assert account |
95 | |||
96 | @pytest.mark.vcr(match_on=['path']) | ||
97 | def test_account_update_credentials_no_header(api): | ||
98 | account = api.account_update_credentials( | ||
99 | display_name='John Lennon', | ||
100 | note='I walk funny', | ||
101 | avatar = "tests/image.jpg") | ||
102 | assert account | ||
103 | |||
104 | @pytest.mark.vcr(match_on=['path']) | ||
105 | def test_account_update_credentials_no_avatar(api): | ||
106 | with open('tests/image.jpg', 'rb') as f: | ||
107 | image = f.read() | ||
108 | |||
109 | account = api.account_update_credentials( | ||
110 | display_name='John Lennon', | ||
111 | note='I walk funny', | ||
112 | header = image, | ||
113 | header_mime_type = "image/jpeg") | ||
114 | assert account | ||