Mastodon.py/tests/test_timeline.py

97 wiersze
3.6 KiB
Python
Czysty Zwykły widok Historia

2017-11-27 13:19:21 +00:00
import pytest
2019-04-28 11:47:43 +00:00
import time
2022-11-17 18:50:23 +00:00
from mastodon.Mastodon import MastodonAPIError, MastodonIllegalArgumentError, MastodonUnauthorizedError
import datetime
2022-11-17 20:00:37 +00:00
import pickle
import os
2017-11-27 13:19:21 +00:00
@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))
2017-11-27 13:19:21 +00:00
@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)
2017-11-27 13:19:21 +00:00
2018-01-03 10:44:14 +00:00
@pytest.mark.vcr()
def test_unauthed_home_tl_throws(api_anonymous, status):
with pytest.raises(MastodonUnauthorizedError):
api_anonymous.timeline_home()
2017-11-27 13:19:21 +00:00
@pytest.mark.vcr()
def test_home_tl(api, status):
time.sleep(3)
tl = api.timeline_home()
2017-11-27 13:19:21 +00:00
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')
2017-11-27 13:19:21 +00:00
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()
2019-04-28 11:47:43 +00:00
@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()
2019-04-28 11:47:43 +00:00
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 == True
assert conversations2[0].unread == False
2022-11-17 18:50:23 +00:00
@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):
2022-11-17 20:00:37 +00:00
if os.path.exists("tests/cassettes/test_min_max_id_datetimes_datetimeobjects.pkl"):
the_past, the_future, the_far_future = pickle.load(open("tests/cassettes/test_min_max_id_datetimes_datetimeobjects.pkl", 'rb'))
else:
the_past = datetime.datetime.now() - datetime.timedelta(seconds=20)
the_future = datetime.datetime.now() + datetime.timedelta(seconds=20)
the_far_future = datetime.datetime.now() + datetime.timedelta(seconds=40)
pickle.dump((the_past, the_future, the_far_future), open("tests/cassettes/test_min_max_id_datetimes_datetimeobjects.pkl", 'wb'))
2022-11-17 18:50:23 +00:00
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)