Fix optional args in account_update_credentials

avatar and header are now correctly ignored if not specified.
This commit is contained in:
Théo Le Calvar 2018-05-20 12:55:25 +02:00
pare 1800a9b2c1
commit 1090d7476f
S'han modificat 2 arxius amb 34 adicions i 12 eliminacions

Veure arxiu

@ -1226,20 +1226,22 @@ class Mastodon:
params_initial = locals() params_initial = locals()
# Load avatar, if specified # Load avatar, if specified
if avatar_mime_type is None and os.path.isfile(avatar): if not avatar is None:
avatar_mime_type = mimetypes.guess_type(avatar)[0] if avatar_mime_type is None and os.path.isfile(avatar):
avatar = open(avatar, 'rb') 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 avatar_mime_type is None:
raise MastodonIllegalArgumentError('Could not determine mime type or data passed directly without mime type.')
# Load header, if specified # Load header, if specified
if header_mime_type is None and os.path.isfile(header): if not header is None:
header_mime_type = mimetypes.guess_type(header)[0] if header_mime_type is None and os.path.isfile(header):
header = open(header, 'rb') 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 header_mime_type is None:
raise MastodonIllegalArgumentError('Could not determine mime type or data passed directly without mime type.')
# Clean up params # Clean up params
for param in ["avatar", "avatar_mime_type", "header", "header_mime_type"]: for param in ["avatar", "avatar_mime_type", "header", "header_mime_type"]:

Veure arxiu

@ -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