File: test_chataction.py

package info (click to toggle)
python-telethon 1.42.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,520 kB
  • sloc: python: 16,285; javascript: 200; makefile: 16; sh: 11
file content (67 lines) | stat: -rw-r--r-- 1,597 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import pytest

from telethon import TelegramClient, events, types, utils


def get_client():
    return TelegramClient(None, 1, '1')


def get_user_456():
    return types.User(
        id=456,
        access_hash=789,
        first_name='User 123'
    )


@pytest.mark.asyncio
async def test_get_input_users_no_action_message_no_entities():
    event = events.ChatAction.build(types.UpdateChatParticipantDelete(
        chat_id=123,
        user_id=456,
        version=1
    ))
    event._set_client(get_client())

    assert await event.get_input_users() == []


@pytest.mark.asyncio
async def test_get_input_users_no_action_message():
    user = get_user_456()
    event = events.ChatAction.build(types.UpdateChatParticipantDelete(
        chat_id=123,
        user_id=456,
        version=1
    ))
    event._set_client(get_client())
    event._entities[user.id] = user

    assert await event.get_input_users() == [utils.get_input_peer(user)]


@pytest.mark.asyncio
async def test_get_users_no_action_message_no_entities():
    event = events.ChatAction.build(types.UpdateChatParticipantDelete(
        chat_id=123,
        user_id=456,
        version=1
    ))
    event._set_client(get_client())

    assert await event.get_users() == []


@pytest.mark.asyncio
async def test_get_users_no_action_message():
    user = get_user_456()
    event = events.ChatAction.build(types.UpdateChatParticipantDelete(
        chat_id=123,
        user_id=456,
        version=1
    ))
    event._set_client(get_client())
    event._entities[user.id] = user

    assert await event.get_users() == [user]