File: test_user.py

package info (click to toggle)
python-telegram-bot 22.3-1
  • links: PTS
  • area: main
  • in suites: sid
  • size: 11,060 kB
  • sloc: python: 90,298; makefile: 176; sh: 4
file content (807 lines) | stat: -rw-r--r-- 38,168 bytes parent folder | download
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
#!/usr/bin/env python
#
# A library that provides a Python interface to the Telegram Bot API
# Copyright (C) 2015-2025
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser Public License for more details.
#
# You should have received a copy of the GNU Lesser Public License
# along with this program.  If not, see [http://www.gnu.org/licenses/].
import pytest

from telegram import Bot, InlineKeyboardButton, Update, User
from telegram.helpers import escape_markdown
from tests.auxil.bot_method_checks import (
    check_defaults_handling,
    check_shortcut_call,
    check_shortcut_signature,
)
from tests.auxil.slots import mro_slots


@pytest.fixture(scope="module")
def json_dict():
    return {
        "id": UserTestBase.id_,
        "is_bot": UserTestBase.is_bot,
        "first_name": UserTestBase.first_name,
        "last_name": UserTestBase.last_name,
        "username": UserTestBase.username,
        "language_code": UserTestBase.language_code,
        "can_join_groups": UserTestBase.can_join_groups,
        "can_read_all_group_messages": UserTestBase.can_read_all_group_messages,
        "supports_inline_queries": UserTestBase.supports_inline_queries,
        "is_premium": UserTestBase.is_premium,
        "added_to_attachment_menu": UserTestBase.added_to_attachment_menu,
        "can_connect_to_business": UserTestBase.can_connect_to_business,
        "has_main_web_app": UserTestBase.has_main_web_app,
    }


@pytest.fixture
def user(bot):
    user = User(
        id=UserTestBase.id_,
        first_name=UserTestBase.first_name,
        is_bot=UserTestBase.is_bot,
        last_name=UserTestBase.last_name,
        username=UserTestBase.username,
        language_code=UserTestBase.language_code,
        can_join_groups=UserTestBase.can_join_groups,
        can_read_all_group_messages=UserTestBase.can_read_all_group_messages,
        supports_inline_queries=UserTestBase.supports_inline_queries,
        is_premium=UserTestBase.is_premium,
        added_to_attachment_menu=UserTestBase.added_to_attachment_menu,
        can_connect_to_business=UserTestBase.can_connect_to_business,
        has_main_web_app=UserTestBase.has_main_web_app,
    )
    user.set_bot(bot)
    user._unfreeze()
    return user


class UserTestBase:
    id_ = 1
    is_bot = True
    first_name = "first\u2022name"
    last_name = "last\u2022name"
    username = "username"
    language_code = "en_us"
    can_join_groups = True
    can_read_all_group_messages = True
    supports_inline_queries = False
    is_premium = True
    added_to_attachment_menu = False
    can_connect_to_business = True
    has_main_web_app = False


class TestUserWithoutRequest(UserTestBase):
    def test_slot_behaviour(self, user):
        for attr in user.__slots__:
            assert getattr(user, attr, "err") != "err", f"got extra slot '{attr}'"
        assert len(mro_slots(user)) == len(set(mro_slots(user))), "duplicate slot"

    def test_de_json(self, json_dict, offline_bot):
        user = User.de_json(json_dict, offline_bot)
        assert user.api_kwargs == {}

        assert user.id == self.id_
        assert user.is_bot == self.is_bot
        assert user.first_name == self.first_name
        assert user.last_name == self.last_name
        assert user.username == self.username
        assert user.language_code == self.language_code
        assert user.can_join_groups == self.can_join_groups
        assert user.can_read_all_group_messages == self.can_read_all_group_messages
        assert user.supports_inline_queries == self.supports_inline_queries
        assert user.is_premium == self.is_premium
        assert user.added_to_attachment_menu == self.added_to_attachment_menu
        assert user.can_connect_to_business == self.can_connect_to_business
        assert user.has_main_web_app == self.has_main_web_app

    def test_to_dict(self, user):
        user_dict = user.to_dict()

        assert isinstance(user_dict, dict)
        assert user_dict["id"] == user.id
        assert user_dict["is_bot"] == user.is_bot
        assert user_dict["first_name"] == user.first_name
        assert user_dict["last_name"] == user.last_name
        assert user_dict["username"] == user.username
        assert user_dict["language_code"] == user.language_code
        assert user_dict["can_join_groups"] == user.can_join_groups
        assert user_dict["can_read_all_group_messages"] == user.can_read_all_group_messages
        assert user_dict["supports_inline_queries"] == user.supports_inline_queries
        assert user_dict["is_premium"] == user.is_premium
        assert user_dict["added_to_attachment_menu"] == user.added_to_attachment_menu
        assert user_dict["can_connect_to_business"] == user.can_connect_to_business
        assert user_dict["has_main_web_app"] == user.has_main_web_app

    def test_equality(self):
        a = User(self.id_, self.first_name, self.is_bot, self.last_name)
        b = User(self.id_, self.first_name, self.is_bot, self.last_name)
        c = User(self.id_, self.first_name, self.is_bot)
        d = User(0, self.first_name, self.is_bot, self.last_name)
        e = Update(self.id_)

        assert a == b
        assert hash(a) == hash(b)
        assert a is not b

        assert a == c
        assert hash(a) == hash(c)

        assert a != d
        assert hash(a) != hash(d)

        assert a != e
        assert hash(a) != hash(e)

    def test_name(self, user):
        assert user.name == "@username"
        user.username = None
        assert user.name == "first\u2022name last\u2022name"
        user.last_name = None
        assert user.name == "first\u2022name"
        user.username = self.username
        assert user.name == "@username"

    def test_full_name(self, user):
        assert user.full_name == "first\u2022name last\u2022name"
        user.last_name = None
        assert user.full_name == "first\u2022name"

    def test_link(self, user):
        assert user.link == f"https://t.me/{user.username}"
        user.username = None
        assert user.link is None

    async def test_instance_method_get_profile_photos(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return kwargs["user_id"] == user.id

        assert check_shortcut_signature(
            User.get_profile_photos, Bot.get_user_profile_photos, ["user_id"], []
        )
        assert await check_shortcut_call(
            user.get_profile_photos, user.get_bot(), "get_user_profile_photos"
        )
        assert await check_defaults_handling(user.get_profile_photos, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "get_user_profile_photos", make_assertion)
        assert await user.get_profile_photos()

    async def test_instance_method_pin_message(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return kwargs["chat_id"] == user.id

        assert check_shortcut_signature(User.pin_message, Bot.pin_chat_message, ["chat_id"], [])
        assert await check_shortcut_call(user.pin_message, user.get_bot(), "pin_chat_message")
        assert await check_defaults_handling(user.pin_message, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "pin_chat_message", make_assertion)
        assert await user.pin_message(1)

    async def test_instance_method_unpin_message(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return kwargs["chat_id"] == user.id

        assert check_shortcut_signature(
            User.unpin_message, Bot.unpin_chat_message, ["chat_id"], []
        )
        assert await check_shortcut_call(user.unpin_message, user.get_bot(), "unpin_chat_message")
        assert await check_defaults_handling(user.unpin_message, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "unpin_chat_message", make_assertion)
        assert await user.unpin_message()

    async def test_instance_method_unpin_all_messages(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return kwargs["chat_id"] == user.id

        assert check_shortcut_signature(
            User.unpin_all_messages, Bot.unpin_all_chat_messages, ["chat_id"], []
        )
        assert await check_shortcut_call(
            user.unpin_all_messages, user.get_bot(), "unpin_all_chat_messages"
        )
        assert await check_defaults_handling(user.unpin_all_messages, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "unpin_all_chat_messages", make_assertion)
        assert await user.unpin_all_messages()

    async def test_instance_method_send_message(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return kwargs["chat_id"] == user.id and kwargs["text"] == "test"

        assert check_shortcut_signature(User.send_message, Bot.send_message, ["chat_id"], [])
        assert await check_shortcut_call(user.send_message, user.get_bot(), "send_message")
        assert await check_defaults_handling(user.send_message, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "send_message", make_assertion)
        assert await user.send_message("test")

    async def test_instance_method_send_photo(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return kwargs["chat_id"] == user.id and kwargs["photo"] == "test_photo"

        assert check_shortcut_signature(User.send_photo, Bot.send_photo, ["chat_id"], [])
        assert await check_shortcut_call(user.send_photo, user.get_bot(), "send_photo")
        assert await check_defaults_handling(user.send_photo, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "send_photo", make_assertion)
        assert await user.send_photo("test_photo")

    async def test_instance_method_send_media_group(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return kwargs["chat_id"] == user.id and kwargs["media"] == "test_media_group"

        assert check_shortcut_signature(
            User.send_media_group, Bot.send_media_group, ["chat_id"], []
        )
        assert await check_shortcut_call(user.send_media_group, user.get_bot(), "send_media_group")
        assert await check_defaults_handling(user.send_media_group, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "send_media_group", make_assertion)
        assert await user.send_media_group("test_media_group")

    async def test_instance_method_send_audio(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return kwargs["chat_id"] == user.id and kwargs["audio"] == "test_audio"

        assert check_shortcut_signature(User.send_audio, Bot.send_audio, ["chat_id"], [])
        assert await check_shortcut_call(user.send_audio, user.get_bot(), "send_audio")
        assert await check_defaults_handling(user.send_audio, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "send_audio", make_assertion)
        assert await user.send_audio("test_audio")

    async def test_instance_method_send_chat_action(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return kwargs["chat_id"] == user.id and kwargs["action"] == "test_chat_action"

        assert check_shortcut_signature(
            User.send_chat_action, Bot.send_chat_action, ["chat_id"], []
        )
        assert await check_shortcut_call(user.send_chat_action, user.get_bot(), "send_chat_action")
        assert await check_defaults_handling(user.send_chat_action, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "send_chat_action", make_assertion)
        assert await user.send_chat_action("test_chat_action")

    async def test_instance_method_send_contact(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return kwargs["chat_id"] == user.id and kwargs["phone_number"] == "test_contact"

        assert check_shortcut_signature(User.send_contact, Bot.send_contact, ["chat_id"], [])
        assert await check_shortcut_call(user.send_contact, user.get_bot(), "send_contact")
        assert await check_defaults_handling(user.send_contact, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "send_contact", make_assertion)
        assert await user.send_contact(phone_number="test_contact")

    async def test_instance_method_send_dice(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return kwargs["chat_id"] == user.id and kwargs["emoji"] == "test_dice"

        assert check_shortcut_signature(User.send_dice, Bot.send_dice, ["chat_id"], [])
        assert await check_shortcut_call(user.send_dice, user.get_bot(), "send_dice")
        assert await check_defaults_handling(user.send_dice, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "send_dice", make_assertion)
        assert await user.send_dice(emoji="test_dice")

    async def test_instance_method_send_document(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return kwargs["chat_id"] == user.id and kwargs["document"] == "test_document"

        assert check_shortcut_signature(User.send_document, Bot.send_document, ["chat_id"], [])
        assert await check_shortcut_call(user.send_document, user.get_bot(), "send_document")
        assert await check_defaults_handling(user.send_document, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "send_document", make_assertion)
        assert await user.send_document("test_document")

    async def test_instance_method_send_game(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return kwargs["chat_id"] == user.id and kwargs["game_short_name"] == "test_game"

        assert check_shortcut_signature(User.send_game, Bot.send_game, ["chat_id"], [])
        assert await check_shortcut_call(user.send_game, user.get_bot(), "send_game")
        assert await check_defaults_handling(user.send_game, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "send_game", make_assertion)
        assert await user.send_game(game_short_name="test_game")

    async def test_instance_method_send_invoice(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            title = kwargs["title"] == "title"
            description = kwargs["description"] == "description"
            payload = kwargs["payload"] == "payload"
            provider_token = kwargs["provider_token"] == "provider_token"
            currency = kwargs["currency"] == "currency"
            prices = kwargs["prices"] == "prices"
            args = title and description and payload and provider_token and currency and prices
            return kwargs["chat_id"] == user.id and args

        assert check_shortcut_signature(User.send_invoice, Bot.send_invoice, ["chat_id"], [])
        assert await check_shortcut_call(user.send_invoice, user.get_bot(), "send_invoice")
        assert await check_defaults_handling(user.send_invoice, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "send_invoice", make_assertion)
        assert await user.send_invoice(
            "title",
            "description",
            "payload",
            "currency",
            "prices",
            "provider_token",
        )

    async def test_instance_method_send_location(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return kwargs["chat_id"] == user.id and kwargs["latitude"] == "test_location"

        assert check_shortcut_signature(User.send_location, Bot.send_location, ["chat_id"], [])
        assert await check_shortcut_call(user.send_location, user.get_bot(), "send_location")
        assert await check_defaults_handling(user.send_location, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "send_location", make_assertion)
        assert await user.send_location("test_location")

    async def test_instance_method_send_sticker(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return kwargs["chat_id"] == user.id and kwargs["sticker"] == "test_sticker"

        assert check_shortcut_signature(User.send_sticker, Bot.send_sticker, ["chat_id"], [])
        assert await check_shortcut_call(user.send_sticker, user.get_bot(), "send_sticker")
        assert await check_defaults_handling(user.send_sticker, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "send_sticker", make_assertion)
        assert await user.send_sticker("test_sticker")

    async def test_instance_method_send_video(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return kwargs["chat_id"] == user.id and kwargs["video"] == "test_video"

        assert check_shortcut_signature(User.send_video, Bot.send_video, ["chat_id"], [])
        assert await check_shortcut_call(user.send_video, user.get_bot(), "send_video")
        assert await check_defaults_handling(user.send_video, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "send_video", make_assertion)
        assert await user.send_video("test_video")

    async def test_instance_method_send_venue(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return kwargs["chat_id"] == user.id and kwargs["title"] == "test_venue"

        assert check_shortcut_signature(User.send_venue, Bot.send_venue, ["chat_id"], [])
        assert await check_shortcut_call(user.send_venue, user.get_bot(), "send_venue")
        assert await check_defaults_handling(user.send_venue, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "send_venue", make_assertion)
        assert await user.send_venue(title="test_venue")

    async def test_instance_method_send_video_note(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return kwargs["chat_id"] == user.id and kwargs["video_note"] == "test_video_note"

        assert check_shortcut_signature(User.send_video_note, Bot.send_video_note, ["chat_id"], [])
        assert await check_shortcut_call(user.send_video_note, user.get_bot(), "send_video_note")
        assert await check_defaults_handling(user.send_video_note, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "send_video_note", make_assertion)
        assert await user.send_video_note("test_video_note")

    async def test_instance_method_send_voice(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return kwargs["chat_id"] == user.id and kwargs["voice"] == "test_voice"

        assert check_shortcut_signature(User.send_voice, Bot.send_voice, ["chat_id"], [])
        assert await check_shortcut_call(user.send_voice, user.get_bot(), "send_voice")
        assert await check_defaults_handling(user.send_voice, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "send_voice", make_assertion)
        assert await user.send_voice("test_voice")

    async def test_instance_method_send_animation(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return kwargs["chat_id"] == user.id and kwargs["animation"] == "test_animation"

        assert check_shortcut_signature(User.send_animation, Bot.send_animation, ["chat_id"], [])
        assert await check_shortcut_call(user.send_animation, user.get_bot(), "send_animation")
        assert await check_defaults_handling(user.send_animation, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "send_animation", make_assertion)
        assert await user.send_animation("test_animation")

    async def test_instance_method_send_poll(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return kwargs["chat_id"] == user.id and kwargs["question"] == "test_poll"

        assert check_shortcut_signature(User.send_poll, Bot.send_poll, ["chat_id"], [])
        assert await check_shortcut_call(user.send_poll, user.get_bot(), "send_poll")
        assert await check_defaults_handling(user.send_poll, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "send_poll", make_assertion)
        assert await user.send_poll(question="test_poll", options=[1, 2])

    async def test_instance_method_send_copy(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            user_id = kwargs["chat_id"] == user.id
            message_id = kwargs["message_id"] == "message_id"
            from_chat_id = kwargs["from_chat_id"] == "from_chat_id"
            return from_chat_id and message_id and user_id

        assert check_shortcut_signature(User.send_copy, Bot.copy_message, ["chat_id"], [])
        assert await check_shortcut_call(user.send_copy, user.get_bot(), "copy_message")
        assert await check_defaults_handling(user.send_copy, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "copy_message", make_assertion)
        assert await user.send_copy(from_chat_id="from_chat_id", message_id="message_id")

    async def test_instance_method_copy_message(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            chat_id = kwargs["chat_id"] == "chat_id"
            message_id = kwargs["message_id"] == "message_id"
            user_id = kwargs["from_chat_id"] == user.id
            return chat_id and message_id and user_id

        assert check_shortcut_signature(User.copy_message, Bot.copy_message, ["from_chat_id"], [])
        assert await check_shortcut_call(user.copy_message, user.get_bot(), "copy_message")
        assert await check_defaults_handling(user.copy_message, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "copy_message", make_assertion)
        assert await user.copy_message(chat_id="chat_id", message_id="message_id")

    async def test_instance_method_get_user_chat_boosts(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            chat_id = kwargs["chat_id"] == "chat_id"
            user_id = kwargs["user_id"] == user.id
            return chat_id and user_id

        assert check_shortcut_signature(
            User.get_chat_boosts, Bot.get_user_chat_boosts, ["user_id"], []
        )
        assert await check_shortcut_call(
            user.get_chat_boosts, user.get_bot(), "get_user_chat_boosts"
        )
        assert await check_defaults_handling(user.get_chat_boosts, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "get_user_chat_boosts", make_assertion)
        assert await user.get_chat_boosts(chat_id="chat_id")

    async def test_instance_method_get_menu_button(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return kwargs["chat_id"] == user.id

        assert check_shortcut_signature(
            User.get_menu_button, Bot.get_chat_menu_button, ["chat_id"], []
        )
        assert await check_shortcut_call(
            user.get_menu_button,
            user.get_bot(),
            "get_chat_menu_button",
            shortcut_kwargs=["chat_id"],
        )
        assert await check_defaults_handling(user.get_menu_button, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "get_chat_menu_button", make_assertion)
        assert await user.get_menu_button()

    async def test_instance_method_set_menu_button(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return kwargs["chat_id"] == user.id and kwargs["menu_button"] == "menu_button"

        assert check_shortcut_signature(
            User.set_menu_button, Bot.set_chat_menu_button, ["chat_id"], []
        )
        assert await check_shortcut_call(
            user.set_menu_button,
            user.get_bot(),
            "set_chat_menu_button",
            shortcut_kwargs=["chat_id"],
        )
        assert await check_defaults_handling(user.set_menu_button, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "set_chat_menu_button", make_assertion)
        assert await user.set_menu_button(menu_button="menu_button")

    async def test_instance_method_approve_join_request(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            chat_id = kwargs["chat_id"] == "chat_id"
            user_id = kwargs["user_id"] == user.id
            return chat_id and user_id

        assert check_shortcut_signature(
            User.approve_join_request, Bot.approve_chat_join_request, ["user_id"], []
        )
        assert await check_shortcut_call(
            user.approve_join_request, user.get_bot(), "approve_chat_join_request"
        )
        assert await check_defaults_handling(user.approve_join_request, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "approve_chat_join_request", make_assertion)
        assert await user.approve_join_request(chat_id="chat_id")

    async def test_instance_method_decline_join_request(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            chat_id = kwargs["chat_id"] == "chat_id"
            user_id = kwargs["user_id"] == user.id
            return chat_id and user_id

        assert check_shortcut_signature(
            User.decline_join_request, Bot.decline_chat_join_request, ["user_id"], []
        )
        assert await check_shortcut_call(
            user.decline_join_request, user.get_bot(), "decline_chat_join_request"
        )
        assert await check_defaults_handling(user.decline_join_request, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "decline_chat_join_request", make_assertion)
        assert await user.decline_join_request(chat_id="chat_id")

    async def test_mention_html(self, user):
        expected = '<a href="tg://user?id={}">{}</a>'

        assert user.mention_html() == expected.format(user.id, user.full_name)
        assert user.mention_html("the<b>name\u2022") == expected.format(
            user.id, "the&lt;b&gt;name\u2022"
        )
        assert user.mention_html(user.username) == expected.format(user.id, user.username)

    def test_mention_button(self, user):
        expected_name = InlineKeyboardButton(text="Bob", url=f"tg://user?id={user.id}")
        expected_full = InlineKeyboardButton(text=user.full_name, url=f"tg://user?id={user.id}")

        assert user.mention_button("Bob") == expected_name
        assert user.mention_button() == expected_full

    def test_mention_markdown(self, user):
        expected = "[{}](tg://user?id={})"

        assert user.mention_markdown() == expected.format(user.full_name, user.id)
        assert user.mention_markdown("the_name*\u2022") == expected.format(
            "the_name*\u2022", user.id
        )
        assert user.mention_markdown(user.username) == expected.format(user.username, user.id)

    async def test_mention_markdown_v2(self, user):
        user.first_name = "first{name"
        user.last_name = "last_name"

        expected = "[{}](tg://user?id={})"

        assert user.mention_markdown_v2() == expected.format(
            escape_markdown(user.full_name, version=2), user.id
        )
        assert user.mention_markdown_v2("the{name>\u2022") == expected.format(
            "the\\{name\\>\u2022", user.id
        )
        assert user.mention_markdown_v2(user.username) == expected.format(user.username, user.id)

    async def test_delete_message(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return kwargs["chat_id"] == user.id and kwargs["message_id"] == 42

        assert check_shortcut_signature(user.delete_message, Bot.delete_message, ["chat_id"], [])
        assert await check_shortcut_call(user.delete_message, user.get_bot(), "delete_message")
        assert await check_defaults_handling(user.delete_message, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "delete_message", make_assertion)
        assert await user.delete_message(message_id=42)

    async def test_delete_messages(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return kwargs["chat_id"] == user.id and kwargs["message_ids"] == (42, 43)

        assert check_shortcut_signature(user.delete_messages, Bot.delete_messages, ["chat_id"], [])
        assert await check_shortcut_call(user.delete_messages, user.get_bot(), "delete_messages")
        assert await check_defaults_handling(user.delete_messages, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "delete_messages", make_assertion)
        assert await user.delete_messages(message_ids=(42, 43))

    async def test_instance_method_send_copies(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            from_chat_id = kwargs["from_chat_id"] == "test_copies"
            message_ids = kwargs["message_ids"] == (42, 43)
            user_id = kwargs["chat_id"] == user.id
            return from_chat_id and message_ids and user_id

        assert check_shortcut_signature(user.send_copies, Bot.copy_messages, ["chat_id"], [])
        assert await check_shortcut_call(user.send_copies, user.get_bot(), "copy_messages")
        assert await check_defaults_handling(user.send_copies, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "copy_messages", make_assertion)
        assert await user.send_copies(from_chat_id="test_copies", message_ids=(42, 43))

    async def test_instance_method_copy_messages(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            from_chat_id = kwargs["from_chat_id"] == user.id
            message_ids = kwargs["message_ids"] == (42, 43)
            user_id = kwargs["chat_id"] == "test_copies"
            return from_chat_id and message_ids and user_id

        assert check_shortcut_signature(
            user.copy_messages, Bot.copy_messages, ["from_chat_id"], []
        )
        assert await check_shortcut_call(user.copy_messages, user.get_bot(), "copy_messages")
        assert await check_defaults_handling(user.copy_messages, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "copy_messages", make_assertion)
        assert await user.copy_messages(chat_id="test_copies", message_ids=(42, 43))

    async def test_instance_method_forward_from(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            user_id = kwargs["chat_id"] == user.id
            message_id = kwargs["message_id"] == 42
            from_chat_id = kwargs["from_chat_id"] == "test_forward"
            return from_chat_id and message_id and user_id

        assert check_shortcut_signature(user.forward_from, Bot.forward_message, ["chat_id"], [])
        assert await check_shortcut_call(user.forward_from, user.get_bot(), "forward_message")
        assert await check_defaults_handling(user.forward_from, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "forward_message", make_assertion)
        assert await user.forward_from(from_chat_id="test_forward", message_id=42)

    async def test_instance_method_forward_to(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            from_chat_id = kwargs["from_chat_id"] == user.id
            message_id = kwargs["message_id"] == 42
            user_id = kwargs["chat_id"] == "test_forward"
            return from_chat_id and message_id and user_id

        assert check_shortcut_signature(user.forward_to, Bot.forward_message, ["from_chat_id"], [])
        assert await check_shortcut_call(user.forward_to, user.get_bot(), "forward_message")
        assert await check_defaults_handling(user.forward_to, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "forward_message", make_assertion)
        assert await user.forward_to(chat_id="test_forward", message_id=42)

    async def test_instance_method_forward_messages_from(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            user_id = kwargs["chat_id"] == user.id
            message_ids = kwargs["message_ids"] == (42, 43)
            from_chat_id = kwargs["from_chat_id"] == "test_forwards"
            return from_chat_id and message_ids and user_id

        assert check_shortcut_signature(
            user.forward_messages_from, Bot.forward_messages, ["chat_id"], []
        )
        assert await check_shortcut_call(
            user.forward_messages_from, user.get_bot(), "forward_messages"
        )
        assert await check_defaults_handling(user.forward_messages_from, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "forward_messages", make_assertion)
        assert await user.forward_messages_from(from_chat_id="test_forwards", message_ids=(42, 43))

    async def test_instance_method_forward_messages_to(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            from_chat_id = kwargs["from_chat_id"] == user.id
            message_ids = kwargs["message_ids"] == (42, 43)
            user_id = kwargs["chat_id"] == "test_forwards"
            return from_chat_id and message_ids and user_id

        assert check_shortcut_signature(
            user.forward_messages_to, Bot.forward_messages, ["from_chat_id"], []
        )
        assert await check_shortcut_call(
            user.forward_messages_to, user.get_bot(), "forward_messages"
        )
        assert await check_defaults_handling(user.forward_messages_to, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "forward_messages", make_assertion)
        assert await user.forward_messages_to(chat_id="test_forwards", message_ids=(42, 43))

    async def test_instance_method_refund_star_payment(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return kwargs["user_id"] == user.id and kwargs["telegram_payment_charge_id"] == 42

        assert check_shortcut_signature(
            user.refund_star_payment, Bot.refund_star_payment, ["user_id"], []
        )
        assert await check_shortcut_call(
            user.refund_star_payment, user.get_bot(), "refund_star_payment"
        )
        assert await check_defaults_handling(user.refund_star_payment, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "refund_star_payment", make_assertion)
        assert await user.refund_star_payment(telegram_payment_charge_id=42)

    async def test_instance_method_send_gift(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return (
                kwargs["user_id"] == user.id
                and kwargs["gift_id"] == "gift_id"
                and kwargs["text"] == "text"
                and kwargs["text_parse_mode"] == "text_parse_mode"
                and kwargs["text_entities"] == "text_entities"
            )

        assert check_shortcut_signature(user.send_gift, Bot.send_gift, ["user_id", "chat_id"], [])
        assert await check_shortcut_call(
            user.send_gift, user.get_bot(), "send_gift", ["chat_id", "user_id"]
        )
        assert await check_defaults_handling(user.send_gift, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "send_gift", make_assertion)
        assert await user.send_gift(
            gift_id="gift_id",
            text="text",
            text_parse_mode="text_parse_mode",
            text_entities="text_entities",
        )

    async def test_instance_method_gift_premium_subscription(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return (
                kwargs["user_id"] == user.id
                and kwargs["month_count"] == 3
                and kwargs["star_count"] == 1000
                and kwargs["text"] == "text"
                and kwargs["text_parse_mode"] == "text_parse_mode"
                and kwargs["text_entities"] == "text_entities"
            )

        assert check_shortcut_signature(
            user.gift_premium_subscription, Bot.gift_premium_subscription, ["user_id"], []
        )
        assert await check_shortcut_call(
            user.gift_premium_subscription,
            user.get_bot(),
            "gift_premium_subscription",
        )
        assert await check_defaults_handling(user.gift_premium_subscription, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "gift_premium_subscription", make_assertion)
        assert await user.gift_premium_subscription(
            month_count=3,
            star_count=1000,
            text="text",
            text_parse_mode="text_parse_mode",
            text_entities="text_entities",
        )

    async def test_instance_method_verify_user(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return (
                kwargs["user_id"] == user.id
                and kwargs["custom_description"] == "This is a custom description"
            )

        assert check_shortcut_signature(user.verify, Bot.verify_user, ["user_id"], [])
        assert await check_shortcut_call(user.verify, user.get_bot(), "verify_user")
        assert await check_defaults_handling(user.verify, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "verify_user", make_assertion)
        assert await user.verify(
            custom_description="This is a custom description",
        )

    async def test_instance_method_remove_user_verification(self, monkeypatch, user):
        async def make_assertion(*_, **kwargs):
            return kwargs["user_id"] == user.id

        assert check_shortcut_signature(
            user.remove_verification, Bot.remove_user_verification, ["user_id"], []
        )
        assert await check_shortcut_call(
            user.remove_verification, user.get_bot(), "remove_user_verification"
        )
        assert await check_defaults_handling(user.remove_verification, user.get_bot())

        monkeypatch.setattr(user.get_bot(), "remove_user_verification", make_assertion)
        assert await user.remove_verification()