Mastodonplus.py/tests/test_status.py

154 líneas
4,6 KiB
Python

2017-11-27 21:36:34 +01:00
import pytest
2018-01-03 11:44:14 +01:00
from mastodon.Mastodon import MastodonAPIError, MastodonNotFoundError
2019-04-28 19:36:12 +02:00
import datetime
import pytz
2017-11-27 21:36:34 +01:00
@pytest.mark.vcr()
def test_status(status, api):
status2 = api.status(status['id'])
2017-11-29 22:03:51 +01:00
assert status2
2018-07-30 21:00:20 +02:00
@pytest.mark.vcr()
def test_status_reply(status, api2):
status2 = api2.status_reply(status, "same!")
try:
assert status2
assert status2.mentions[0].id == status.account.id
finally:
api2.status_delete(status2['id'])
2017-11-29 22:03:51 +01:00
@pytest.mark.vcr()
def test_status_empty(api):
with pytest.raises(MastodonAPIError):
api.status_post('')
2017-11-27 21:36:34 +01:00
@pytest.mark.vcr()
def test_status_missing(api):
2018-01-03 11:44:14 +01:00
with pytest.raises(MastodonNotFoundError):
2017-11-27 21:36:34 +01:00
api.status(0)
2018-04-18 22:00:35 +02:00
# Messy and will only work if there is an internet connection that is decent, obviously.
@pytest.mark.vcr()
2017-11-27 21:36:34 +01:00
def test_status_card(api):
2018-04-18 22:00:35 +02:00
import time
status = api.status_post("http://example.org/")
time.sleep(5) # Card generation may take time
2017-11-27 21:36:34 +01:00
card = api.status_card(status['id'])
2018-04-18 22:00:35 +02:00
try:
assert card
finally:
api.status_delete(status['id'])
2017-11-27 21:36:34 +01:00
@pytest.mark.vcr()
def test_status_context(status, api):
context = api.status_context(status['id'])
assert context
@pytest.mark.vcr()
def test_status_reblogged_by(status, api):
api.status_reblog(status['id'])
reblogs = api.status_reblogged_by(status['id'])
assert reblogs
@pytest.mark.vcr()
2019-04-28 21:24:31 +02:00
def test_status_reblog_visibility(status, api):
reblog_result = api.status_reblog(status['id'], visibility = 'unlisted')
assert reblog_result.visibility == 'unlisted'
@pytest.mark.vcr()
2017-11-27 21:36:34 +01:00
def test_status_favourited_by(status, api):
api.status_favourite(status['id'])
favourites = api.status_favourited_by(status['id'])
assert favourites
2017-11-27 22:52:19 +01:00
@pytest.mark.vcr()
def test_toot(api):
status = api.toot('Toot!')
try:
assert status
finally:
api.status_delete(status['id'])
@pytest.mark.vcr()
2018-04-18 22:00:35 +02:00
@pytest.mark.parametrize('visibility', (None, 'direct', 'private', 'unlisted', 'public',
pytest.param('foobar', marks=pytest.mark.xfail(strict=True))))
2017-11-27 22:52:19 +01:00
@pytest.mark.parametrize('spoiler_text', (None, 'Content warning'))
def test_status_post(api, visibility, spoiler_text):
status = api.status_post(
'Toot!',
visibility=visibility,
spoiler_text=spoiler_text)
try:
assert status
if visibility:
assert status['visibility'] == visibility
if spoiler_text:
assert status['spoiler_text'] == spoiler_text
finally:
api.status_delete(status['id'])
@pytest.mark.vcr()
def test_status_reblog_unreblog(status, api):
reblog = api.status_reblog(status['id'])
assert reblog
status = reblog['reblog']
assert status['reblogged']
status = api.status_unreblog(status['id'])
assert not status['reblogged']
@pytest.mark.vcr()
def test_status_fav_unfav(status, api):
status = api.status_favourite(status['id'])
assert status['favourited']
status = api.status_unfavourite(status['id'])
assert not status['favourited']
2017-11-30 02:26:28 +01:00
@pytest.mark.vcr()
def test_favourites(api):
favs = api.favourites()
assert isinstance(favs, list)
2017-11-27 22:52:19 +01:00
@pytest.mark.vcr()
def test_status_mute_unmute(status, api):
status = api.status_mute(status['id'])
assert status['muted']
status = api.status_unmute(status['id'])
assert not status['muted']
2018-06-04 20:55:44 +02:00
@pytest.mark.vcr()
def test_status_pin_unpin(status, api):
status = api.status_pin(status['id'])
assert status['pinned']
status = api.status_unpin(status['id'])
assert not status['pinned']
2019-04-28 19:36:12 +02:00
@pytest.mark.vcr(match_on=['path'])
2019-04-28 19:36:12 +02:00
def test_scheduled_status(api):
base_time = datetime.datetime(4000, 1, 1, 12, 13, 14, 0, pytz.timezone("Etc/GMT+2"))
2019-04-28 19:46:20 +02:00
the_future = base_time + datetime.timedelta(minutes=20)
2019-04-28 19:36:12 +02:00
scheduled_toot = api.status_post("please ensure adequate headroom", scheduled_at=the_future)
assert scheduled_toot
2019-04-28 19:46:20 +02:00
the_immediate_future = base_time + datetime.timedelta(minutes=10)
2019-04-28 19:36:12 +02:00
scheduled_toot_2 = api.scheduled_status_update(scheduled_toot, the_immediate_future)
assert scheduled_toot_2
assert scheduled_toot_2.id == scheduled_toot.id
assert scheduled_toot_2.scheduled_at < scheduled_toot.scheduled_at
scheduled_toot_list = api.scheduled_statuses()
assert scheduled_toot_2.id in map(lambda x: x.id, scheduled_toot_list)
scheduled_toot_3 = api.scheduled_status(scheduled_toot.id)
assert scheduled_toot_2.id == scheduled_toot_3.id
api.scheduled_status_delete(scheduled_toot_2)
scheduled_toot_list_2 = api.scheduled_statuses()
assert not scheduled_toot_2.id in map(lambda x: x.id, scheduled_toot_list_2)