Migrate from chat to peer

This commit is contained in:
Lonami Exo
2024-03-18 18:55:23 +01:00
parent 1dba3ae6d0
commit 38241dffd2
39 changed files with 841 additions and 802 deletions

View File

@@ -1,10 +0,0 @@
from telethon._impl.session import PackedType, PeerRef
def test_hash_optional() -> None:
for ty in PackedType:
pc = PeerRef(ty, 123, 456789)
assert PeerRef.from_bytes(bytes(pc)) == pc
pc = PeerRef(ty, 987, None)
assert PeerRef.from_bytes(bytes(pc)) == pc

View File

@@ -0,0 +1,40 @@
import inspect
from pytest import raises
from telethon._impl.session import ChannelRef, GroupRef, PeerRef, UserRef
USER = UserRef(12, 34)
GROUP = GroupRef(5, None)
CHANNEL = ChannelRef(67, 89)
def test_peer_ref() -> None:
assert PeerRef.from_str(str(USER)) == USER
assert PeerRef.from_str(str(GROUP)) == GROUP
assert PeerRef.from_str(str(CHANNEL)) == CHANNEL
assert inspect.isabstract(PeerRef)
with raises(ValueError):
PeerRef.from_str("invalid")
def test_user_ref() -> None:
assert UserRef.from_str(str(USER)) == USER
with raises(TypeError):
UserRef.from_str(str(GROUP))
def test_group_ref() -> None:
assert GroupRef.from_str(str(GROUP)) == GROUP
with raises(TypeError):
GroupRef.from_str(str(CHANNEL))
def test_channel_ref() -> None:
assert ChannelRef.from_str(str(CHANNEL)) == CHANNEL
with raises(TypeError):
ChannelRef.from_str(str(USER))