aboutsummaryrefslogtreecommitdiff
blob: 4de654f3796b9dd8cb82113173849cbb05c4ea37 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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/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=media2,
            sensitive=sensitive
            )

    assert status

    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'])

@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))
    
    assert media

    media_up = api.media_update(
            media,
            description="John Lennon doing a cool walk",
            focus=(0.69, 0.69))

    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

@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
Powered by cgit v1.2.3 (git 2.41.0)