clean up media loading, add thumbnail to media_update

pull/257/head
halcy 2022-11-13 14:06:50 +02:00
rodzic c670ed8ce2
commit adcddefd59
10 zmienionych plików z 41496 dodań i 6893 usunięć

Wyświetl plik

@ -2212,24 +2212,6 @@ class Mastodon:
"""
params_initial = collections.OrderedDict(locals())
# Load avatar, if specified
if not avatar is None:
if avatar_mime_type is None and (isinstance(avatar, str) and os.path.isfile(avatar)):
avatar_mime_type = guess_type(avatar)
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 not header is None:
if header_mime_type is None and (isinstance(header, str) and os.path.isfile(header)):
header_mime_type = guess_type(header)
header = open(header, 'rb')
if header_mime_type is None:
raise MastodonIllegalArgumentError('Could not determine mime type or data passed directly without mime type.')
# Convert fields
if fields != None:
if len(fields) > 4:
@ -2248,11 +2230,9 @@ class Mastodon:
# Create file info
files = {}
if not avatar is None:
avatar_file_name = "mastodonpyupload_" + mimetypes.guess_extension(avatar_mime_type)
files["avatar"] = (avatar_file_name, avatar, avatar_mime_type)
files["avatar"] = self.__load_media_file(avatar, avatar_mime_type)
if not header is None:
header_file_name = "mastodonpyupload_" + mimetypes.guess_extension(header_mime_type)
files["header"] = (header_file_name, header, header_mime_type)
files["header"] = self.__load_media_file(header, header_mime_type)
params = self.__generate_params(params_initial)
return self.__api_request('PATCH', '/api/v1/accounts/update_credentials', params, files=files)
@ -2511,37 +2491,15 @@ class Mastodon:
"synchronous" to emulate the old behaviour. Not recommended, inefficient
and deprecated, you know the deal.
"""
if mime_type is None and (isinstance(media_file, str) and os.path.isfile(media_file)):
mime_type = guess_type(media_file)
media_file = open(media_file, 'rb')
elif isinstance(media_file, str) and os.path.isfile(media_file):
media_file = open(media_file, 'rb')
if mime_type is None:
raise MastodonIllegalArgumentError('Could not determine mime type or data passed directly without mime type.')
if file_name is None:
random_suffix = uuid.uuid4().hex
file_name = "mastodonpyupload_" + str(time.time()) + "_" + str(random_suffix) + mimetypes.guess_extension(mime_type)
files = {'file': self.__load_media_file(media_file, mime_type, file_name)}
if focus != None:
focus = str(focus[0]) + "," + str(focus[1])
files = {'file': (file_name, media_file, mime_type)}
focus = str(focus[0]) + "," + str(focus[1])
if not thumbnail is None:
if not self.verify_minimum_version("3.2.0"):
raise MastodonVersionError('Thumbnail requires version > 3.2.0')
if isinstance(thumbnail, str) and os.path.isfile(thumbnail):
thumbnail_mime_type = guess_type(thumbnail)
thumbnail = open(thumbnail, 'rb')
elif isinstance(thumbnail, str) and os.path.isfile(thumbnail):
thumbnail = open(thumbnail, 'rb')
if thumbnail_mime_type is None:
raise MastodonIllegalArgumentError('Could not determine mime type or data passed directly without mime type.')
files["thumbnail"] = ("thumb" + mimetypes.guess_extension(mime_type), thumbnail, thumbnail_mime_type)
files["thumbnail"] = self.__load_media_file(thumbnail, thumbnail_mime_type)
# Disambiguate URL by version
if self.verify_minimum_version("3.1.4"):
@ -2564,11 +2522,11 @@ class Mastodon:
return ret_dict
@api_version("2.3.0", "2.3.0", __DICT_VERSION_MEDIA)
def media_update(self, id, description=None, focus=None):
@api_version("2.3.0", "3.2.0", __DICT_VERSION_MEDIA)
def media_update(self, id, description=None, focus=None, thumbnail=None, thumbnail_mime_type=None):
"""
Update the metadata of the media file with the given `id`. `description` and
`focus` are as in `media_post()`_ .
`focus` and `thumbnail` are as in `media_post()`_ .
Returns the updated `media dict`_.
"""
@ -2576,9 +2534,16 @@ class Mastodon:
if focus != None:
focus = str(focus[0]) + "," + str(focus[1])
params = self.__generate_params(locals(), ['id'])
return self.__api_request('PUT', '/api/v1/media/{0}'.format(str(id)), params)
params = self.__generate_params(locals(), ['id', 'thumbnail', 'thumbnail_mime_type'])
if not thumbnail is None:
if not self.verify_minimum_version("3.2.0"):
raise MastodonVersionError('Thumbnail requires version > 3.2.0')
files = {"thumbnail": self.__load_media_file(thumbnail, thumbnail_mime_type)}
return self.__api_request('PUT', '/api/v1/media/{0}'.format(str(id)), params, files = files)
else:
return self.__api_request('PUT', '/api/v1/media/{0}'.format(str(id)), params)
@api_version("3.1.4", "3.1.4", __DICT_VERSION_MEDIA)
def media(self, id):
@ -3823,7 +3788,29 @@ class Mastodon:
"""Internal helper for oauth code"""
self._refresh_token = value
return
def __guess_type(self, media_file):
"""Internal helper to guess media file type"""
mime_type = None
try:
mime_type = magic.from_file(media_file, mime=True)
except AttributeError:
mime_type = mimetypes.guess_type(media_file)[0]
return mime_type
def __load_media_file(self, media_file, mime_type = None, file_name = None):
if isinstance(media_file, str) and os.path.isfile(media_file):
mime_type = self.__guess_type(media_file)
media_file = open(media_file, 'rb')
elif isinstance(media_file, str) and os.path.isfile(media_file):
media_file = open(media_file, 'rb')
if mime_type is None:
raise MastodonIllegalArgumentError('Could not determine mime type or data passed directly without mime type.')
if file_name is None:
random_suffix = uuid.uuid4().hex
file_name = "mastodonpyupload_" + str(time.time()) + "_" + str(random_suffix) + mimetypes.guess_extension(mime_type)
return (file_name, media_file, mime_type)
@staticmethod
def __protocolize(base_url):
"""Internal add-protocol-to-url helper"""
@ -3913,10 +3900,3 @@ class MastodonMalformedEventError(MastodonError):
"""Raised when the server-sent event stream is malformed"""
pass
def guess_type(media_file):
mime_type = None
try:
mime_type = magic.from_file(media_file, mime=True)
except AttributeError:
mime_type = mimetypes.guess_type(media_file)[0]
return mime_type

Wyświetl plik

@ -23,7 +23,7 @@ interactions:
Content-Security-Policy:
- 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src
''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000;
style-src ''self'' http://localhost:3000 ''nonce-khnMwJohbzdEXl9oAb/QLA=='';
style-src ''self'' http://localhost:3000 ''nonce-uSy33UpG9ORLcKvU5+Bbvg=='';
media-src ''self'' https: data: http://localhost:3000; frame-src ''self''
https:; manifest-src ''self'' http://localhost:3000; connect-src ''self''
data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000
@ -33,7 +33,7 @@ interactions:
Content-Type:
- application/json; charset=utf-8
Date:
- Sun, 13 Nov 2022 11:14:08 GMT
- Sun, 13 Nov 2022 12:03:43 GMT
ETag:
- W/"bf317ffab393d8d1da7195269f28968a"
Referrer-Policy:
@ -51,9 +51,9 @@ interactions:
X-Permitted-Cross-Domain-Policies:
- none
X-Request-Id:
- 6a68491d-8454-45d8-b1f1-4e8fb162d289
- daaf9e52-f63f-41f1-beaa-6e38348ffad0
X-Runtime:
- '0.013625'
- '0.014406'
X-XSS-Protection:
- 1; mode=block
status:
@ -61,13 +61,13 @@ interactions:
message: OK
- request:
body: !!binary |
LS05MmU0MGJhNzBiOTMwODUxYmMxZjg4OWVhOTI1NGU3Mw0KQ29udGVudC1EaXNwb3NpdGlvbjog
LS01ZTUzMjJlY2FmYTRlYjgwNTZkNjBmNzk5YTk5NTdjNQ0KQ29udGVudC1EaXNwb3NpdGlvbjog
Zm9ybS1kYXRhOyBuYW1lPSJkZXNjcmlwdGlvbiINCg0KSm9obiBMZW5ub24gZG9pbmcgYSBmdW5u
eSB3YWxrDQotLTkyZTQwYmE3MGI5MzA4NTFiYzFmODg5ZWE5MjU0ZTczDQpDb250ZW50LURpc3Bv
c2l0aW9uOiBmb3JtLWRhdGE7IG5hbWU9ImZvY3VzIg0KDQotMC41LDAuMw0KLS05MmU0MGJhNzBi
OTMwODUxYmMxZjg4OWVhOTI1NGU3Mw0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBu
YW1lPSJmaWxlIjsgZmlsZW5hbWU9Im1hc3RvZG9ucHl1cGxvYWRfMTY2ODMzODA0OC42NjA0MjU0
X2U2YmZlNzJkMmE5YzQ4MWJiZTA0MTdhZmE3NjY1MWYyLmpwZyINCkNvbnRlbnQtVHlwZTogaW1h
eSB3YWxrDQotLTVlNTMyMmVjYWZhNGViODA1NmQ2MGY3OTlhOTk1N2M1DQpDb250ZW50LURpc3Bv
c2l0aW9uOiBmb3JtLWRhdGE7IG5hbWU9ImZvY3VzIg0KDQotMC41LDAuMw0KLS01ZTUzMjJlY2Fm
YTRlYjgwNTZkNjBmNzk5YTk5NTdjNQ0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBu
YW1lPSJmaWxlIjsgZmlsZW5hbWU9Im1hc3RvZG9ucHl1cGxvYWRfMTY2ODM0MTAyMy4wODQ1Mjg3
X2Y3NzZhODA3MWFlYTQ4MWVhMDVmYWY1ZDNlNmFiNTRjLmpwZyINCkNvbnRlbnQtVHlwZTogaW1h
Z2UvanBlZw0KDQr/2P/gABBKRklGAAEBAQBIAEgAAP/iAhxJQ0NfUFJPRklMRQABAQAAAgxsY21z
AhAAAG1udHJSR0IgWFlaIAfcAAEAGQADACkAOWFjc3BBUFBMAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAD21gABAAAAANMtbGNtcwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
@ -1003,8 +1003,8 @@ interactions:
KWI3D24r93pUoX5EQbZIDAphpUqKI6mINwj9YYOV2oMLkmWXo9TfelSoHhykWUoovQTO33qdoivL
umOvT8UqVFWbbHaEokDtzf5qMy4XCMTEjfPbPilSoFOFzByxzhRey1WUSaxVdtqVKgaCiiCrnK5p
kwMTGX4pUqBTtsYnLjJ4xUrWDGZB1d1z+KVKguWW3ctzMCb7u1NAIwEky3zsvWlSoIzwuWI/Ypgk
yI8qxk4wZ/WlSoGNPcbo46Oebs70qVKg/9kNCi0tOTJlNDBiYTcwYjkzMDg1MWJjMWY4ODllYTky
NTRlNzMtLQ0K
yI8qxk4wZ/WlSoGNPcbo46Oebs70qVKg/9kNCi0tNWU1MzIyZWNhZmE0ZWI4MDU2ZDYwZjc5OWE5
OTU3YzUtLQ0K
headers:
Accept:
- '*/*'
@ -1017,14 +1017,14 @@ interactions:
Content-Length:
- '53760'
Content-Type:
- multipart/form-data; boundary=92e40ba70b930851bc1f889ea9254e73
- multipart/form-data; boundary=5e5322ecafa4eb8056d60f799a9957c5
User-Agent:
- tests/v311
method: POST
uri: http://localhost:3000/api/v2/media
response:
body:
string: '{"id":"109336202366605575","type":"image","url":"http://localhost:3000/system/media_attachments/files/109/336/202/366/605/575/original/cf723e729eeece3b.jpg","preview_url":"http://localhost:3000/system/media_attachments/files/109/336/202/366/605/575/small/cf723e729eeece3b.jpg","remote_url":null,"preview_remote_url":null,"text_url":null,"meta":{"original":{"width":600,"height":600,"size":"600x600","aspect":1.0},"small":{"width":480,"height":480,"size":"480x480","aspect":1.0},"focus":{"x":-0.5,"y":0.3}},"description":"John
string: '{"id":"109336397301097789","type":"image","url":"http://localhost:3000/system/media_attachments/files/109/336/397/301/097/789/original/84fe2e3e1279a737.jpg","preview_url":"http://localhost:3000/system/media_attachments/files/109/336/397/301/097/789/small/84fe2e3e1279a737.jpg","remote_url":null,"preview_remote_url":null,"text_url":null,"meta":{"original":{"width":600,"height":600,"size":"600x600","aspect":1.0},"small":{"width":480,"height":480,"size":"480x480","aspect":1.0},"focus":{"x":-0.5,"y":0.3}},"description":"John
Lennon doing a funny walk","blurhash":"UGD9YhIn00j[NFofR%M{IURj%Ms;D%of%MR%"}'
headers:
Cache-Control:
@ -1032,7 +1032,7 @@ interactions:
Content-Security-Policy:
- 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src
''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000;
style-src ''self'' http://localhost:3000 ''nonce-TpR4xRwQGj0jkZMqRlCEcA=='';
style-src ''self'' http://localhost:3000 ''nonce-QyCWdR6KOcZok16Ok7aqWg=='';
media-src ''self'' https: data: http://localhost:3000; frame-src ''self''
https:; manifest-src ''self'' http://localhost:3000; connect-src ''self''
data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000
@ -1042,7 +1042,7 @@ interactions:
Content-Type:
- application/json; charset=utf-8
ETag:
- W/"ccd8ed65239189b5ef85fd397a97f888"
- W/"e24f520198f6c547f0cbbb7ce2c06179"
Referrer-Policy:
- strict-origin-when-cross-origin
Transfer-Encoding:
@ -1058,9 +1058,9 @@ interactions:
X-Permitted-Cross-Domain-Policies:
- none
X-Request-Id:
- ae1b3811-ce7d-4344-a1c6-cbc0e92c7b70
- 430f7ebc-28cf-41d0-a7bd-3804ecc18af0
X-Runtime:
- '0.130515'
- '0.179570'
X-XSS-Protection:
- 1; mode=block
status:
@ -1090,7 +1090,7 @@ interactions:
Content-Security-Policy:
- 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src
''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000;
style-src ''self'' http://localhost:3000 ''nonce-kzXxOSNHHyVDBYw3Yf+2ag=='';
style-src ''self'' http://localhost:3000 ''nonce-8gQrn9Z0cc52hsDL8dGa6g=='';
media-src ''self'' https: data: http://localhost:3000; frame-src ''self''
https:; manifest-src ''self'' http://localhost:3000; connect-src ''self''
data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000
@ -1100,7 +1100,7 @@ interactions:
Content-Type:
- application/json; charset=utf-8
Date:
- Sun, 13 Nov 2022 11:14:08 GMT
- Sun, 13 Nov 2022 12:03:43 GMT
ETag:
- W/"6de86e074f529b0074f74528eee15b7a"
Referrer-Policy:
@ -1118,9 +1118,9 @@ interactions:
X-Permitted-Cross-Domain-Policies:
- none
X-Request-Id:
- f9323830-01c5-44c7-a75f-f90f9d50000d
- 842ad82e-8a50-484f-a5dd-a6ec8b7ab2ed
X-Runtime:
- '0.022495'
- '0.062652'
X-XSS-Protection:
- 1; mode=block
status:
@ -1150,7 +1150,7 @@ interactions:
Content-Security-Policy:
- 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src
''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000;
style-src ''self'' http://localhost:3000 ''nonce-U6yO7UVcX/ZjJ1t0RN4PzA=='';
style-src ''self'' http://localhost:3000 ''nonce-SVZg7L6AdoM+Hyz0PmMJXA=='';
media-src ''self'' https: data: http://localhost:3000; frame-src ''self''
https:; manifest-src ''self'' http://localhost:3000; connect-src ''self''
data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000
@ -1160,7 +1160,7 @@ interactions:
Content-Type:
- application/json; charset=utf-8
Date:
- Sun, 13 Nov 2022 11:14:08 GMT
- Sun, 13 Nov 2022 12:03:43 GMT
ETag:
- W/"6de86e074f529b0074f74528eee15b7a"
Referrer-Policy:
@ -1178,9 +1178,9 @@ interactions:
X-Permitted-Cross-Domain-Policies:
- none
X-Request-Id:
- 0327b8e0-1677-4f18-b298-b5cd95b60cf4
- 172c6369-24ba-443b-9795-6fb85cfc6a5a
X-Runtime:
- '0.013002'
- '0.013162'
X-XSS-Protection:
- 1; mode=block
status:
@ -1188,13 +1188,13 @@ interactions:
message: OK
- request:
body: !!binary |
LS1hMmQzOTcwZDIxMzM2YzBiYTQzNTc5NzM4NzgzNjU4Zg0KQ29udGVudC1EaXNwb3NpdGlvbjog
LS05Y2ZmZTZhZWRkOTBiY2JmOWU0MzhlNTVhMmZjZWM2Yw0KQ29udGVudC1EaXNwb3NpdGlvbjog
Zm9ybS1kYXRhOyBuYW1lPSJkZXNjcmlwdGlvbiINCg0KaG9sb2xpdmVzICMxIGRldGVjdGl2ZSwg
d2F0c29uIGFtZWxpYWNoYW4NCi0tYTJkMzk3MGQyMTMzNmMwYmE0MzU3OTczODc4MzY1OGYNCkNv
d2F0c29uIGFtZWxpYWNoYW4NCi0tOWNmZmU2YWVkZDkwYmNiZjllNDM4ZTU1YTJmY2VjNmMNCkNv
bnRlbnQtRGlzcG9zaXRpb246IGZvcm0tZGF0YTsgbmFtZT0iZm9jdXMiDQoNCjAuNSwwLjUNCi0t
YTJkMzk3MGQyMTMzNmMwYmE0MzU3OTczODc4MzY1OGYNCkNvbnRlbnQtRGlzcG9zaXRpb246IGZv
cm0tZGF0YTsgbmFtZT0iZmlsZSI7IGZpbGVuYW1lPSJtYXN0b2RvbnB5dXBsb2FkXzE2NjgzMzgw
NDguODM5Mjk3M182NDUxNjk0ZDVmNjE0NWJhOTVkYzEzNWEyN2JlMjljYi5qcGciDQpDb250ZW50
OWNmZmU2YWVkZDkwYmNiZjllNDM4ZTU1YTJmY2VjNmMNCkNvbnRlbnQtRGlzcG9zaXRpb246IGZv
cm0tZGF0YTsgbmFtZT0iZmlsZSI7IGZpbGVuYW1lPSJtYXN0b2RvbnB5dXBsb2FkXzE2NjgzNDEw
MjMuMzU5Nzg5Nl9mOTM2OTIwNWFmNDA0ZmQwYWMwMjUyMzEwYmRlM2ExYS5qcGciDQpDb250ZW50
LVR5cGU6IGltYWdlL2pwZWcNCg0K/9j/4AAQSkZJRgABAQAAAQABAAD/4gKgSUNDX1BST0ZJTEUA
AQEAAAKQbGNtcwQwAABtbnRyUkdCIFhZWiAAAAAAAAAAAAAAAABhY3NwQVBQTAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA9tYAAQAAAADTLWxjbXMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
@ -1668,8 +1668,8 @@ interactions:
NN1l2JUiCCkCfJQuAqdyfmpsGiCkcZQT0ipcFDtuAORQNtwCWjiOo59qNyaqa8qiytgPSFd303FN
YyRalj2WjajkwhI9o/yqXk7oqZBKgurLSgqNqLAqt0puaZq5xeFKVwuynHY60lFZmjsSgpz0/YjQ
tPJAr2amp/oqf6KCkkoi6sUTmfnXeZ5qUPImhkYMhww60+izCtWlrFOshM0ed/mU1a27R1TTB91B
H7gdym2Fgi7vVveGB+KhAwvu82i5voYn9+0miV456UxiEYTagvxpW8ZXs/F//9kNCi0tYTJkMzk3
MGQyMTMzNmMwYmE0MzU3OTczODc4MzY1OGYtLQ0K
H7gdym2Fgi7vVveGB+KhAwvu82i5voYn9+0miV456UxiEYTagvxpW8ZXs/F//9kNCi0tOWNmZmU2
YWVkZDkwYmNiZjllNDM4ZTU1YTJmY2VjNmMtLQ0K
headers:
Accept:
- '*/*'
@ -1682,14 +1682,14 @@ interactions:
Content-Length:
- '27447'
Content-Type:
- multipart/form-data; boundary=a2d3970d21336c0ba43579738783658f
- multipart/form-data; boundary=9cffe6aedd90bcbf9e438e55a2fcec6c
User-Agent:
- tests/v311
method: POST
uri: http://localhost:3000/api/v2/media
response:
body:
string: '{"id":"109336202375987007","type":"image","url":"http://localhost:3000/system/media_attachments/files/109/336/202/375/987/007/original/974fe7224ae7c409.jpg","preview_url":"http://localhost:3000/system/media_attachments/files/109/336/202/375/987/007/small/974fe7224ae7c409.jpg","remote_url":null,"preview_remote_url":null,"text_url":null,"meta":{"original":{"width":400,"height":400,"size":"400x400","aspect":1.0},"small":{"width":400,"height":400,"size":"400x400","aspect":1.0},"focus":{"x":0.5,"y":0.5}},"description":"hololives
string: '{"id":"109336397314377564","type":"image","url":"http://localhost:3000/system/media_attachments/files/109/336/397/314/377/564/original/fb76e61bbb716e34.jpg","preview_url":"http://localhost:3000/system/media_attachments/files/109/336/397/314/377/564/small/fb76e61bbb716e34.jpg","remote_url":null,"preview_remote_url":null,"text_url":null,"meta":{"original":{"width":400,"height":400,"size":"400x400","aspect":1.0},"small":{"width":400,"height":400,"size":"400x400","aspect":1.0},"focus":{"x":0.5,"y":0.5}},"description":"hololives
#1 detective, watson ameliachan","blurhash":"UPNKI$xbloIA9ZoI.8RjK-oy%NkD%hW?i^t6"}'
headers:
Cache-Control:
@ -1697,7 +1697,7 @@ interactions:
Content-Security-Policy:
- 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src
''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000;
style-src ''self'' http://localhost:3000 ''nonce-MmsIxDwinfAKMd0VTr0yLw=='';
style-src ''self'' http://localhost:3000 ''nonce-cCkKE07dJbcfVLY2r1gkqw=='';
media-src ''self'' https: data: http://localhost:3000; frame-src ''self''
https:; manifest-src ''self'' http://localhost:3000; connect-src ''self''
data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000
@ -1707,7 +1707,7 @@ interactions:
Content-Type:
- application/json; charset=utf-8
ETag:
- W/"71f4d7f337956fa6122fb2f13419d8bc"
- W/"7e68d6c5a37151236ce8904e4eeb2637"
Referrer-Policy:
- strict-origin-when-cross-origin
Transfer-Encoding:
@ -1723,9 +1723,9 @@ interactions:
X-Permitted-Cross-Domain-Policies:
- none
X-Request-Id:
- 90110f94-2183-4a0b-8016-fdb3b66c602d
- d091ee2d-3e73-4075-895a-7a0680025230
X-Runtime:
- '0.096357'
- '0.098882'
X-XSS-Protection:
- 1; mode=block
status:
@ -1755,7 +1755,7 @@ interactions:
Content-Security-Policy:
- 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src
''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000;
style-src ''self'' http://localhost:3000 ''nonce-G1AKawpSo9fBQq37nnLILg=='';
style-src ''self'' http://localhost:3000 ''nonce-gaNcYn9jn2JG1QmP0vihpw=='';
media-src ''self'' https: data: http://localhost:3000; frame-src ''self''
https:; manifest-src ''self'' http://localhost:3000; connect-src ''self''
data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000
@ -1765,7 +1765,7 @@ interactions:
Content-Type:
- application/json; charset=utf-8
Date:
- Sun, 13 Nov 2022 11:14:08 GMT
- Sun, 13 Nov 2022 12:03:43 GMT
ETag:
- W/"6de86e074f529b0074f74528eee15b7a"
Referrer-Policy:
@ -1783,16 +1783,16 @@ interactions:
X-Permitted-Cross-Domain-Policies:
- none
X-Request-Id:
- a831bc1d-14f1-45e8-b71c-b1a1a1b5bd13
- b47d4a0f-9ab7-4bb4-8652-cada80f623c5
X-Runtime:
- '0.013263'
- '0.014133'
X-XSS-Protection:
- 1; mode=block
status:
code: 200
message: OK
- request:
body: status=LOL+check+this+out&media_ids%5B%5D=109336202366605575&media_ids%5B%5D=109336202375987007
body: status=LOL+check+this+out&media_ids%5B%5D=109336397301097789&media_ids%5B%5D=109336397314377564
headers:
Accept:
- '*/*'
@ -1812,10 +1812,10 @@ interactions:
uri: http://localhost:3000/api/v1/statuses
response:
body:
string: '{"id":"109336202378387806","created_at":"2022-11-13T11:14:08.988Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"public","language":"ja","uri":"http://localhost:3000/users/mastodonpy_test/statuses/109336202378387806","url":"http://localhost:3000/@mastodonpy_test/109336202378387806","replies_count":0,"reblogs_count":0,"favourites_count":0,"edited_at":null,"favourited":false,"reblogged":false,"muted":false,"bookmarked":false,"pinned":false,"content":"\u003cp\u003eLOL
string: '{"id":"109336397316903440","created_at":"2022-11-13T12:03:43.514Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"public","language":"ja","uri":"http://localhost:3000/users/mastodonpy_test/statuses/109336397316903440","url":"http://localhost:3000/@mastodonpy_test/109336397316903440","replies_count":0,"reblogs_count":0,"favourites_count":0,"edited_at":null,"favourited":false,"reblogged":false,"muted":false,"bookmarked":false,"pinned":false,"content":"\u003cp\u003eLOL
check this out\u003c/p\u003e","filtered":[],"reblog":null,"application":{"name":"Mastodon.py
test suite","website":null},"account":{"id":"109336199970122902","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"","locked":true,"bot":false,"discoverable":null,"group":false,"created_at":"2022-11-13T00:00:00.000Z","note":"","url":"http://localhost:3000/@mastodonpy_test","avatar":"http://localhost:3000/avatars/original/missing.png","avatar_static":"http://localhost:3000/avatars/original/missing.png","header":"http://localhost:3000/headers/original/missing.png","header_static":"http://localhost:3000/headers/original/missing.png","followers_count":0,"following_count":0,"statuses_count":1,"last_status_at":"2022-11-13","noindex":false,"emojis":[],"fields":[]},"media_attachments":[{"id":"109336202366605575","type":"image","url":"http://localhost:3000/system/media_attachments/files/109/336/202/366/605/575/original/cf723e729eeece3b.jpg","preview_url":"http://localhost:3000/system/media_attachments/files/109/336/202/366/605/575/small/cf723e729eeece3b.jpg","remote_url":null,"preview_remote_url":null,"text_url":null,"meta":{"original":{"width":600,"height":600,"size":"600x600","aspect":1.0},"small":{"width":480,"height":480,"size":"480x480","aspect":1.0},"focus":{"x":-0.5,"y":0.3}},"description":"John
Lennon doing a funny walk","blurhash":"UGD9YhIn00j[NFofR%M{IURj%Ms;D%of%MR%"},{"id":"109336202375987007","type":"image","url":"http://localhost:3000/system/media_attachments/files/109/336/202/375/987/007/original/974fe7224ae7c409.jpg","preview_url":"http://localhost:3000/system/media_attachments/files/109/336/202/375/987/007/small/974fe7224ae7c409.jpg","remote_url":null,"preview_remote_url":null,"text_url":null,"meta":{"original":{"width":400,"height":400,"size":"400x400","aspect":1.0},"small":{"width":400,"height":400,"size":"400x400","aspect":1.0},"focus":{"x":0.5,"y":0.5}},"description":"hololives
test suite","website":null},"account":{"id":"109336199970122902","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"","locked":true,"bot":false,"discoverable":null,"group":false,"created_at":"2022-11-13T00:00:00.000Z","note":"","url":"http://localhost:3000/@mastodonpy_test","avatar":"http://localhost:3000/avatars/original/missing.png","avatar_static":"http://localhost:3000/avatars/original/missing.png","header":"http://localhost:3000/headers/original/missing.png","header_static":"http://localhost:3000/headers/original/missing.png","followers_count":0,"following_count":0,"statuses_count":1,"last_status_at":"2022-11-13","noindex":false,"emojis":[],"fields":[]},"media_attachments":[{"id":"109336397301097789","type":"image","url":"http://localhost:3000/system/media_attachments/files/109/336/397/301/097/789/original/84fe2e3e1279a737.jpg","preview_url":"http://localhost:3000/system/media_attachments/files/109/336/397/301/097/789/small/84fe2e3e1279a737.jpg","remote_url":null,"preview_remote_url":null,"text_url":null,"meta":{"original":{"width":600,"height":600,"size":"600x600","aspect":1.0},"small":{"width":480,"height":480,"size":"480x480","aspect":1.0},"focus":{"x":-0.5,"y":0.3}},"description":"John
Lennon doing a funny walk","blurhash":"UGD9YhIn00j[NFofR%M{IURj%Ms;D%of%MR%"},{"id":"109336397314377564","type":"image","url":"http://localhost:3000/system/media_attachments/files/109/336/397/314/377/564/original/fb76e61bbb716e34.jpg","preview_url":"http://localhost:3000/system/media_attachments/files/109/336/397/314/377/564/small/fb76e61bbb716e34.jpg","remote_url":null,"preview_remote_url":null,"text_url":null,"meta":{"original":{"width":400,"height":400,"size":"400x400","aspect":1.0},"small":{"width":400,"height":400,"size":"400x400","aspect":1.0},"focus":{"x":0.5,"y":0.5}},"description":"hololives
#1 detective, watson ameliachan","blurhash":"UPNKI$xbloIA9ZoI.8RjK-oy%NkD%hW?i^t6"}],"mentions":[],"tags":[],"emojis":[],"card":null,"poll":null}'
headers:
Cache-Control:
@ -1823,7 +1823,7 @@ interactions:
Content-Security-Policy:
- 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src
''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000;
style-src ''self'' http://localhost:3000 ''nonce-GOflCu6eWXy64W5XabzdQw=='';
style-src ''self'' http://localhost:3000 ''nonce-erLPNEwJH/Wg2NZU+k8iwA=='';
media-src ''self'' https: data: http://localhost:3000; frame-src ''self''
https:; manifest-src ''self'' http://localhost:3000; connect-src ''self''
data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000
@ -1833,7 +1833,7 @@ interactions:
Content-Type:
- application/json; charset=utf-8
ETag:
- W/"44187a7b451d7ea896b5f3b706b238b8"
- W/"a8b2a157119cb8a2d379ee0b9a4d0de9"
Referrer-Policy:
- strict-origin-when-cross-origin
Transfer-Encoding:
@ -1853,11 +1853,11 @@ interactions:
X-RateLimit-Remaining:
- '297'
X-RateLimit-Reset:
- '2022-11-13T12:00:00.008874Z'
- '2022-11-13T15:00:00.536036Z'
X-Request-Id:
- c49e75b8-1169-46d8-805b-05f95e937730
- 57d9027b-311f-4670-9447-f70ac92e5cc2
X-Runtime:
- '0.033419'
- '0.035654'
X-XSS-Protection:
- 1; mode=block
status:
@ -1879,13 +1879,13 @@ interactions:
User-Agent:
- tests/v311
method: DELETE
uri: http://localhost:3000/api/v1/statuses/109336202378387806
uri: http://localhost:3000/api/v1/statuses/109336397316903440
response:
body:
string: '{"id":"109336202378387806","created_at":"2022-11-13T11:14:08.988Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"public","language":"ja","uri":"http://localhost:3000/users/mastodonpy_test/statuses/109336202378387806","url":"http://localhost:3000/@mastodonpy_test/109336202378387806","replies_count":0,"reblogs_count":0,"favourites_count":0,"edited_at":null,"favourited":false,"reblogged":false,"muted":false,"bookmarked":false,"pinned":false,"text":"LOL
string: '{"id":"109336397316903440","created_at":"2022-11-13T12:03:43.514Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"public","language":"ja","uri":"http://localhost:3000/users/mastodonpy_test/statuses/109336397316903440","url":"http://localhost:3000/@mastodonpy_test/109336397316903440","replies_count":0,"reblogs_count":0,"favourites_count":0,"edited_at":null,"favourited":false,"reblogged":false,"muted":false,"bookmarked":false,"pinned":false,"text":"LOL
check this out","filtered":[],"reblog":null,"application":{"name":"Mastodon.py
test suite","website":null},"account":{"id":"109336199970122902","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"","locked":true,"bot":false,"discoverable":null,"group":false,"created_at":"2022-11-13T00:00:00.000Z","note":"","url":"http://localhost:3000/@mastodonpy_test","avatar":"http://localhost:3000/avatars/original/missing.png","avatar_static":"http://localhost:3000/avatars/original/missing.png","header":"http://localhost:3000/headers/original/missing.png","header_static":"http://localhost:3000/headers/original/missing.png","followers_count":0,"following_count":0,"statuses_count":0,"last_status_at":"2022-11-13","noindex":false,"emojis":[],"fields":[]},"media_attachments":[{"id":"109336202366605575","type":"image","url":"http://localhost:3000/system/media_attachments/files/109/336/202/366/605/575/original/cf723e729eeece3b.jpg","preview_url":"http://localhost:3000/system/media_attachments/files/109/336/202/366/605/575/small/cf723e729eeece3b.jpg","remote_url":null,"preview_remote_url":null,"text_url":null,"meta":{"original":{"width":600,"height":600,"size":"600x600","aspect":1.0},"small":{"width":480,"height":480,"size":"480x480","aspect":1.0},"focus":{"x":-0.5,"y":0.3}},"description":"John
Lennon doing a funny walk","blurhash":"UGD9YhIn00j[NFofR%M{IURj%Ms;D%of%MR%"},{"id":"109336202375987007","type":"image","url":"http://localhost:3000/system/media_attachments/files/109/336/202/375/987/007/original/974fe7224ae7c409.jpg","preview_url":"http://localhost:3000/system/media_attachments/files/109/336/202/375/987/007/small/974fe7224ae7c409.jpg","remote_url":null,"preview_remote_url":null,"text_url":null,"meta":{"original":{"width":400,"height":400,"size":"400x400","aspect":1.0},"small":{"width":400,"height":400,"size":"400x400","aspect":1.0},"focus":{"x":0.5,"y":0.5}},"description":"hololives
test suite","website":null},"account":{"id":"109336199970122902","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"","locked":true,"bot":false,"discoverable":null,"group":false,"created_at":"2022-11-13T00:00:00.000Z","note":"","url":"http://localhost:3000/@mastodonpy_test","avatar":"http://localhost:3000/avatars/original/missing.png","avatar_static":"http://localhost:3000/avatars/original/missing.png","header":"http://localhost:3000/headers/original/missing.png","header_static":"http://localhost:3000/headers/original/missing.png","followers_count":0,"following_count":0,"statuses_count":0,"last_status_at":"2022-11-13","noindex":false,"emojis":[],"fields":[]},"media_attachments":[{"id":"109336397301097789","type":"image","url":"http://localhost:3000/system/media_attachments/files/109/336/397/301/097/789/original/84fe2e3e1279a737.jpg","preview_url":"http://localhost:3000/system/media_attachments/files/109/336/397/301/097/789/small/84fe2e3e1279a737.jpg","remote_url":null,"preview_remote_url":null,"text_url":null,"meta":{"original":{"width":600,"height":600,"size":"600x600","aspect":1.0},"small":{"width":480,"height":480,"size":"480x480","aspect":1.0},"focus":{"x":-0.5,"y":0.3}},"description":"John
Lennon doing a funny walk","blurhash":"UGD9YhIn00j[NFofR%M{IURj%Ms;D%of%MR%"},{"id":"109336397314377564","type":"image","url":"http://localhost:3000/system/media_attachments/files/109/336/397/314/377/564/original/fb76e61bbb716e34.jpg","preview_url":"http://localhost:3000/system/media_attachments/files/109/336/397/314/377/564/small/fb76e61bbb716e34.jpg","remote_url":null,"preview_remote_url":null,"text_url":null,"meta":{"original":{"width":400,"height":400,"size":"400x400","aspect":1.0},"small":{"width":400,"height":400,"size":"400x400","aspect":1.0},"focus":{"x":0.5,"y":0.5}},"description":"hololives
#1 detective, watson ameliachan","blurhash":"UPNKI$xbloIA9ZoI.8RjK-oy%NkD%hW?i^t6"}],"mentions":[],"tags":[],"emojis":[],"card":null,"poll":null}'
headers:
Cache-Control:
@ -1893,7 +1893,7 @@ interactions:
Content-Security-Policy:
- 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src
''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000;
style-src ''self'' http://localhost:3000 ''nonce-etQkSyqdGCt/N0Rl9QVEgg=='';
style-src ''self'' http://localhost:3000 ''nonce-6xa4wBM0rfSdorPiv4aWDw=='';
media-src ''self'' https: data: http://localhost:3000; frame-src ''self''
https:; manifest-src ''self'' http://localhost:3000; connect-src ''self''
data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000
@ -1903,7 +1903,7 @@ interactions:
Content-Type:
- application/json; charset=utf-8
ETag:
- W/"992cf9d795946847173bd5f2fc63002d"
- W/"329b71ac92625b1e9273ed664450a738"
Referrer-Policy:
- strict-origin-when-cross-origin
Transfer-Encoding:
@ -1919,9 +1919,9 @@ interactions:
X-Permitted-Cross-Domain-Policies:
- none
X-Request-Id:
- cb005fbc-e112-414c-861c-01ff2796cebf
- fe402c72-a87b-41cd-892f-b2a0e29bd156
X-Runtime:
- '0.023174'
- '0.025771'
X-XSS-Protection:
- 1; mode=block
status:

Wyświetl plik

@ -103,16 +103,19 @@ def test_media_post_multiple(api):
@pytest.mark.vcr(match_on=['path'])
def test_media_update(api):
media = api.media_post(
'tests/image.jpg',
description="John Lennon doing a funny walk",
focus=(-0.5, 0.3))
'tests/video.mp4',
description="me when a cat",
focus=(-0.5, 0.3)
)
assert media
media_up = api.media_update(
media,
description="John Lennon doing a cool walk",
focus=(0.69, 0.69))
media,
description="John Lennon doing a cool walk",
focus=(0.69, 0.69),
thumbnail='tests/amewatson.jpg'
)
assert media_up
assert media_up['description'] == "John Lennon doing a cool walk"