Merge pull request #135 from goldensuneur/fix_update_credentials
Fix update credentials
This commit is contained in:
commit
be77f4e8ab
S'han modificat 2 arxius amb 35 adicions i 13 eliminacions
|
@ -1226,19 +1226,21 @@ class Mastodon:
|
||||||
params_initial = locals()
|
params_initial = locals()
|
||||||
|
|
||||||
# Load avatar, if specified
|
# Load avatar, if specified
|
||||||
|
if not avatar is None:
|
||||||
if avatar_mime_type is None and os.path.isfile(avatar):
|
if avatar_mime_type is None and os.path.isfile(avatar):
|
||||||
avatar_mime_type = mimetypes.guess_type(avatar)[0]
|
avatar_mime_type = mimetypes.guess_type(avatar)[0]
|
||||||
avatar = open(avatar, 'rb')
|
avatar = open(avatar, 'rb')
|
||||||
|
|
||||||
if (not avatar is None and avatar_mime_type is None):
|
if avatar_mime_type is None:
|
||||||
raise MastodonIllegalArgumentError('Could not determine mime type or data passed directly without mime type.')
|
raise MastodonIllegalArgumentError('Could not determine mime type or data passed directly without mime type.')
|
||||||
|
|
||||||
# Load header, if specified
|
# Load header, if specified
|
||||||
|
if not header is None:
|
||||||
if header_mime_type is None and os.path.isfile(header):
|
if header_mime_type is None and os.path.isfile(header):
|
||||||
header_mime_type = mimetypes.guess_type(header)[0]
|
header_mime_type = mimetypes.guess_type(header)[0]
|
||||||
header = open(header, 'rb')
|
header = open(header, 'rb')
|
||||||
|
|
||||||
if (not header is None and header_mime_type is None):
|
if header_mime_type is None:
|
||||||
raise MastodonIllegalArgumentError('Could not determine mime type or data passed directly without mime type.')
|
raise MastodonIllegalArgumentError('Could not determine mime type or data passed directly without mime type.')
|
||||||
|
|
||||||
# Clean up params
|
# Clean up params
|
||||||
|
@ -1252,7 +1254,7 @@ class Mastodon:
|
||||||
avatar_file_name = "mastodonpyupload_" + mimetypes.guess_extension(avatar_mime_type)
|
avatar_file_name = "mastodonpyupload_" + mimetypes.guess_extension(avatar_mime_type)
|
||||||
files["avatar"] = (avatar_file_name, avatar, avatar_mime_type)
|
files["avatar"] = (avatar_file_name, avatar, avatar_mime_type)
|
||||||
if not header is None:
|
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)
|
files["header"] = (header_file_name, header, header_mime_type)
|
||||||
|
|
||||||
params = self.__generate_params(params_initial)
|
params = self.__generate_params(params_initial)
|
||||||
|
|
|
@ -92,3 +92,23 @@ def test_account_update_credentials(api):
|
||||||
header = image,
|
header = image,
|
||||||
header_mime_type = "image/jpeg")
|
header_mime_type = "image/jpeg")
|
||||||
assert account
|
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
|
||||||
|
|
Loading…
Referencia en una nova incidència