aboutsummaryrefslogtreecommitdiff
blob: afc2122b0674f575c5797a7699f40ac8e8d6b531 (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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
import pytest
from mastodon.Mastodon import MastodonAPIError, MastodonIllegalArgumentError
import re
import time

@pytest.mark.vcr()
def test_account(api):
    account = api.account(api.account_verify_credentials())
    assert account

@pytest.mark.vcr()
def test_verify_credentials(api):
    account_a = api.account_verify_credentials()
    account_b = api.me()
    
    assert account_a.id == account_b.id
    
@pytest.mark.vcr()
def test_account_following(api):
    following = api.account_following(api.account_verify_credentials())
    assert isinstance(following, list)


@pytest.mark.vcr()
def test_account_followers(api):
    followers = api.account_followers(api.account_verify_credentials())
    assert isinstance(followers, list)


@pytest.mark.vcr()
def test_account_relationships(api):
    relationships = api.account_relationships(api.account_verify_credentials())
    assert isinstance(relationships, list)
    assert len(relationships) == 1

@pytest.mark.vcr()
def test_account_search(api):
    results = api.account_search('admin')
    admin_acc = results[0]
    
    assert isinstance(results, list)
    assert len(results) == 2

    api.account_follow(admin_acc)
    results = api.account_search('admin', following = True)
    assert isinstance(results, list)
    assert len(results) == 1
    
    api.account_unfollow(admin_acc)
    results = api.account_search('admin', following = True)
    assert isinstance(results, list)
    assert len(results) == 0
    
    results = api.account_search('admin')
    assert isinstance(results, list)
    assert len(results) == 2
    
@pytest.mark.vcr()
def test_account_follow_unfollow(api, api2):
    api2_id = api2.account_verify_credentials().id
    relationship = api.account_follow(api2_id)
    try:
        assert relationship
        print(relationship)
        assert relationship['following']
    finally:
        relationship = api.account_unfollow(api2_id)
        assert relationship
        assert not relationship['following']

@pytest.mark.vcr()
def test_account_block_unblock(api, api2):
    api2_id = api2.account_verify_credentials().id
    relationship = api.account_block(api2_id)
    try:
        assert relationship
        assert relationship['blocking']
    finally:
        relationship = api.account_unblock(api2_id)
        assert relationship
        assert not relationship['blocking']

@pytest.mark.vcr()
def test_account_mute_unmute(api, api2):
    api2_id = api2.account_verify_credentials().id
    relationship = api.account_mute(api2_id)
    try:
        assert relationship
        assert relationship['muting']
    finally:
        relationship = api.account_unmute(api2_id)
        assert relationship
        assert not relationship['muting']

    relationship = api.account_mute(api2_id, duration = 3)
    time.sleep(8)
    assert not api.account_relationships(api2_id)[0].muting        

@pytest.mark.vcr()
def test_mutes(api):
    mutes = api.mutes()
    assert isinstance(mutes, list)


@pytest.mark.vcr()
def test_blocks(api):
    blocks = api.blocks()
    assert isinstance(blocks, list)

@pytest.mark.vcr(match_on=['path'])
def test_account_update_credentials(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',
        avatar = "tests/image.jpg",
        header = image,
        header_mime_type = "image/jpeg",
        fields = [
            ("bread", "toasty."),
            ("lasagna", "no!!!"),
        ]
    )
    
    assert account
    assert account["display_name"] == 'John Lennon'
    assert re.sub("<.*?>", " ", account["note"]).strip() == 'I walk funny'
    assert account["fields"][0].name == "bread"
    assert account["fields"][0].value == "toasty."
    assert account["fields"][1].name == "lasagna"
    assert account["fields"][1].value == "no!!!"

@pytest.mark.vcr()
def test_account_update_credentials_too_many_fields(api):
    with pytest.raises(MastodonIllegalArgumentError):
        api.account_update_credentials(fields = [
            ('a', 'b'),
            ('c', 'd'), 
            ('e', 'f'), 
            ('g', 'h'), 
            ('i', 'j'),
        ])

@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

@pytest.mark.vcr()
def test_account_pinned(status, status2, api):
    try:
        status = api.status_pin(status['id'])
        pinned = api.account_statuses(api.account_verify_credentials(), pinned = True)
        assert status in pinned
        assert not status2 in pinned
    finally:
        api.status_unpin(status['id'])

@pytest.mark.vcr()
def test_follow_suggestions(api2, status):
    api2.status_favourite(status)
    
    suggestions = api2.suggestions()
    assert(suggestions)
    assert(len(suggestions) > 0)
    
    api2.suggestion_delete(suggestions[0])
    suggestions2 = api2.suggestions()
    assert(len(suggestions2) < len(suggestions))
    
@pytest.mark.vcr()
def test_account_pin_unpin(api, api2):
    user = api2.account_verify_credentials()
    
    # Make sure we are in the correct state
    try:
        api.account_follow(user)
    except:
        pass
    
    try:
        api.account_unpin(user)
    except:
        pass
    
    relationship = api.account_pin(user)
    endorsed = api.endorsements()
        
    try:
        assert relationship
        assert relationship['endorsed']
        assert user["id"] in map(lambda x: x["id"], endorsed)
    finally:
        relationship = api.account_unpin(user)
        endorsed2 = api.endorsements()
        api.account_unfollow(user)        
        assert relationship
        assert not relationship['endorsed']
        assert not user["id"] in map(lambda x: x["id"], endorsed2)

@pytest.mark.vcr()
def test_preferences(api):
    prefs = api.preferences()
    assert prefs

@pytest.mark.vcr()
def test_suggested_tags(api):
    try:
        status = api.status_post("cool free #ringtones")
        time.sleep(2)
        
        suggests = api.featured_tag_suggestions()
        assert suggests
        assert len(suggests) > 0
    finally:
        api.status_delete(status)
    
@pytest.mark.vcr()
def test_featured_tags(api):
    try:
        featured_tag = api.featured_tag_create("ringtones")
        assert featured_tag
        assert featured_tag.name == "ringtones"

        featured_tag_2 = api.featured_tag_create("#coolfree")
        assert featured_tag_2
        assert featured_tag_2.name == "coolfree"

        api.featured_tag_delete(featured_tag)
        featured_tag = None

        featured_tag_list = api.account_featured_tags(api.account_verify_credentials())
        assert len(featured_tag_list) == 1
        assert featured_tag_list[0].name == "coolfree"
        assert "url" in featured_tag_list[0]
    finally:
        if featured_tag is not None:
            api.featured_tag_delete(featured_tag)
        api.featured_tag_delete(featured_tag_2) 

@pytest.mark.vcr()
def test_account_notes(api, api2):
    relationship = api.account_note_set(api2.account_verify_credentials(), "top ebayer gerne wieder")
    assert relationship
    assert relationship.note == "top ebayer gerne wieder"

@pytest.mark.vcr()
def test_follow_with_notify_reblog(api, api2, api3):
    api2_id = api2.account_verify_credentials()
    try:
        api.account_follow(api2_id, notify = True, reblogs = False)
        status1 = api3.toot("rootin tooting and shootin")
        time.sleep(1)
        status2 = api2.toot("horses are not real")
        api2.status_reblog(status1)
        time.sleep(3)
        notifications = api.notifications()
        timeline = api.timeline(local=True)
        assert timeline[0].id == status2.id
        assert notifications[0].status.id == status2.id
    finally:
        api.account_unfollow(api2_id)
        api3.status_delete(status1)
        api2.status_delete(status2)

@pytest.mark.vcr()
def test_account_lookup(api, api3):
    id = api.me().id
    try:
        api.account_lookup("kljadklajsdkljlkjlkjlkjasdasd")
        assert False
    except:
        pass
    assert(api.account_lookup("mastodonpy_test").id == id)
    assert(api.account_lookup("mastodonpy_test@localhost:3000").id == id)

@pytest.mark.vcr()
def test_account_familiar_followers(api, api2, api3):
    followers_list = api.account_familiar_followers(api2.me())
    assert followers_list
    assert len(followers_list) == 1
    assert followers_list[0].id == api2.me().id
    assert "accounts" in followers_list[0]

    followers_list = api.account_familiar_followers([api2.me(), api3.me()])
    assert followers_list
    assert len(followers_list) == 2
    assert followers_list[0].id == api2.me().id
    assert followers_list[1].id == api3.me().id

@pytest.mark.vcr()
def test_account_remove_from_followers(api, api2):
    api.account_follow(api2.me())
    assert api.account_relationships(api2.me())[0].following == True
    api2.account_remove_from_followers(api.me())
    assert api.account_relationships(api2.me())[0].following == False
Powered by cgit v1.2.3 (git 2.41.0)