2017-11-29 23:56:35 +00:00
|
|
|
import pytest
|
2018-06-04 23:54:12 +00:00
|
|
|
from mastodon.Mastodon import MastodonAPIError, MastodonIllegalArgumentError
|
|
|
|
import re
|
2019-10-12 19:47:58 +00:00
|
|
|
import time
|
2017-11-29 23:56:35 +00:00
|
|
|
|
|
|
|
@pytest.mark.vcr()
|
|
|
|
def test_account(api):
|
2022-11-13 13:33:10 +00:00
|
|
|
account = api.account(api.account_verify_credentials())
|
2017-11-29 23:56:35 +00:00
|
|
|
assert account
|
|
|
|
|
2024-10-22 21:58:14 +00:00
|
|
|
@pytest.mark.vcr()
|
|
|
|
def test_accounts(api):
|
|
|
|
account_ids = [
|
|
|
|
api.account_lookup("mastodonpy_test").id,
|
|
|
|
api.account_lookup("mastodonpy_test_2").id
|
|
|
|
]
|
|
|
|
accounts = api.accounts(account_ids)
|
|
|
|
assert len(accounts) == 2
|
|
|
|
|
2019-10-12 17:05:46 +00:00
|
|
|
@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
|
|
|
|
|
2017-11-29 23:56:35 +00:00
|
|
|
@pytest.mark.vcr()
|
|
|
|
def test_account_following(api):
|
2022-11-13 13:33:10 +00:00
|
|
|
following = api.account_following(api.account_verify_credentials())
|
2017-11-29 23:56:35 +00:00
|
|
|
assert isinstance(following, list)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.vcr()
|
|
|
|
def test_account_followers(api):
|
2022-11-13 13:33:10 +00:00
|
|
|
followers = api.account_followers(api.account_verify_credentials())
|
2017-11-29 23:56:35 +00:00
|
|
|
assert isinstance(followers, list)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.vcr()
|
|
|
|
def test_account_relationships(api):
|
2022-11-13 13:33:10 +00:00
|
|
|
relationships = api.account_relationships(api.account_verify_credentials())
|
2017-11-29 23:56:35 +00:00
|
|
|
assert isinstance(relationships, list)
|
|
|
|
assert len(relationships) == 1
|
|
|
|
|
|
|
|
@pytest.mark.vcr()
|
|
|
|
def test_account_search(api):
|
|
|
|
results = api.account_search('admin')
|
2018-07-13 23:03:42 +00:00
|
|
|
admin_acc = results[0]
|
|
|
|
|
2017-11-29 23:56:35 +00:00
|
|
|
assert isinstance(results, list)
|
2022-11-07 21:11:30 +00:00
|
|
|
assert len(results) == 2
|
2017-11-29 23:56:35 +00:00
|
|
|
|
2018-07-13 23:03:42 +00:00
|
|
|
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)
|
2022-11-07 21:11:30 +00:00
|
|
|
assert len(results) == 2
|
2018-07-13 23:03:42 +00:00
|
|
|
|
2017-11-29 23:56:35 +00:00
|
|
|
@pytest.mark.vcr()
|
2022-11-13 13:33:10 +00:00
|
|
|
def test_account_follow_unfollow(api, api2):
|
|
|
|
api2_id = api2.account_verify_credentials().id
|
|
|
|
relationship = api.account_follow(api2_id)
|
2017-11-29 23:56:35 +00:00
|
|
|
try:
|
|
|
|
assert relationship
|
|
|
|
assert relationship['following']
|
|
|
|
finally:
|
2022-11-13 13:33:10 +00:00
|
|
|
relationship = api.account_unfollow(api2_id)
|
2017-11-29 23:56:35 +00:00
|
|
|
assert relationship
|
|
|
|
assert not relationship['following']
|
|
|
|
|
|
|
|
@pytest.mark.vcr()
|
2022-11-13 13:33:10 +00:00
|
|
|
def test_account_block_unblock(api, api2):
|
|
|
|
api2_id = api2.account_verify_credentials().id
|
|
|
|
relationship = api.account_block(api2_id)
|
2017-11-29 23:56:35 +00:00
|
|
|
try:
|
|
|
|
assert relationship
|
|
|
|
assert relationship['blocking']
|
|
|
|
finally:
|
2022-11-13 13:33:10 +00:00
|
|
|
relationship = api.account_unblock(api2_id)
|
2017-11-29 23:56:35 +00:00
|
|
|
assert relationship
|
|
|
|
assert not relationship['blocking']
|
|
|
|
|
|
|
|
@pytest.mark.vcr()
|
2022-11-13 13:33:10 +00:00
|
|
|
def test_account_mute_unmute(api, api2):
|
|
|
|
api2_id = api2.account_verify_credentials().id
|
|
|
|
relationship = api.account_mute(api2_id)
|
2017-11-29 23:56:35 +00:00
|
|
|
try:
|
|
|
|
assert relationship
|
|
|
|
assert relationship['muting']
|
|
|
|
finally:
|
2022-11-13 13:33:10 +00:00
|
|
|
relationship = api.account_unmute(api2_id)
|
2017-11-29 23:56:35 +00:00
|
|
|
assert relationship
|
|
|
|
assert not relationship['muting']
|
|
|
|
|
2022-11-13 13:33:10 +00:00
|
|
|
relationship = api.account_mute(api2_id, duration = 3)
|
|
|
|
time.sleep(8)
|
|
|
|
assert not api.account_relationships(api2_id)[0].muting
|
2017-11-29 23:56:35 +00:00
|
|
|
|
2017-11-30 01:24:16 +00:00
|
|
|
@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)
|
|
|
|
|
2018-04-18 20:11:32 +00:00
|
|
|
@pytest.mark.vcr(match_on=['path'])
|
2017-11-29 23:56:35 +00:00
|
|
|
def test_account_update_credentials(api):
|
|
|
|
with open('tests/image.jpg', 'rb') as f:
|
|
|
|
image = f.read()
|
|
|
|
|
|
|
|
account = api.account_update_credentials(
|
2018-06-04 23:54:12 +00:00
|
|
|
display_name='John Lennon',
|
|
|
|
note='I walk funny',
|
|
|
|
avatar = "tests/image.jpg",
|
|
|
|
header = image,
|
|
|
|
header_mime_type = "image/jpeg",
|
|
|
|
fields = [
|
|
|
|
("bread", "toasty."),
|
|
|
|
("lasagna", "no!!!"),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2023-06-23 22:31:51 +00:00
|
|
|
print(type(account.fields))
|
2017-11-29 23:56:35 +00:00
|
|
|
assert account
|
2023-06-19 21:35:03 +00:00
|
|
|
assert account.id
|
2018-06-04 23:54:12 +00:00
|
|
|
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!!!"
|
|
|
|
|
2025-02-14 21:45:52 +00:00
|
|
|
api.account_delete_avatar()
|
|
|
|
api.account_delete_header()
|
|
|
|
|
2018-06-04 23:54:12 +00:00
|
|
|
@pytest.mark.vcr()
|
|
|
|
def test_account_update_credentials_too_many_fields(api):
|
2023-06-23 20:16:44 +00:00
|
|
|
with pytest.raises(MastodonAPIError):
|
2018-06-04 23:54:12 +00:00
|
|
|
api.account_update_credentials(fields = [
|
|
|
|
('a', 'b'),
|
|
|
|
('c', 'd'),
|
|
|
|
('e', 'f'),
|
|
|
|
('g', 'h'),
|
|
|
|
('i', 'j'),
|
|
|
|
])
|
2018-05-20 10:55:25 +00:00
|
|
|
|
|
|
|
@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
|
2018-06-04 18:55:44 +00:00
|
|
|
|
|
|
|
@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:
|
2018-07-13 23:03:42 +00:00
|
|
|
api.status_unpin(status['id'])
|
2018-07-30 19:14:40 +00:00
|
|
|
|
|
|
|
@pytest.mark.vcr()
|
2025-02-13 21:35:34 +00:00
|
|
|
def test_follow_suggestions(api2):
|
|
|
|
"""
|
|
|
|
status2 = None
|
|
|
|
try:
|
|
|
|
# Ensure we don't follow
|
|
|
|
api2.account_unfollow(api3.account_verify_credentials())
|
|
|
|
|
|
|
|
# Post a bunch and interact
|
|
|
|
status = api3.status_post("even cooler free #ringtones")
|
|
|
|
api2.status_reblog(status)
|
|
|
|
api2.status_favourite(status)
|
|
|
|
api2.status_reblog(status3)
|
|
|
|
api2.status_favourite(status3)
|
|
|
|
status2 = api3.status_post("even cooler free #ringtones")
|
|
|
|
status2 = api2.status_post("i also like #ringtones", visibility = "public")
|
|
|
|
api3.status_reblog(status2)
|
|
|
|
api3.status_favourite(status2)
|
|
|
|
api3.account_follow(api2.account_verify_credentials())
|
|
|
|
time.sleep(2)
|
|
|
|
|
|
|
|
suggestions = api2.suggestions()
|
|
|
|
assert(suggestions)
|
|
|
|
assert(len(suggestions) > 0)
|
|
|
|
|
|
|
|
api2.suggestion_delete(suggestions[0])
|
|
|
|
suggestions2 = api2.suggestions()
|
|
|
|
assert(len(suggestions2) < len(suggestions))
|
|
|
|
finally:
|
|
|
|
api3.status_delete(status)
|
|
|
|
if status2 is not None:
|
|
|
|
api2.status_delete(status2)
|
|
|
|
"""
|
|
|
|
# In 3.4.0+, it doesn't seem possible to seed suggestions like before, so instead,
|
|
|
|
# we just test the endpoints function
|
2019-04-27 19:04:06 +00:00
|
|
|
suggestions = api2.suggestions()
|
2025-02-13 21:35:34 +00:00
|
|
|
assert isinstance(suggestions, list)
|
|
|
|
suggestions = api2.suggestions_v2()
|
|
|
|
assert isinstance(suggestions, list)
|
|
|
|
suggestions = api2.suggestions_v1()
|
|
|
|
assert isinstance(suggestions, list)
|
|
|
|
|
2019-04-27 20:13:27 +00:00
|
|
|
@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']
|
2022-12-03 21:04:26 +00:00
|
|
|
assert any(x["id"] == user["id"] for x in endorsed)
|
2019-04-27 20:13:27 +00:00
|
|
|
finally:
|
|
|
|
relationship = api.account_unpin(user)
|
|
|
|
endorsed2 = api.endorsements()
|
|
|
|
api.account_unfollow(user)
|
|
|
|
assert relationship
|
|
|
|
assert not relationship['endorsed']
|
2022-12-03 21:04:26 +00:00
|
|
|
assert not any(x["id"] == user["id"] for x in endorsed2)
|
2019-04-27 20:13:27 +00:00
|
|
|
|
2019-04-28 19:53:01 +00:00
|
|
|
@pytest.mark.vcr()
|
|
|
|
def test_preferences(api):
|
|
|
|
prefs = api.preferences()
|
|
|
|
assert prefs
|
2019-10-12 19:47:58 +00:00
|
|
|
|
|
|
|
@pytest.mark.vcr()
|
|
|
|
def test_suggested_tags(api):
|
2023-06-19 21:35:03 +00:00
|
|
|
status = None
|
2019-10-12 19:47:58 +00:00
|
|
|
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):
|
2023-06-19 21:35:03 +00:00
|
|
|
featured_tag = None
|
|
|
|
featured_tag_2 = None
|
2022-11-13 12:54:23 +00:00
|
|
|
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:
|
2022-11-20 19:14:25 +00:00
|
|
|
if featured_tag is not None:
|
2022-11-13 12:54:23 +00:00
|
|
|
api.featured_tag_delete(featured_tag)
|
2023-06-19 21:35:03 +00:00
|
|
|
if featured_tag_2 is not None:
|
|
|
|
api.featured_tag_delete(featured_tag_2)
|
2022-11-07 21:11:30 +00:00
|
|
|
|
2025-02-13 21:35:34 +00:00
|
|
|
@pytest.mark.vcr()
|
|
|
|
def test_followed_hashtags(api):
|
2025-02-13 23:34:02 +00:00
|
|
|
api.tag_unfollow("heeho")
|
2025-02-13 21:35:34 +00:00
|
|
|
followed_1 = api.followed_tags()
|
2025-02-13 23:34:02 +00:00
|
|
|
tag_1 = api.tag_follow("heeho")
|
2025-02-13 21:35:34 +00:00
|
|
|
assert tag_1.name == "heeho"
|
|
|
|
assert tag_1.following == True
|
|
|
|
followed_2 = api.followed_tags()
|
|
|
|
assert len(followed_1) < len(followed_2)
|
2025-02-13 23:34:02 +00:00
|
|
|
tag_2 = api.tag_unfollow(tag_1)
|
2025-02-13 21:35:34 +00:00
|
|
|
assert tag_2.following == False
|
|
|
|
tag_3 = api.tag("heeho")
|
|
|
|
assert tag_3.following == False
|
|
|
|
with pytest.raises(MastodonIllegalArgumentError):
|
|
|
|
api.tag("#heeho")
|
|
|
|
|
2022-11-13 12:22:43 +00:00
|
|
|
@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"
|
2022-11-13 14:02:34 +00:00
|
|
|
|
|
|
|
@pytest.mark.vcr()
|
|
|
|
def test_follow_with_notify_reblog(api, api2, api3):
|
|
|
|
api2_id = api2.account_verify_credentials()
|
2023-06-19 21:35:03 +00:00
|
|
|
status1 = None
|
|
|
|
status2 = None
|
2022-11-13 14:02:34 +00:00
|
|
|
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)
|
2022-11-18 23:29:14 +00:00
|
|
|
|
|
|
|
@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)
|
2022-11-27 21:38:42 +00:00
|
|
|
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
|
2022-11-27 21:55:26 +00:00
|
|
|
|
|
|
|
@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
|