2017-11-27 22:49:14 +00:00
|
|
|
import pytest
|
2022-11-08 21:24:42 +00:00
|
|
|
import vcr
|
|
|
|
import time
|
|
|
|
|
|
|
|
@pytest.mark.vcr(match_on=['path'])
|
|
|
|
def test_media_post_v1(api):
|
|
|
|
with vcr.use_cassette('test_media_post.yaml', cassette_library_dir='tests/cassettes_pre_4_0_0', record_mode='none'):
|
|
|
|
media = api.media_post(
|
|
|
|
'tests/image.jpg',
|
|
|
|
description="John Lennon doing a funny walk",
|
|
|
|
focus=(-0.5, 0.3))
|
|
|
|
|
|
|
|
assert media
|
|
|
|
|
|
|
|
status = api.status_post(
|
|
|
|
'LOL check this out',
|
|
|
|
media_ids=media,
|
|
|
|
sensitive=False
|
|
|
|
)
|
|
|
|
|
|
|
|
assert status
|
|
|
|
|
|
|
|
try:
|
|
|
|
assert status['sensitive'] == False
|
|
|
|
assert status['media_attachments']
|
|
|
|
assert status['media_attachments'][0]['description'] == "John Lennon doing a funny walk"
|
|
|
|
assert status['media_attachments'][0]['meta']['focus']['x'] == -0.5
|
|
|
|
assert status['media_attachments'][0]['meta']['focus']['y'] == 0.3
|
|
|
|
finally:
|
|
|
|
api.status_delete(status['id'])
|
2017-11-27 22:49:14 +00:00
|
|
|
|
|
|
|
@pytest.mark.vcr(match_on=['path'])
|
|
|
|
@pytest.mark.parametrize('sensitive', (False, True))
|
|
|
|
def test_media_post(api, sensitive):
|
|
|
|
media = api.media_post(
|
2022-11-13 11:14:34 +00:00
|
|
|
'tests/video.mp4',
|
|
|
|
description="me when a cat",
|
|
|
|
focus=(-0.5, 0.3),
|
|
|
|
thumbnail='tests/amewatson.jpg'
|
|
|
|
)
|
2018-06-04 19:20:43 +00:00
|
|
|
|
2017-11-27 22:49:14 +00:00
|
|
|
assert media
|
2022-11-08 21:24:42 +00:00
|
|
|
assert media.url is None
|
|
|
|
|
|
|
|
time.sleep(10)
|
|
|
|
media2 = api.media(media)
|
|
|
|
assert media2.id == media.id
|
|
|
|
assert not media2.url is None
|
2017-11-27 22:49:14 +00:00
|
|
|
|
|
|
|
status = api.status_post(
|
2022-11-13 11:14:34 +00:00
|
|
|
'LOL check this out',
|
|
|
|
media_ids=media2,
|
|
|
|
sensitive=sensitive
|
|
|
|
)
|
2017-11-27 22:49:14 +00:00
|
|
|
|
|
|
|
assert status
|
|
|
|
|
|
|
|
try:
|
|
|
|
assert status['sensitive'] == sensitive
|
2022-11-08 21:24:42 +00:00
|
|
|
assert status['media_attachments']
|
|
|
|
assert status['media_attachments'][0]['description'] == "me when a cat"
|
|
|
|
assert status['media_attachments'][0]['meta']['focus']['x'] == -0.5
|
|
|
|
assert status['media_attachments'][0]['meta']['focus']['y'] == 0.3
|
|
|
|
finally:
|
|
|
|
api.status_delete(status['id'])
|
|
|
|
|
2022-11-10 23:14:38 +00:00
|
|
|
@pytest.mark.vcr(match_on=['path'])
|
2022-11-08 21:24:42 +00:00
|
|
|
def test_media_post_multiple(api):
|
|
|
|
media = api.media_post(
|
|
|
|
'tests/image.jpg',
|
|
|
|
description="John Lennon doing a funny walk",
|
|
|
|
focus=(-0.5, 0.3),
|
|
|
|
synchronous=True)
|
|
|
|
media2 = api.media_post(
|
|
|
|
'tests/amewatson.jpg',
|
|
|
|
description="hololives #1 detective, watson ameliachan",
|
|
|
|
focus=(0.5, 0.5),
|
|
|
|
synchronous=True)
|
|
|
|
|
|
|
|
assert media
|
|
|
|
assert media.url is not None
|
|
|
|
assert media2
|
|
|
|
assert media2.url is not None
|
|
|
|
|
|
|
|
status = api.status_post(
|
|
|
|
'LOL check this out',
|
|
|
|
media_ids=[media, media2.id],
|
|
|
|
)
|
|
|
|
|
|
|
|
assert status
|
|
|
|
|
|
|
|
try:
|
2017-11-27 22:49:14 +00:00
|
|
|
assert status['media_attachments']
|
2018-06-05 09:39:31 +00:00
|
|
|
assert status['media_attachments'][0]['description'] == "John Lennon doing a funny walk"
|
2018-06-04 19:20:43 +00:00
|
|
|
assert status['media_attachments'][0]['meta']['focus']['x'] == -0.5
|
|
|
|
assert status['media_attachments'][0]['meta']['focus']['y'] == 0.3
|
2022-11-08 21:24:42 +00:00
|
|
|
assert status['media_attachments'][1]['description'] == "hololives #1 detective, watson ameliachan"
|
|
|
|
assert status['media_attachments'][1]['meta']['focus']['x'] == 0.5
|
|
|
|
assert status['media_attachments'][1]['meta']['focus']['y'] == 0.5
|
2017-11-27 22:49:14 +00:00
|
|
|
finally:
|
|
|
|
api.status_delete(status['id'])
|
|
|
|
|
2018-06-05 20:52:18 +00:00
|
|
|
@pytest.mark.vcr(match_on=['path'])
|
|
|
|
def test_media_update(api):
|
|
|
|
media = api.media_post(
|
2022-11-13 12:06:50 +00:00
|
|
|
'tests/video.mp4',
|
|
|
|
description="me when a cat",
|
|
|
|
focus=(-0.5, 0.3)
|
|
|
|
)
|
2018-06-05 20:52:18 +00:00
|
|
|
|
|
|
|
assert media
|
|
|
|
|
|
|
|
media_up = api.media_update(
|
2022-11-13 12:06:50 +00:00
|
|
|
media,
|
|
|
|
description="John Lennon doing a cool walk",
|
|
|
|
focus=(0.69, 0.69),
|
|
|
|
thumbnail='tests/amewatson.jpg'
|
|
|
|
)
|
2018-06-05 20:52:18 +00:00
|
|
|
|
|
|
|
assert media_up
|
|
|
|
assert media_up['description'] == "John Lennon doing a cool walk"
|
|
|
|
assert media_up['meta']['focus']['x'] == 0.69
|
|
|
|
assert media_up['meta']['focus']['y'] == 0.69
|
|
|
|
|
2017-11-27 22:49:14 +00:00
|
|
|
@pytest.mark.vcr(match_on=['path'])
|
|
|
|
def test_media_post_file(api):
|
|
|
|
with open('tests/image.jpg', 'rb') as f:
|
|
|
|
media = api.media_post(f, mime_type='image/jpeg')
|
|
|
|
assert media
|