2017-11-27 03:22:03 +00:00
|
|
|
import pytest
|
2017-11-27 01:25:33 +00:00
|
|
|
from datetime import datetime
|
2025-02-13 23:34:02 +00:00
|
|
|
from mastodon.return_types import IdType
|
2023-06-20 21:15:40 +00:00
|
|
|
import typing
|
2023-06-23 20:16:44 +00:00
|
|
|
import copy
|
2017-11-27 01:25:33 +00:00
|
|
|
|
2023-06-20 21:15:40 +00:00
|
|
|
def get_type_class(typ):
|
|
|
|
try:
|
|
|
|
return typ.__extra__
|
|
|
|
except AttributeError:
|
|
|
|
try:
|
|
|
|
return typ.__origin__
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
|
|
|
return typ
|
|
|
|
|
|
|
|
|
|
|
|
def real_issubclass(obj1, type2orig):
|
|
|
|
type1 = get_type_class(type(obj1))
|
|
|
|
type2 = get_type_class(type2orig)
|
|
|
|
valid_types = []
|
|
|
|
if type2 is typing.Union:
|
|
|
|
valid_types = type2orig.__args__
|
|
|
|
elif type2 is typing.Generic:
|
|
|
|
valid_types = [type2orig.__args__[0]]
|
|
|
|
else:
|
|
|
|
valid_types = [type2orig]
|
|
|
|
return issubclass(type1, tuple(valid_types))
|
2017-11-27 19:42:54 +00:00
|
|
|
|
2017-11-27 01:25:33 +00:00
|
|
|
@pytest.mark.vcr()
|
|
|
|
def test_id_hook(status):
|
2023-06-20 21:15:40 +00:00
|
|
|
assert real_issubclass(status['id'], IdType)
|
2017-11-27 01:25:33 +00:00
|
|
|
|
2017-11-27 19:42:54 +00:00
|
|
|
|
2017-11-27 01:25:33 +00:00
|
|
|
@pytest.mark.vcr()
|
2017-11-27 13:35:02 +00:00
|
|
|
def test_id_hook_in_reply_to(api, status):
|
|
|
|
reply = api.status_post('Reply!', in_reply_to_id=status['id'])
|
2017-11-27 01:25:33 +00:00
|
|
|
try:
|
2023-06-20 21:15:40 +00:00
|
|
|
assert real_issubclass(reply['in_reply_to_id'], IdType)
|
|
|
|
assert real_issubclass(reply['in_reply_to_account_id'], IdType)
|
2017-11-27 01:25:33 +00:00
|
|
|
finally:
|
2017-11-27 13:35:02 +00:00
|
|
|
api.status_delete(reply['id'])
|
2017-11-27 01:25:33 +00:00
|
|
|
|
2017-11-27 19:42:54 +00:00
|
|
|
|
2017-11-27 01:25:33 +00:00
|
|
|
@pytest.mark.vcr()
|
2017-11-27 13:35:02 +00:00
|
|
|
def test_id_hook_within_reblog(api, status):
|
|
|
|
reblog = api.status_reblog(status['id'])
|
2017-11-27 01:25:33 +00:00
|
|
|
try:
|
2023-06-20 21:15:40 +00:00
|
|
|
assert real_issubclass(reblog['reblog']['id'], IdType)
|
2017-11-27 01:25:33 +00:00
|
|
|
finally:
|
2017-11-27 13:35:02 +00:00
|
|
|
api.status_delete(reblog['id'])
|
2017-11-27 01:25:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.vcr()
|
|
|
|
def test_date_hook(status):
|
2023-06-20 21:15:40 +00:00
|
|
|
assert real_issubclass(status['created_at'], datetime)
|
2018-05-06 00:50:54 +00:00
|
|
|
|
|
|
|
@pytest.mark.vcr()
|
|
|
|
def test_attribute_access(status):
|
2022-11-20 19:14:25 +00:00
|
|
|
assert status.id is not None
|
2023-06-23 20:16:44 +00:00
|
|
|
status2 = copy.deepcopy(status)
|
2025-02-14 18:08:00 +00:00
|
|
|
status2.id = 420
|
|
|
|
|