From d0b1da993d4a38469106d6bd52dab6254bbd0053 Mon Sep 17 00:00:00 2001 From: halcy Date: Tue, 8 Nov 2022 23:24:42 +0200 Subject: add media v2 API + tests, move v1 test --- tests/test_media.py | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 3 deletions(-) (limited to 'tests/test_media.py') diff --git a/tests/test_media.py b/tests/test_media.py index f2c3b2f..4de654f 100644 --- a/tests/test_media.py +++ b/tests/test_media.py @@ -1,18 +1,53 @@ import pytest +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']) @pytest.mark.vcr(match_on=['path']) @pytest.mark.parametrize('sensitive', (False, True)) def test_media_post(api, sensitive): media = api.media_post( - 'tests/image.jpg', - description="John Lennon doing a funny walk", + 'tests/video.mp4', + description="me when a cat", focus=(-0.5, 0.3)) assert media + assert media.url is None + + time.sleep(10) + media2 = api.media(media) + assert media2.id == media.id + assert not media2.url is None status = api.status_post( 'LOL check this out', - media_ids=media, + media_ids=media2, sensitive=sensitive ) @@ -20,10 +55,45 @@ def test_media_post(api, sensitive): try: assert status['sensitive'] == sensitive + 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']) + +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: 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 + 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 finally: api.status_delete(status['id']) -- cgit v1.2.3