aboutsummaryrefslogtreecommitdiff
blob: 239fac3b4cb80bf8e6cfed8ca1e182e8d16073f9 (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
import pytest
import time
from mastodon.Mastodon import MastodonAPIError, MastodonIllegalArgumentError, MastodonUnauthorizedError
import datetime
import pickle
import os

@pytest.mark.vcr()
def test_public_tl_anonymous(api_anonymous, status3):
    time.sleep(3)
    tl = api_anonymous.timeline_public()
    assert status3['id'] in list(map(lambda st: st['id'], tl))

@pytest.mark.vcr()
def test_public_tl(api, status):
    public = api.timeline_public()
    local = api.timeline_local()
    assert status['id'] in map(lambda st: st['id'], public)
    assert status['id'] in map(lambda st: st['id'], local)

@pytest.mark.vcr()
def test_unauthed_home_tl_throws(api_anonymous, status):
    with pytest.raises(MastodonUnauthorizedError):
        api_anonymous.timeline_home()

@pytest.mark.vcr()
def test_home_tl(api, status):
    time.sleep(3)
    tl = api.timeline_home()
    assert status['id'] in map(lambda st: st['id'], tl)

@pytest.mark.vcr()
def test_hashtag_tl(api):
    status = api.status_post('#hoot (hashtag toot)')
    tl = api.timeline_hashtag('hoot')
    try:
        assert status['id'] in map(lambda st: st['id'], tl)
    finally:
        api.status_delete(status['id'])

def test_hashtag_tl_leading_hash(api):
    with pytest.raises(MastodonIllegalArgumentError):
        api.timeline_hashtag('#hoot')

@pytest.mark.vcr()
def test_home_tl_anonymous_throws(api_anonymous):
    with pytest.raises(MastodonAPIError):
        api_anonymous.timeline_home()

@pytest.mark.vcr()
def test_conversations(api, api2):
    account = api.account_verify_credentials()
    status = api.status_post("@admin ilu bby ;3", visibility="direct")
    time.sleep(2)
    conversations = api2.conversations()
    api2.conversations_read(conversations[0])
    time.sleep(2)
    conversations2 = api2.conversations()
    api.status_delete(status)
    assert conversations
    assert status.id in map(lambda x: x.last_status.id, conversations)
    assert account.id in map(lambda x: x.accounts[0].id, conversations)
    assert conversations[0].unread is True
    assert conversations2[0].unread is False

@pytest.mark.vcr()
def test_min_max_id(api, status):
    time.sleep(3)
    tl = api.timeline_home(min_id = status.id - 1000, max_id = status.id + 1000)
    assert status['id'] in map(lambda st: st['id'], tl)

    tl = api.timeline_home(min_id = status.id - 2000, max_id = status.id - 1000)
    assert not status['id'] in map(lambda st: st['id'], tl)

    tl = api.timeline_home(min_id = status.id + 1000, max_id = status.id + 2000)
    assert not status['id'] in map(lambda st: st['id'], tl)

    tl = api.timeline_home(since_id = status.id - 1000)
    assert status['id'] in map(lambda st: st['id'], tl)

@pytest.mark.vcr()
def test_min_max_id_datetimes(api, status):
    if os.path.exists("tests/cassettes/test_min_max_id_datetimes_datetimeobjects.pkl"):
        data_dict = pickle.load(open("tests/cassettes/test_min_max_id_datetimes_datetimeobjects.pkl", 'rb'))
        the_past = datetime.datetime.fromtimestamp(data_dict["the_past"])
        the_future = datetime.datetime.fromtimestamp(data_dict["the_future"])
        the_far_future = datetime.datetime.fromtimestamp(data_dict["the_far_future"])
    else:
        epoch_time = datetime.datetime.now().timestamp()
        now = datetime.datetime.fromtimestamp(epoch_time)
        the_past = now - datetime.timedelta(seconds=20)
        the_future = now + datetime.timedelta(seconds=20)
        the_far_future = now + datetime.timedelta(seconds=40)
        pickle.dump({
            "the_past": the_past.timestamp(),
            "the_future": the_future.timestamp(),
            "the_far_future": the_far_future.timestamp(),
        }, open("tests/cassettes/test_min_max_id_datetimes_datetimeobjects.pkl", 'wb'))

    time.sleep(3)
    tl = api.timeline_home(min_id = the_past, max_id = the_future)
    assert status['id'] in map(lambda st: st['id'], tl)

    tl = api.timeline_home(min_id = the_future, max_id = the_far_future)
    assert not status['id'] in map(lambda st: st['id'], tl)
Powered by cgit v1.2.3 (git 2.41.0)