From 47d30bf25d18628fb98c9d37ca51b130392158ec Mon Sep 17 00:00:00 2001 From: Badiboy Date: Sun, 16 Aug 2026 00:42:38 +0300 Subject: [PATCH] Revert wrong tests update --- tests/test_types.bak01 | 2737 ------------------------------ tests/test_types.bak02 | 2689 ----------------------------- tests/test_types.bak03 | 2679 ----------------------------- tests/test_types.py | 2958 ++++---------------------------- tests/test_types.to_dict | 3465 -------------------------------------- 5 files changed, 334 insertions(+), 14194 deletions(-) delete mode 100644 tests/test_types.bak01 delete mode 100644 tests/test_types.bak02 delete mode 100644 tests/test_types.bak03 delete mode 100644 tests/test_types.to_dict diff --git a/tests/test_types.bak01 b/tests/test_types.bak01 deleted file mode 100644 index 3f3a56f6e..000000000 --- a/tests/test_types.bak01 +++ /dev/null @@ -1,2737 +0,0 @@ -# -*- coding: utf-8 -*- -import sys - -sys.path.append('../') -from telebot import types -import json - - -def test_json_user(): - json_dict = json.loads(r'{"id": 123456789, "is_bot": false, "first_name": "John", "last_name": "Doe", "username": "@johndoe", "language_code": "en", "can_join_groups": true, "can_read_all_group_messages": false, "supports_inline_queries": true, "is_premium": true, "added_to_attachment_menu": false, "can_connect_to_business": true, "has_main_web_app": false, "has_topics_enabled": true, "allows_users_to_create_topics": true, "can_manage_bots": true, "supports_guest_queries": true, "supports_join_request_queries": true}') - result = types.User.de_json(json_dict) - assert result.id == 123456789 - assert result.is_bot == False - assert result.first_name == 'John' - assert result.last_name == 'Doe' - assert result.username == '@johndoe' - assert result.language_code == 'en' - assert result.can_join_groups == True - assert result.can_read_all_group_messages == False - assert result.supports_inline_queries == True - assert result.is_premium == True - assert result.added_to_attachment_menu == False - assert result.can_connect_to_business == True - assert result.has_main_web_app == False - assert result.has_topics_enabled == True - assert result.allows_users_to_create_topics == True - assert result.can_manage_bots == True - assert result.supports_guest_queries == True - assert result.supports_join_request_queries == True - assert isinstance(result, types.User) - - -def test_json_chat(): - json_dict = json.loads(r'{"id": 12345, "type": "private", "title": "Test Chat", "username": "@testchat", "first_name": "John", "last_name": "Doe", "photo": {"small_file_id": "s", "small_file_unique_id": "su", "big_file_id": "b", "big_file_unique_id": "bu"}, "bio": "bio text", "has_private_forwards": true, "description": "chat description", "invite_link": "https://t.me/joinchat/ABC", "pinned_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "pinned"}, "permissions": {"can_send_messages": true, "can_send_audios": true, "can_send_documents": true, "can_send_photos": true, "can_send_videos": true, "can_send_video_notes": true, "can_send_voice_notes": true, "can_send_polls": true, "can_send_other_messages": true, "can_add_web_page_previews": true, "can_change_info": true, "can_invite_users": true, "can_pin_messages": true, "can_manage_topics": true}, "slow_mode_delay": 30, "message_auto_delete_time": 86400, "has_protected_content": true, "sticker_set_name": "TestStickerSet", "can_set_sticker_set": false, "linked_chat_id": 2, "location": {"chat": {"id": 1, "type": "supergroup", "title": "Loc"}, "location": {"latitude": 50.45, "longitude": 30.52}, "address": "Main St"}, "join_to_send_messages": false, "join_by_request": true, "has_restricted_voice_and_video_messages": false, "is_forum": true, "max_reaction_count": 10, "active_usernames": ["test"], "emoji_status_custom_emoji_id": "custom_emoji", "has_hidden_members": false, "has_aggressive_anti_spam_enabled": false, "emoji_status_expiration_date": 1682275907, "available_reactions": ["emoji", "custom_emoji"], "accent_color_id": 1, "background_custom_emoji_id": "bg_emoji", "profile_accent_color_id": 2, "profile_background_custom_emoji_id": "profile_bg", "has_visible_history": true, "unrestrict_boost_count": 5, "custom_emoji_sticker_set_name": "custom_stickers", "business_intro": {"title": "Business", "description": "Business desc", "has_visible_history": true}, "business_location": {"address": "New York, NY", "has_active_address": true}, "business_opening_hours": {"time_zone_name": "America/New_York", "opening_hours": [{"opening_minute": 540, "closing_minute": 1020, "day_of_week": 1, "is_recurring": true}]}, "personal_chat": {"id": 3, "type": "private", "title": "Personal"}, "birthdate": {"day": "15", "month": "6"}, "can_send_paid_media": true, "accepted_gift_types": {"unlimited_gifts": false, "limited_gifts": false, "unique_gifts": true, "premium_subscription": false, "gifts_from_channels": false}, "is_direct_messages": true, "parent_chat": {"id": 4, "type": "supergroup", "title": "Parent"}, "rating": {"level": "test", "rating": "test", "current_level_rating": "test"}, "paid_message_star_count": 5, "first_profile_audio": {"file_id": "fa1", "file_unique_id": "fa1u", "duration": 30, "mime_type": "audio/ogg"}, "unique_gift_colors": {"model_custom_emoji_id": 1, "symbol_custom_emoji_id": 1, "light_theme_main_color": 333333, "light_theme_other_colors": [444444], "dark_theme_main_color": 555555, "dark_theme_other_colors": [666666]}, "guard_bot": {"id": 2, "is_bot": true, "first_name": "GuardBot"}, "community": {"id": 5, "name": "Community"}}') - result = types.Chat.de_json(json_dict) - assert result.id == 12345 - assert result.type == 'private' - assert result.title == 'Test Chat' - assert result.username == "@testchat" - assert result.first_name == "John" - assert result.last_name == "Doe" - assert isinstance(result.photo, types.ChatPhoto) - assert result.bio == "bio text" - assert result.has_private_forwards == True - assert result.description == "chat description" - assert result.invite_link == "https://t.me/joinchat/ABC" - assert isinstance(result.pinned_message, types.Message) - assert isinstance(result.permissions, types.ChatPermissions) - assert result.slow_mode_delay == 30 - assert result.message_auto_delete_time == 86400 - assert result.has_protected_content == True - assert result.sticker_set_name == "TestStickerSet" - assert result.can_set_sticker_set == False - assert result.linked_chat_id == 2 - assert isinstance(result.location, types.ChatLocation) - assert result.join_to_send_messages == False - assert result.join_by_request == True - assert result.has_restricted_voice_and_video_messages == False - assert result.is_forum == True - assert result.max_reaction_count == 10 - assert isinstance(result.active_usernames, list) - assert result.emoji_status_custom_emoji_id == "custom_emoji" - assert result.has_hidden_members == False - assert result.has_aggressive_anti_spam_enabled == False - assert result.emoji_status_expiration_date == 1682275907 - assert isinstance(result.available_reactions, list) - assert result.accent_color_id == 1 - assert result.background_custom_emoji_id == "bg_emoji" - assert result.profile_accent_color_id == 2 - assert result.profile_background_custom_emoji_id == "profile_bg" - assert result.has_visible_history == True - assert result.unrestrict_boost_count == 5 - assert result.custom_emoji_sticker_set_name == "custom_stickers" - assert isinstance(result.business_intro, types.BusinessIntro) - assert isinstance(result.business_location, types.BusinessLocation) - assert isinstance(result.business_opening_hours, types.BusinessOpeningHours) - assert isinstance(result.personal_chat, types.Chat) - assert isinstance(result.birthdate, types.Birthdate) - assert result.can_send_paid_media == True - assert isinstance(result.accepted_gift_types, types.AcceptedGiftTypes) - assert result.is_direct_messages == True - assert isinstance(result.parent_chat, types.Chat) - assert isinstance(result.rating, types.UserRating) - assert result.paid_message_star_count == 5 - assert isinstance(result.unique_gift_colors, types.UniqueGiftColors) - assert isinstance(result.first_profile_audio, types.Audio) - assert isinstance(result.guard_bot, types.User) - assert isinstance(result.community, types.Community) - assert isinstance(result, types.Chat) - - -# NOTE: Message has internal fields that are not covered by de_json tests: -# - options: internal field, not from JSON -# - json_string: internal field, not from JSON -def test_json_message(): - json_dict = json.loads(r'{"message_id": 1, "date": 1682189507, "chat": {"id": 12345, "type": "private", "title": "Chat"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "Hello", "content_type": "text"}') - result = types.Message.de_json(json_dict) - assert result.message_id == 1 - assert isinstance(result.from_user, types.User) - assert result.date == 1682189507 - assert isinstance(result.chat, types.Chat) - assert result.content_type == 'text' - assert isinstance(result, types.Message) - - -def test_json_location(): - json_dict = json.loads(r'{"latitude": 50.4501, "longitude": 30.5234, "horizontal_accuracy": 1.5, "live_period": 3600, "heading": 45, "proximity_alert_radius": 100}') - result = types.Location.de_json(json_dict) - assert result.longitude == 30.5234 - assert result.latitude == 50.4501 - assert result.horizontal_accuracy == 1.5 - assert result.live_period == 3600 - assert result.heading == 45 - assert result.proximity_alert_radius == 100 - assert isinstance(result, types.Location) - - -def test_json_venue(): - json_dict = json.loads(r'{"location": {"latitude": 50.45, "longitude": 30.52}, "title": "Kyiv", "address": "Khreshchatyk St", "foursquare_id": "12345", "foursquare_type": "restaurant", "google_place_id": "ChI123456", "google_place_type": "locality"}') - result = types.Venue.de_json(json_dict) - assert isinstance(result.location, types.Location) - assert result.title == 'Kyiv' - assert result.address == 'Khreshchatyk St' - assert result.foursquare_id == '12345' - assert result.foursquare_type == 'restaurant' - assert result.google_place_id == 'ChI123456' - assert result.google_place_type == 'locality' - assert isinstance(result, types.Venue) - - -def test_json_contact(): - json_dict = json.loads(r'{"phone_number": "+123****7890", "first_name": "John", "user_id": 12345, "last_name": "Doe", "vcard": "some vcard data"}') - result = types.Contact.de_json(json_dict) - assert result.phone_number == '+123****7890' - assert result.first_name == 'John' - assert result.last_name == 'Doe' - assert result.user_id == 12345 - assert result.vcard == 'some vcard data' - assert isinstance(result, types.Contact) - - -def test_json_document(): - json_dict = json.loads(r'{"file_id": "doc1", "file_unique_id": "du1", "file_name": "test.pdf", "mime_type": "application/pdf", "file_size": 1024, "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 50, "height": 50}}') - result = types.Document.de_json(json_dict) - assert result.file_id == 'doc1' - assert result.file_unique_id == 'du1' - assert isinstance(result.thumbnail, types.PhotoSize) - assert result.file_name == 'test.pdf' - assert result.mime_type == 'application/pdf' - assert result.file_size == 1024 - assert isinstance(result, types.Document) - - -def test_json_photo_size(): - json_dict = json.loads(r'{"file_id": "photo1", "file_unique_id": "pu1", "width": 100, "height": 100, "file_size": 512}') - result = types.PhotoSize.de_json(json_dict) - assert result.file_id == 'photo1' - assert result.file_unique_id == 'pu1' - assert result.width == 100 - assert result.height == 100 - assert result.file_size == 512 - assert isinstance(result, types.PhotoSize) - - -def test_json_video(): - json_dict = json.loads(r'{"file_id": "video1", "file_unique_id": "vu1", "width": 640, "height": 480, "duration": 30, "mime_type": "video/mp4", "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 50, "height": 50}, "file_name": "video.mp4", "file_size": 2048, "start_timestamp": 5, "qualities": [{"file_id": "q1", "file_unique_id": "qu1", "width": 240, "height": 360, "codec": "h264", "file_size": 1024}, {"file_id": "q2", "file_unique_id": "qu2", "width": 640, "height": 480, "codec": "h264", "file_size": 2048}]}') - result = types.Video.de_json(json_dict) - assert result.file_id == 'video1' - assert result.file_unique_id == 'vu1' - assert result.width == 640 - assert result.height == 480 - assert result.duration == 30 - assert isinstance(result.thumbnail, types.PhotoSize) - assert result.file_name == 'video.mp4' - assert result.mime_type == 'video/mp4' - assert result.file_size == 2048 - assert result.cover is None - assert result.start_timestamp == 5 - assert isinstance(result.qualities, list) - assert isinstance(result, types.Video) - - -def test_json_audio(): - json_dict = json.loads(r'{"file_id": "audio1", "file_unique_id": "au1", "duration": 30, "mime_type": "audio/mpeg", "performer": "Artist", "title": "Song Title", "file_name": "song.mp3", "file_size": 512, "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 50, "height": 50}}') - result = types.Audio.de_json(json_dict) - assert result.file_id == 'audio1' - assert result.file_unique_id == 'au1' - assert result.duration == 30 - assert result.performer == 'Artist' - assert result.title == 'Song Title' - assert result.file_name == 'song.mp3' - assert result.mime_type == 'audio/mpeg' - assert result.file_size == 512 - assert isinstance(result.thumbnail, types.PhotoSize) - assert isinstance(result, types.Audio) - - -def test_json_voice(): - json_dict = json.loads(r'{"file_id": "voice1", "file_unique_id": "vu1", "duration": 30, "mime_type": "audio/ogg", "file_size": 256}') - result = types.Voice.de_json(json_dict) - assert result.file_id == 'voice1' - assert result.file_unique_id == 'vu1' - assert result.duration == 30 - assert result.mime_type == 'audio/ogg' - assert result.file_size == 256 - assert isinstance(result, types.Voice) - - -def test_json_animation(): - json_dict = json.loads(r'{"file_id": "anim1", "file_unique_id": "anu1", "width": 100, "height": 100, "duration": 10, "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 50, "height": 50}, "file_name": "anim.mp4", "mime_type": "video/mp4", "file_size": 1024}') - result = types.Animation.de_json(json_dict) - assert result.file_id == 'anim1' - assert result.file_unique_id == 'anu1' - assert result.width == 100 - assert result.height == 100 - assert result.duration == 10 - assert isinstance(result.thumbnail, types.PhotoSize) - assert result.file_name == 'anim.mp4' - assert result.mime_type == 'video/mp4' - assert result.file_size == 1024 - assert isinstance(result, types.Animation) - - -def test_json_sticker(): - json_dict = json.loads(r'{"file_id": "sticker1", "file_unique_id": "stu1", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false, "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 100, "height": 100}, "emoji": "😀", "set_name": "TestSet", "mask_position": {"point": "forehead", "x_shift": 0.0, "y_shift": 0.0, "scale": 0.5}, "file_size": 4096, "premium_animation": {"file_id": "pa1", "file_unique_id": "pa1u"}, "custom_emoji_id": "ce1", "needs_repainting": true}') - result = types.Sticker.de_json(json_dict) - assert result.file_id == 'sticker1' - assert result.file_unique_id == 'stu1' - assert result.type == 'regular' - assert result.width == 512 - assert result.height == 512 - assert result.is_animated == False - assert result.is_video == False - assert isinstance(result.thumbnail, types.PhotoSize) - assert result.emoji == '😀' - assert result.set_name == 'TestSet' - assert isinstance(result.mask_position, types.MaskPosition) - assert result.file_size == 4096 - assert isinstance(result.premium_animation, types.File) - assert result.custom_emoji_id == 'ce1' - assert result.needs_repainting == True - assert isinstance(result, types.Sticker) - - -def test_json_stickerset(): - json_dict = json.loads(r'{"name": "TestName", "title": "Test Title", "sticker_type": "regular", "stickers": [{"file_id": "st1", "file_unique_id": "su1", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}], "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 100, "height": 100}}') - result = types.StickerSet.de_json(json_dict) - assert result.name == 'TestName' - assert result.title == 'Test Title' - assert result.sticker_type == 'regular' - assert isinstance(result.stickers, list) - assert isinstance(result.thumbnail, types.PhotoSize) - assert isinstance(result, types.StickerSet) - - -def test_json_chatlocation(): - json_dict = json.loads(r'{"location": {"latitude": 50.45, "longitude": 30.52}, "address": "New York, NY"}') - result = types.ChatLocation.de_json(json_dict) - assert isinstance(result.location, types.Location) - assert result.address == 'New York, NY' - - -def test_json_reactiontypeemoji(): - json_dict = json.loads(r'{"type": "emoji", "emoji": "\u2764\uFE0F"}') - result = types.ReactionTypeEmoji.de_json(json_dict) - assert result.emoji == '❤️' - assert isinstance(result, types.ReactionTypeEmoji) - - -def test_json_reactiontypecustomemoji(): - json_dict = json.loads(r'{"type": "custom_emoji", "custom_emoji_id": "ce123"}') - result = types.ReactionTypeCustomEmoji.de_json(json_dict) - assert result.custom_emoji_id == 'ce123' - assert isinstance(result, types.ReactionTypeCustomEmoji) - - -def test_json_reactioncount(): - json_dict = json.loads(r'{"type": {"type": "emoji", "emoji": "\u2764\uFE0F"}, "total_count": 5}') - result = types.ReactionCount.de_json(json_dict) - assert isinstance(result.type, types.ReactionType) - assert result.total_count == 5 - assert isinstance(result, types.ReactionCount) - - -def test_json_chatinvitelink(): - json_dict = json.loads(r'{"invite_link": "https://t.me/joinchat/ABC", "creator": {"id": 12345, "is_bot": false, "first_name": "Test"}, "creates_join_request": false, "is_primary": true, "is_revoked": false, "name": "Invite", "expire_date": 1704067200, "member_limit": 10, "pending_join_request_count": 3}') - result = types.ChatInviteLink.de_json(json_dict) - assert result.invite_link == 'https://t.me/joinchat/ABC' - assert isinstance(result.creator, types.User) - assert result.creates_join_request == False - assert result.is_primary == True - assert result.is_revoked == False - assert result.name == 'Invite' - assert result.expire_date == 1704067200 - assert result.member_limit == 10 - assert result.pending_join_request_count == 3 - assert isinstance(result, types.ChatInviteLink) - - -def test_json_forumtopic(): - json_dict = json.loads(r'{"message_thread_id": 42, "name": "Topic", "icon_color": 4294967295, "icon_custom_emoji_id": "emoji1", "is_name_implicit": true}') - result = types.ForumTopic.de_json(json_dict) - assert result.message_thread_id == 42 - assert result.name == 'Topic' - assert result.icon_color == 4294967295 - assert result.icon_custom_emoji_id == 'emoji1' - assert result.is_name_implicit == True - assert isinstance(result, types.ForumTopic) - - -def test_json_loginurl(): - json_dict = json.loads(r'{"url": "https://example.com", "forward_text": "Forward", "bot_username": "botuser", "request_write_access": true}') - result = types.LoginUrl.de_json(json_dict) - assert result.url == 'https://example.com' - assert result.forward_text == 'Forward' - assert result.bot_username == 'botuser' - assert result.request_write_access == True - assert isinstance(result, types.LoginUrl) - - -def test_json_webappinfo(): - json_dict = json.loads(r'{"url": "https://example.com"}') - result = types.WebAppInfo.de_json(json_dict) - assert result.url == 'https://example.com' - assert isinstance(result, types.WebAppInfo) - - -def test_json_webappdata(): - json_dict = json.loads(r'{"data": "test_data", "button_text": "Button"}') - result = types.WebAppData.de_json(json_dict) - assert result.data == 'test_data' - assert result.button_text == 'Button' - assert isinstance(result, types.WebAppData) - - -def test_json_maskposition(): - json_dict = json.loads(r'{"point": "forehead", "x_shift": 0.0, "y_shift": 0.0, "scale": 0.5}') - result = types.MaskPosition.de_json(json_dict) - assert result.point == 'forehead' - assert result.x_shift == 0.0 - assert result.y_shift == 0.0 - assert result.scale == 0.5 - assert isinstance(result, types.MaskPosition) - - -def test_json_messageentity(): - json_dict = json.loads(r'{"type": "bold", "offset": 0, "length": 5, "url": "https://example.com", "language": "en", "unix_time": 1682189507, "date_time_format": "YYYY-MM-DD"}') - result = types.MessageEntity.de_json(json_dict) - assert result.type == 'bold' - assert result.offset == 0 - assert result.length == 5 - assert result.url == 'https://example.com' - assert result.language == 'en' - assert result.unix_time == 1682189507 - assert result.date_time_format == 'YYYY-MM-DD' - assert isinstance(result, types.MessageEntity) - - -def test_json_messageentitycustomemoji(): - json_dict = json.loads(r'{"type": "custom_emoji", "offset": 0, "length": 10, "custom_emoji_id": "ce123"}') - result = types.MessageEntity.de_json(json_dict) - assert result.type == 'custom_emoji' - assert result.offset == 0 - assert result.length == 10 - assert result.custom_emoji_id == 'ce123' - assert isinstance(result, types.MessageEntity) - - -def test_json_messageentitytextmention(): - json_dict = json.loads(r'{"type": "text_mention", "offset": 0, "length": 10, "user": {"id": 12345, "is_bot": false, "first_name": "Test"}}') - result = types.MessageEntity.de_json(json_dict) - assert result.type == 'text_mention' - assert result.offset == 0 - assert result.length == 10 - assert isinstance(result.user, types.User) - assert isinstance(result, types.MessageEntity) - - -def test_json_chatshared(): - json_dict = json.loads(r'{"request_id": 1, "chat_id": 12345, "title": "Chat Title", "photo": {"small_file_id": "s", "small_file_unique_id": "su", "big_file_id": "b", "big_file_unique_id": "bu"}, "username": "chatuser"}') - result = types.ChatShared.de_json(json_dict) - assert result.request_id == 1 - assert result.chat_id == 12345 - assert result.title == 'Chat Title' - # photo is returned as dict in this fork (not parsed to ChatPhoto) - assert isinstance(result.photo, dict) - assert result.photo.get('small_file_id') == 's' - assert result.username == 'chatuser' - assert isinstance(result, types.ChatShared) - - -def test_json_shareduser(): - json_dict = json.loads(r'{"user_id": 12345, "first_name": "Test", "last_name": "User", "username": "testuser", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}') - result = types.SharedUser.de_json(json_dict) - assert result.user_id == 12345 - assert result.first_name == 'Test' - assert result.last_name == 'User' - assert result.username == 'testuser' - assert isinstance(result.photo, list) - assert isinstance(result.photo[0], types.PhotoSize) - assert isinstance(result, types.SharedUser) - - -def test_json_usersshared(): - json_dict = json.loads(r'{"request_id": 1, "users": [{"user_id": 12345, "first_name": "Test", "last_name": "User"}]}') - result = types.UsersShared.de_json(json_dict) - assert result.request_id == 1 - assert isinstance(result.users, list) - assert isinstance(result, types.UsersShared) - - -def test_json_chatboost(): - json_dict = json.loads(r'{"boost_item_id": "b1", "add_date": 1682189507, "expiration_date": 1682275907, "source": {"source": "premium", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}}') - result = types.ChatBoost.de_json(json_dict) - assert result.boost_id is None - assert result.add_date == 1682189507 - assert result.expiration_date == 1682275907 - assert isinstance(result.source, types.ChatBoostSourcePremium) - assert result.source.source == 'premium' - assert isinstance(result.source.user, types.User) - assert isinstance(result, types.ChatBoost) - - -def test_json_gift(): - json_dict = json.loads(r'{"id": 123456789, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100, "total_count": 5, "remaining_count": 3, "upgrade_star_count": 50, "personal_total_count": 10, "personal_remaining_count": 2, "is_premium": true, "has_colors": true, "background": {"center_color": 16777215, "edge_color": 16711680, "text_color": 0}, "publisher_chat": {"id": 1, "type": "channel", "title": "Publisher"}, "unique_gift_variant_count": 3}') - result = types.Gift.de_json(json_dict) - assert result.id == 123456789 - assert isinstance(result.sticker, types.Sticker) - assert result.star_count == 100 - assert result.total_count == 5 - assert result.remaining_count == 3 - assert result.upgrade_star_count == 50 - assert result.personal_total_count == 10 - assert result.personal_remaining_count == 2 - assert result.is_premium == True - assert result.has_colors == True - assert isinstance(result.background, types.GiftBackground) - assert isinstance(result.publisher_chat, types.Chat) - assert result.unique_gift_variant_count == 3 - assert isinstance(result, types.Gift) - - -def test_json_giftinfo(): - json_dict = json.loads(r'{"gift": {"id": 123456789, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100}, "owned_gift_id": "og_123", "convert_star_count": 50, "prepaid_upgrade_star_count": 100, "can_be_upgraded": true, "text": {"type": "bold", "text": "Gift text"}, "entities": [{"type": "bold", "offset": 0, "length": 4}], "is_private": false, "is_upgrade_separate": false, "unique_gift_number": 42}') - result = types.GiftInfo.de_json(json_dict) - assert isinstance(result.gift, types.Gift) - assert result.owned_gift_id == 'og_123' - assert result.convert_star_count == 50 - assert result.prepaid_upgrade_star_count == 100 - assert result.can_be_upgraded == True - assert result.text == {'type': 'bold', 'text': 'Gift text'} - assert isinstance(result.entities, list) - assert result.is_private == False - assert result.is_upgrade_separate == False - assert result.unique_gift_number == 42 - assert isinstance(result, types.GiftInfo) - - -def test_json_gifts(): - json_dict = json.loads(r'{"gifts": [{"id": 123456789, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100}]}') - result = types.Gifts.de_json(json_dict) - assert isinstance(result.gifts, list) - assert isinstance(result, types.Gifts) - - -def test_json_richtextbold(): - json_dict = json.loads(r'{"type": "bold", "text": "Test"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextBold.de_json(data) - assert result.text == 'Test' - assert isinstance(result, types.RichTextBold) - - -def test_json_richtextitalic(): - json_dict = json.loads(r'{"type": "italic", "text": "Test"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextItalic.de_json(data) - assert result.text == 'Test' - assert isinstance(result, types.RichTextItalic) - - -def test_json_richtextunderline(): - json_dict = json.loads(r'{"type": "underline", "text": "Test"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextUnderline.de_json(data) - assert result.text == 'Test' - assert isinstance(result, types.RichTextUnderline) - - -def test_json_richtextstrikethrough(): - json_dict = json.loads(r'{"type": "strikethrough", "text": "Test"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextStrikethrough.de_json(data) - assert result.text == 'Test' - assert isinstance(result, types.RichTextStrikethrough) - - -def test_json_richtextspoiler(): - json_dict = json.loads(r'{"type": "spoiler", "text": "Test"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextSpoiler.de_json(data) - assert result.text == 'Test' - assert isinstance(result, types.RichTextSpoiler) - - -def test_json_richtextsubscript(): - json_dict = json.loads(r'{"type": "subscript", "text": "sub"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextSubscript.de_json(data) - assert result.text == 'sub' - assert isinstance(result, types.RichTextSubscript) - - -def test_json_richtextsuperscript(): - json_dict = json.loads(r'{"type": "superscript", "text": "sup"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextSuperscript.de_json(data) - assert result.text == 'sup' - assert isinstance(result, types.RichTextSuperscript) - - -def test_json_richtextmarked(): - json_dict = json.loads(r'{"type": "marked", "text": "marked"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextMarked.de_json(data) - assert result.text == 'marked' - assert isinstance(result, types.RichTextMarked) - - -def test_json_richtextcode(): - json_dict = json.loads(r'{"type": "code", "text": "code"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextCode.de_json(data) - assert result.text == 'code' - assert isinstance(result, types.RichTextCode) - - -def test_json_richtextanchor(): - json_dict = json.loads(r'{"type": "anchor", "name": "anchor"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextAnchor.de_json(data) - assert result.name == 'anchor' - assert isinstance(result, types.RichTextAnchor) - - -def test_json_richtextdatetime(): - json_dict = json.loads(r'{"type": "date_time", "text": "2024-01-01", "unix_time": 1704067200, "date_time_format": "YYYY-MM-DD"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextDateTime.de_json(data) - assert result.text == '2024-01-01' - assert result.unix_time == 1704067200 - assert result.date_time_format == 'YYYY-MM-DD' - assert isinstance(result, types.RichTextDateTime) - - -def test_json_richtexttextmention(): - json_dict = json.loads(r'{"type": "text_mention", "text": "test text", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextTextMention.de_json(data) - assert result.text == 'test text' - assert isinstance(result.user, types.User) - assert isinstance(result, types.RichTextTextMention) - - -def test_json_richtextanchorlink(): - json_dict = json.loads(r'{"type": "anchor_link", "text": "Link", "anchor_name": "anchor"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextAnchorLink.de_json(data) - assert result.text == 'Link' - assert result.anchor_name == 'anchor' - assert isinstance(result, types.RichTextAnchorLink) - - -def test_json_richtexturl(): - json_dict = json.loads(r'{"type": "url", "text": "click here", "url": "https://example.com"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextUrl.de_json(data) - assert result.text == 'click here' - assert result.url == 'https://example.com' - assert isinstance(result, types.RichTextUrl) - - -def test_json_richtextemailaddress(): - json_dict = json.loads(r'{"type": "email_address", "text": "test@example.com", "email_address": "test@example.com"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextEmailAddress.de_json(data) - assert result.text == 'test@example.com' - assert result.email_address == 'test@example.com' - assert isinstance(result, types.RichTextEmailAddress) - - -def test_json_richtextphonenumber(): - json_dict = json.loads(r'{"type": "phone_number", "text": "+123****7890", "phone_number": "+123****7890"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextPhoneNumber.de_json(data) - assert result.text == '+123****7890' - assert result.phone_number == '+123****7890' - assert isinstance(result, types.RichTextPhoneNumber) - - -def test_json_richtextbankcardnumber(): - json_dict = json.loads(r'{"type": "bank_card_number", "text": "1234 5678 9012 3456", "bank_card_number": "1234 5678 9012 3456"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextBankCardNumber.de_json(data) - assert result.text == '1234 5678 9012 3456' - assert result.bank_card_number == '1234 5678 9012 3456' - assert isinstance(result, types.RichTextBankCardNumber) - - -def test_json_richblockparagraph(): - json_dict = json.loads(r'{"type": "paragraph", "text": "Test"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichBlockParagraph.de_json(data) - assert result.text == 'Test' - assert isinstance(result, types.RichBlockParagraph) - - -def test_json_richblockpreformatted(): - json_dict = json.loads(r'{"type": "preformatted", "text": "Code", "language": "python"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichBlockPreformatted.de_json(data) - assert result.text == 'Code' - assert result.language == 'python' - assert isinstance(result, types.RichBlockPreformatted) - - -def test_json_richblockfooter(): - json_dict = json.loads(r'{"type": "footer", "text": "Footer"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichBlockFooter.de_json(data) - assert result.text == 'Footer' - assert isinstance(result, types.RichBlockFooter) - - -def test_json_richblockcaption(): - json_dict = json.loads(r'{"type": "caption", "text": "Caption", "credit": "Author"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichBlockCaption.de_json(data) - assert result.text == 'Caption' - assert result.credit == 'Author' - assert isinstance(result, types.RichBlockCaption) - - -def test_json_richblockanimation(): - json_dict = json.loads(r'{"type": "animation", "animation": {"file_id": "anim_id", "file_unique_id": "anim_uid", "width": 100, "height": 100, "duration": 10}, "caption": {"type": "bold", "text": "anim caption"}, "has_spoiler": true}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichBlockAnimation.de_json(data) - assert isinstance(result.animation, types.Animation) - assert result.has_spoiler == True - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockAnimation) - - -def test_json_richblockdetails(): - json_dict = json.loads(r'{"type": "details", "summary": {"text": "summary text"}, "blocks": [{"text": "detail"}], "is_open": false}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichBlockDetails.de_json(data) - assert isinstance(result.summary, dict) or result.summary is None - assert isinstance(result.blocks, list) - assert result.is_open == False - assert isinstance(result, types.RichBlockDetails) - - -def test_json_richblocklistitem(): - json_dict = json.loads(r'{"label": {"text": "label text"}, "blocks": [{"text": "item block"}], "has_checkbox": true, "is_checked": true, "value": "item value"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichBlockListItem.de_json(data) - assert isinstance(result.label, dict) - assert isinstance(result.blocks, list) - assert result.has_checkbox == True - assert result.is_checked == True - assert result.value == 'item value' - assert result.type is None - assert isinstance(result, types.RichBlockListItem) - - -def test_json_richblockvoicenote(): - json_dict = json.loads(r'{"type": "voice_note", "voice_note": {"file_id": "voice_id", "file_unique_id": "voice_uid", "duration": 30}, "caption": {"type": "bold", "text": "voice caption"}}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichBlockVoiceNote.de_json(data) - assert isinstance(result.voice_note, types.Voice) - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockVoiceNote) - - -def test_json_chatadministratorrights(): - json_dict = json.loads(r'{"is_anonymous": true, "can_manage_chat": true, "can_delete_messages": true, "can_manage_video_chats": true, "can_restrict_members": true, "can_promote_members": true, "can_change_info": true, "can_invite_users": true, "can_post_messages": true, "can_edit_messages": true, "can_pin_messages": true, "can_manage_topics": true, "can_post_stories": true, "can_edit_stories": true, "can_delete_stories": true, "can_manage_direct_messages": true, "can_manage_tags": true}') - result = types.ChatAdministratorRights.de_json(json_dict) - assert result.is_anonymous == True - assert result.can_manage_chat == True - assert result.can_delete_messages == True - assert result.can_manage_video_chats == True - assert result.can_restrict_members == True - assert result.can_promote_members == True - assert result.can_change_info == True - assert result.can_invite_users == True - assert result.can_post_messages == True - assert result.can_edit_messages == True - assert result.can_pin_messages == True - assert result.can_manage_topics == True - assert result.can_post_stories == True - assert result.can_edit_stories == True - assert result.can_delete_stories == True - assert result.can_manage_direct_messages == True - assert result.can_manage_tags == True - assert isinstance(result, types.ChatAdministratorRights) - - -def test_json_chatpermissions(): - json_dict = json.loads(r'{"can_send_messages": true, "can_send_audios": true, "can_send_documents": true, "can_send_photos": true, "can_send_videos": true, "can_send_video_notes": true, "can_send_voice_notes": true, "can_send_polls": true, "can_send_other_messages": true, "can_add_web_page_previews": true, "can_change_info": true, "can_invite_users": true, "can_pin_messages": true, "can_manage_topics": true, "can_edit_tag": true, "can_react_to_messages": true}') - result = types.ChatPermissions.de_json(json_dict) - assert result.can_send_messages == True - # can_send_media_messages is deprecated in this fork, not a real attribute - assert result.can_send_audios == True - assert result.can_send_documents == True - assert result.can_send_photos == True - assert result.can_send_videos == True - assert result.can_send_video_notes == True - assert result.can_send_voice_notes == True - assert result.can_send_polls == True - assert result.can_send_other_messages == True - assert result.can_add_web_page_previews == True - assert result.can_change_info == True - assert result.can_invite_users == True - assert result.can_pin_messages == True - assert result.can_manage_topics == True - assert result.can_edit_tag == True - assert result.can_react_to_messages == True - assert isinstance(result, types.ChatPermissions) - - -def test_json_chatmembermember(): - json_dict = json.loads(r'{"user": {"id": 1, "is_bot": false, "first_name": "Test"}, "status": "member", "until_date": 1682275907, "tag": "member_tag"}') - result = types.ChatMemberMember.de_json(json_dict) - assert isinstance(result.user, types.User) - assert result.status == 'member' - assert result.until_date == 1682275907 - assert result.tag == 'member_tag' - assert isinstance(result, types.ChatMemberMember) - - -def test_json_chatmemberowner(): - json_dict = json.loads(r'{"status": "creator", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "is_anonymous": false, "custom_title": "Owner"}') - result = types.ChatMemberOwner.de_json(json_dict) - assert isinstance(result.user, types.User) - assert result.status == 'creator' - assert result.is_anonymous == False - assert result.custom_title == 'Owner' - assert isinstance(result, types.ChatMemberOwner) - - -def test_json_chatmemberadministrator(): - json_dict = json.loads(r'{"status": "administrator", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "is_anonymous": true, "can_be_edited": true, "can_manage_chat": true, "can_delete_messages": true, "can_manage_video_chats": true, "can_restrict_members": true, "can_promote_members": true, "can_change_info": true, "can_invite_users": true, "can_post_stories": true, "can_edit_stories": true, "can_delete_stories": true, "can_post_messages": true, "can_edit_messages": true, "can_pin_messages": true, "can_manage_topics": true, "can_manage_direct_messages": true, "can_manage_tags": true, "custom_title": "mod"}') - result = types.ChatMemberAdministrator.de_json(json_dict) - assert isinstance(result.user, types.User) - assert result.status == 'administrator' - assert result.can_be_edited == True - assert result.is_anonymous == True - assert result.can_manage_chat == True - assert result.can_delete_messages == True - assert result.can_manage_video_chats == True - assert result.can_restrict_members == True - assert result.can_promote_members == True - assert result.can_change_info == True - assert result.can_invite_users == True - assert result.can_post_stories == True - assert result.can_edit_stories == True - assert result.can_delete_stories == True - assert result.can_post_messages == True - assert result.can_edit_messages == True - assert result.can_pin_messages == True - assert result.can_manage_topics == True - assert result.custom_title == "mod" - assert result.can_manage_direct_messages == True - assert result.can_manage_tags == True - assert isinstance(result, types.ChatMemberAdministrator) - - -def test_json_chatmemberrestricted(): - json_dict = json.loads(r'{"status": "restricted", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "is_member": true, "can_send_messages": true, "can_send_audios": true, "can_send_documents": true, "can_send_photos": true, "can_send_videos": true, "can_send_video_notes": true, "can_send_voice_notes": true, "can_send_polls": true, "can_send_other_messages": true, "can_add_web_page_previews": true, "can_change_info": false, "can_invite_users": false, "can_pin_messages": false, "can_manage_topics": false, "until_date": 1682189507, "tag": "test_tag", "can_edit_tag": true, "can_react_to_messages": true}') - result = types.ChatMemberRestricted.de_json(json_dict) - assert isinstance(result.user, types.User) - assert result.status == 'restricted' - assert result.is_member == True - assert result.can_send_messages == True - assert result.can_send_audios == True - assert result.can_send_documents == True - assert result.can_send_photos == True - assert result.can_send_videos == True - assert result.can_send_video_notes == True - assert result.can_send_voice_notes == True - assert result.can_send_polls == True - assert result.can_send_other_messages == True - assert result.can_add_web_page_previews == True - assert result.can_change_info == False - assert result.can_invite_users == False - assert result.can_pin_messages == False - assert result.can_manage_topics == False - assert result.until_date == 1682189507 - assert result.tag == 'test_tag' - assert result.can_edit_tag == True - assert result.can_react_to_messages == True - assert isinstance(result, types.ChatMemberRestricted) - - -def test_json_chatmemberleft(): - json_dict = json.loads(r'{"status": "left", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}}') - result = types.ChatMemberLeft.de_json(json_dict) - assert isinstance(result.user, types.User) - assert result.status == 'left' - assert isinstance(result, types.ChatMemberLeft) - - -def test_json_chatmemberbanned(): - json_dict = json.loads(r'{"status": "kicked", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "until_date": 1682189507}') - result = types.ChatMemberBanned.de_json(json_dict) - assert isinstance(result.user, types.User) - assert result.status == 'kicked' - assert result.until_date == 1682189507 - assert isinstance(result, types.ChatMemberBanned) - - -def test_json_botcommand(): - json_dict = json.loads(r'{"command": "/start", "description": "Start command", "is_ephemeral": true}') - result = types.BotCommand.de_json(json_dict) - assert result.command == '/start' - assert result.description == 'Start command' - assert result.is_ephemeral == True - assert isinstance(result, types.BotCommand) - - -def test_json_botdescription(): - json_dict = json.loads(r'{"language_code": "en", "description": "Bot description"}') - result = types.BotDescription.de_json(json_dict) - assert result.description == 'Bot description' - assert isinstance(result, types.BotDescription) - - -def test_json_botname(): - json_dict = json.loads(r'{"language_code": "en", "name": "Bot Name"}') - result = types.BotName.de_json(json_dict) - assert result.name == 'Bot Name' - assert isinstance(result, types.BotName) - - -def test_json_botshortdescription(): - json_dict = json.loads(r'{"language_code": "en", "short_description": "Short"}') - result = types.BotShortDescription.de_json(json_dict) - assert result.short_description == 'Short' - assert isinstance(result, types.BotShortDescription) - - -def test_json_inlinekeyboardbutton(): - json_dict = json.loads(r'{"text": "Button", "url": "https://example.com", "callback_data": "data", "web_app": {"url": "https://example.com"}, "switch_inline_query": "query", "switch_inline_query_current_chat": "query", "switch_inline_query_chosen_chat": {"query": "q", "allow_user_chats": true, "allow_bot_chats": true, "allow_group_chats": true, "allow_channel_chats": true}, "callback_game": {"type": "test"}, "pay": true, "login_url": {"url": "https://example.com", "forward_text": "Forward", "bot_username": "bot", "request_write_access": true}, "copy_text": {"text": "copy"}, "icon_custom_emoji_id": "emoji123", "style": "primary"}') - result = types.InlineKeyboardButton.de_json(json_dict) - assert result.text == 'Button' - assert result.url == 'https://example.com' - assert result.callback_data == 'data' - assert isinstance(result.web_app, types.WebAppInfo) - assert result.switch_inline_query == 'query' - assert result.switch_inline_query_current_chat == 'query' - assert isinstance(result.switch_inline_query_chosen_chat, types.SwitchInlineQueryChosenChat) - assert isinstance(result.callback_game, dict) - assert result.pay == True - assert isinstance(result.login_url, types.LoginUrl) - assert isinstance(result.copy_text, types.CopyTextButton) - assert result.icon_custom_emoji_id == 'emoji123' - assert result.style == 'primary' - assert isinstance(result, types.InlineKeyboardButton) - - -def test_json_menubuttoncommands(): - json_dict = json.loads(r'{"type": "commands", "default_width": 100}') - result = types.MenuButtonCommands.de_json(json_dict) - assert result.type == 'commands' - assert isinstance(result, types.MenuButtonCommands) - - -def test_json_menubuttondefault(): - json_dict = json.loads(r'{"type": "default"}') - result = types.MenuButtonDefault.de_json(json_dict) - assert result.type == 'default' - assert isinstance(result, types.MenuButtonDefault) - - -def test_json_menubuttonwebapp(): - json_dict = json.loads(r'{"type": "web_app", "text": "Open App", "web_app": {"url": "https://example.com"}}') - result = types.MenuButtonWebApp.de_json(json_dict) - assert result.type == 'web_app' - assert result.text == 'Open App' - assert isinstance(result.web_app, dict) - assert isinstance(result, types.MenuButtonWebApp) - - -def test_json_pollanswer(): - json_dict = json.loads(r'{"poll_id": "poll_id", "option_ids": [0], "option_persistent_ids": [0], "user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "voter_chat": {"id": 67890, "type": "channel", "title": "Channel"}}') - result = types.PollAnswer.de_json(json_dict) - assert result.poll_id == 'poll_id' - assert isinstance(result.option_ids, list) - assert isinstance(result.option_persistent_ids, list) - assert isinstance(result.user, types.User) - assert isinstance(result.voter_chat, types.Chat) - assert isinstance(result, types.PollAnswer) - - -def test_json_reactiontype(): - json_dict = json.loads(r'{"type": "emoji", "emoji": "\u2764\uFE0F"}') - result = types.ReactionType.de_json(json_dict) - assert result.type == 'emoji' - assert isinstance(result, types.ReactionType) - - -def test_linkpreviewoptionsto_dict(): - obj = types.LinkPreviewOptions(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_sentwebappmessageto_dict(): - obj = types.SentWebAppMessage(message_id=1) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_json_reactiontypepaid(): - json_dict = json.loads(r'{"type": "paid"}') - result = types.ReactionTypePaid.de_json(json_dict) - assert isinstance(result, types.ReactionTypePaid) - - -def test_json_businessbotrights(): - result = types.BusinessBotRights.de_json({}) - assert result.can_reply is None - assert result.can_read_messages is None - assert result.can_delete_outgoing_messages is None - assert result.can_delete_all_messages is None - assert result.can_edit_name is None - assert result.can_edit_bio is None - assert result.can_edit_profile_photo is None - assert result.can_edit_username is None - assert result.can_change_gift_settings is None - assert result.can_view_gifts_and_stars is None - assert result.can_convert_gifts_to_stars is None - assert result.can_transfer_and_upgrade_gifts is None - assert result.can_transfer_stars is None - assert result.can_manage_stories is None - assert isinstance(result, types.BusinessBotRights) - - -def test_json_businessintro(): - json_dict = json.loads(r'{"title": "Business Title", "message": "Business message text", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}}') - result = types.BusinessIntro.de_json(json_dict) - assert result.title == 'Business Title' - assert result.message == 'Business message text' - assert isinstance(result.sticker, types.Sticker) - assert isinstance(result, types.BusinessIntro) - - -def test_json_chatownerleft(): - result = types.ChatOwnerLeft.de_json({}) - assert isinstance(result, types.ChatOwnerLeft) or result is None - assert result.new_owner is None - - -def test_json_checklisttasksdone(): - json_dict = json.loads(r'{"checklist_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "checklist"}, "marked_as_done_task_ids": [1, 2], "marked_as_not_done_task_ids": [3]}') - result = types.ChecklistTasksDone.de_json(json_dict) - assert isinstance(result.checklist_message, types.Message) - assert isinstance(result.marked_as_done_task_ids, list) - assert result.marked_as_done_task_ids == [1, 2] - assert isinstance(result.marked_as_not_done_task_ids, list) - assert result.marked_as_not_done_task_ids == [3] - assert isinstance(result, types.ChecklistTasksDone) - - -def test_json_communitychatadded(): - result = types.CommunityChatAdded.de_json({}) - assert isinstance(result, types.CommunityChatAdded) or result is None - assert result.community is None - - -def test_json_communitychatremoved(): - result = types.CommunityChatRemoved.de_json({}) - assert isinstance(result, types.CommunityChatRemoved) or result is None - - -def test_json_forumtopicclosed(): - result = types.ForumTopicClosed.de_json({}) - assert isinstance(result, types.ForumTopicClosed) or result is None - - -def test_json_forumtopicedited(): - result = types.ForumTopicEdited.de_json({'name': 'New Name', 'icon_custom_emoji_id': 'custom_emoji'}) - assert result.name == 'New Name' - assert result.icon_custom_emoji_id == 'custom_emoji' - assert isinstance(result, types.ForumTopicEdited) - - -def test_json_forumtopicreopened(): - result = types.ForumTopicReopened.de_json({}) - assert isinstance(result, types.ForumTopicReopened) or result is None - - -def test_json_generalforumtopichidden(): - result = types.GeneralForumTopicHidden.de_json({}) - assert isinstance(result, types.GeneralForumTopicHidden) or result is None - - -def test_json_generalforumtopicunhidden(): - result = types.GeneralForumTopicUnhidden.de_json({}) - assert isinstance(result, types.GeneralForumTopicUnhidden) or result is None - - -def test_json_giveawaycreated(): - result = types.GiveawayCreated.de_json({}) - assert isinstance(result, types.GiveawayCreated) or result is None - assert hasattr(result, 'prize_star_count') - - -def test_json_linkpreviewoptions(): - result = types.LinkPreviewOptions.de_json({}) - assert result.is_disabled is None - assert result.url is None - assert result.prefer_small_media is None - assert result.prefer_large_media is None - assert result.show_above_text is None - assert isinstance(result, types.LinkPreviewOptions) - - -def test_json_orderinfo(): - json_dict = {'name': 'John', 'phone_number': '+1234567890', 'email': 'john@example.com', 'shipping_address': {'country_code': 'US', 'city': 'New York', 'street_line1': '123 Main St', 'street_line2': 'Apt 4B', 'postal_code': '10001', 'state': 'NY', 'post_code': '10001'}} - result = types.OrderInfo.de_json(json_dict) - assert result.name == 'John' - assert result.phone_number == '+1234567890' - assert result.email == 'john@example.com' - assert isinstance(result.shipping_address, types.ShippingAddress) - assert isinstance(result, types.OrderInfo) or result is None - assert hasattr(result, 'name') - assert hasattr(result, 'phone_number') - assert hasattr(result, 'email') - - -def test_json_pollmedia(): - json_dict = json.loads(r'{"animation": {"file_id": "a", "file_unique_id": "au", "width": 100, "height": 100, "duration": 10}, "audio": {"file_id": "au1", "file_unique_id": "au1u", "duration": 30}, "document": {"file_id": "d", "file_unique_id": "du", "file_name": "test.pdf"}, "live_photo": {"file_id": "lp", "file_unique_id": "lpu", "width": 100, "height": 100, "duration": 5}, "location": {"latitude": 50.45, "longitude": 30.52}, "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}], "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "venue": {"location": {"latitude": 50.45, "longitude": 30.52}, "title": "Place", "address": "Addr"}, "video": {"file_id": "v", "file_unique_id": "vu", "width": 640, "height": 480, "duration": 30}, "link": {"url": "https://example.com", "shows_above_caption": true, "enhanced_smileys": true, "prefer_large_media": true}}') - result = types.PollMedia.de_json(json_dict) - assert isinstance(result.animation, types.Animation) - assert isinstance(result.audio, types.Audio) - assert isinstance(result.document, types.Document) - assert isinstance(result.live_photo, types.LivePhoto) - assert isinstance(result.location, types.Location) - assert isinstance(result.photo, list) - assert isinstance(result.sticker, types.Sticker) - assert isinstance(result.venue, types.Venue) - assert isinstance(result.video, types.Video) - assert isinstance(result.link, types.Link) - assert isinstance(result, types.PollMedia) - - -def test_json_richblock(): - result = types.RichBlock.de_json({}) - assert isinstance(result, types.RichBlock) or result is None - - -def test_json_richblockdivider(): - result = types.RichBlockDivider.de_json({}) - assert isinstance(result, types.RichBlockDivider) or result is None - - -def test_json_richtext(): - result = types.RichText.de_json({}) - assert isinstance(result, types.RichText) or result is None - - -def test_json_sentwebappmessage(): - result = types.SentWebAppMessage.de_json({}) - assert isinstance(result, types.SentWebAppMessage) or result is None - assert hasattr(result, 'inline_message_id') - - -def test_json_suggestedpostdeclined(): - json_dict = json.loads(r'{"suggested_post_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "suggested"}, "comment": "declined reason"}') - result = types.SuggestedPostDeclined.de_json(json_dict) - assert isinstance(result.suggested_post_message, types.Message) - assert result.comment == 'declined reason' - assert isinstance(result, types.SuggestedPostDeclined) - - -def test_json_switchinlinequerychosenchat(): - json_dict = json.loads(r'{"query": "test", "allow_user_chats": true, "allow_bot_chats": true, "allow_group_chats": true, "allow_channel_chats": true}') - result = types.SwitchInlineQueryChosenChat.de_json(json_dict) - assert result.query == 'test' - assert result.allow_user_chats == True - assert result.allow_bot_chats == True - assert result.allow_group_chats == True - assert result.allow_channel_chats == True - assert isinstance(result, types.SwitchInlineQueryChosenChat) - - -def test_json_transactionpartnertelegramads(): - result = types.TransactionPartnerTelegramAds.de_json(None) - assert isinstance(result, types.TransactionPartnerTelegramAds) or result is None - - -def test_json_videochatstarted(): - result = types.VideoChatStarted.de_json({}) - assert isinstance(result, types.VideoChatStarted) or result is None - - -def test_json_voicechatstarted(): - result = types.VoiceChatStarted.de_json({}) - assert isinstance(result, types.VoiceChatStarted) or result is None - - -def test_json_writeaccessallowed(): - result = types.WriteAccessAllowed.de_json({'from_request': True, 'web_app_name': 'TestApp', 'from_attachment_menu': False}) - assert result.from_request == True - assert result.web_app_name == 'TestApp' - assert result.from_attachment_menu == False - assert isinstance(result, types.WriteAccessAllowed) - - -def test_json_acceptedgifttypes(): - json_dict = json.loads(r'{"unlimited_gifts": "test", "limited_gifts": "test", "unique_gifts": "test", "premium_subscription": "test", "gifts_from_channels": "test"}') - result = types.AcceptedGiftTypes.de_json(json_dict) - assert result.unlimited_gifts == 'test' - assert result.limited_gifts == 'test' - assert result.unique_gifts == 'test' - assert result.premium_subscription == 'test' - assert result.gifts_from_channels == 'test' - assert isinstance(result, types.AcceptedGiftTypes) - - -def test_json_copytextbutton(): - json_dict = json.loads(r'{"text": "Test"}') - result = types.CopyTextButton.de_json(json_dict) - assert result.text == 'Test' - assert isinstance(result, types.CopyTextButton) - - -def test_json_dice(): - json_dict = json.loads(r'{"value": "test", "emoji": "😀"}') - result = types.Dice.de_json(json_dict) - assert result.value == 'test' - assert result.emoji == '😀' - assert isinstance(result, types.Dice) - - -def test_json_richblocktablecell(): - json_dict = json.loads(r'{"align": "test", "valign": "test", "text": "Test", "is_header": true, "colspan": "test", "rowspan": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockTableCell.de_json(data) - assert result.align == 'test' - assert result.valign == 'test' - assert result.text == 'Test' - assert result.is_header == True - assert result.colspan == 'test' - assert result.rowspan == 'test' - assert isinstance(result, types.RichBlockTableCell) - - -def test_json_richtextbotcommand(): - json_dict = json.loads(r'{"type": "bot_command", "text": "Test", "bot_command": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichTextBotCommand.de_json(data) - assert result.text == 'Test' - assert result.bot_command == 'test' - assert isinstance(result, types.RichTextBotCommand) - - -def test_json_richtextcashtag(): - json_dict = json.loads(r'{"type": "cashtag", "text": "Test", "cashtag": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichTextCashtag.de_json(data) - assert result.text == 'Test' - assert result.cashtag == 'test' - assert isinstance(result, types.RichTextCashtag) - - -def test_json_richtextcustomemoji(): - json_dict = json.loads(r'{"type": "custom_emoji", "custom_emoji_id": "test", "alternative_text": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichTextCustomEmoji.de_json(data) - assert result.custom_emoji_id == 'test' - assert result.alternative_text == 'test' - assert isinstance(result, types.RichTextCustomEmoji) - - -def test_json_richtexthashtag(): - json_dict = json.loads(r'{"type": "hashtag", "text": "Test", "hashtag": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichTextHashtag.de_json(data) - assert result.text == 'Test' - assert result.hashtag == 'test' - assert isinstance(result, types.RichTextHashtag) - - -def test_json_richtextmathematicalexpression(): - json_dict = json.loads(r'{"type": "mathematical_expression", "expression": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichTextMathematicalExpression.de_json(data) - assert result.expression == 'test' - assert isinstance(result, types.RichTextMathematicalExpression) - - -def test_json_richtextmention(): - json_dict = json.loads(r'{"type": "mention", "text": "Test", "username": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichTextMention.de_json(data) - assert result.text == 'Test' - assert result.username == 'test' - assert isinstance(result, types.RichTextMention) - - -def test_json_richtextreference(): - json_dict = json.loads(r'{"type": "reference", "text": "Test", "name": "Test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichTextReference.de_json(data) - assert result.text == 'Test' - assert result.name == 'Test' - assert isinstance(result, types.RichTextReference) - - -def test_json_richtextreferencelink(): - json_dict = json.loads(r'{"type": "reference_link", "text": "Test", "reference_name": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichTextReferenceLink.de_json(data) - assert result.text == 'Test' - assert result.reference_name == 'test' - assert isinstance(result, types.RichTextReferenceLink) - - -def test_json_suggestedpostprice(): - json_dict = json.loads(r'{"currency": "en", "amount": 1}') - result = types.SuggestedPostPrice.de_json(json_dict) - assert result.currency == 'en' - assert result.amount == 1 - assert isinstance(result, types.SuggestedPostPrice) - - -def test_json_affiliateinfo(): - json_dict = json.loads(r'{"commission_per_mille": 1000, "amount": 100, "affiliate_user": {"id": 1, "is_bot": false, "first_name": "User"}, "affiliate_chat": {"id": -1001234567890, "type": "channel", "title": "Channel"}, "nanostar_amount": 10000000}') - result = types.AffiliateInfo.de_json(json_dict) - assert result.commission_per_mille == 1000 - assert result.amount == 100 - assert isinstance(result.affiliate_user, types.User) - assert isinstance(result.affiliate_chat, types.Chat) - assert result.nanostar_amount == 10000000 - assert isinstance(result, types.AffiliateInfo) - - -def test_json_backgroundfill(): - # BackgroundFill is abstract - test BackgroundFillSolid directly - json_dict = json.loads(r'{"type": "solid", "color": 123456}') - result = types.BackgroundFillSolid.de_json(json_dict) - assert isinstance(result, types.BackgroundFillSolid) - - -def test_json_backgroundfillfreeformgradient(): - json_dict = json.loads(r'{"type": "freeform_gradient", "colors": [123456, 654321, 111222]}') - result = types.BackgroundFillFreeformGradient.de_json(json_dict) - assert result.type == 'freeform_gradient' - assert isinstance(result.colors, list) - assert isinstance(result, types.BackgroundFillFreeformGradient) - - -def test_json_backgroundfillgradient(): - json_dict = json.loads(r'{"type": "gradient", "top_color": 123456, "bottom_color": 654321, "rotation_angle": 180}') - result = types.BackgroundFillGradient.de_json(json_dict) - assert result.type == 'gradient' - assert result.top_color == 123456 - assert result.bottom_color == 654321 - assert result.rotation_angle == 180 - assert isinstance(result, types.BackgroundFillGradient) - - -def test_json_backgroundfillsolid(): - json_dict = json.loads(r'{"type": "solid", "color": 123456}') - result = types.BackgroundFillSolid.de_json(json_dict) - assert result.type == 'solid' - assert result.color == 123456 - assert isinstance(result, types.BackgroundFillSolid) - - -def test_json_backgroundtype(): - # BackgroundType is abstract - test BackgroundTypeFill directly - json_dict = json.loads(r'{"type": "fill", "fill": {"type": "solid", "color": 123456}, "dark_theme_dimming": 0}') - result = types.BackgroundTypeFill.de_json(json_dict) - assert isinstance(result, types.BackgroundTypeFill) - - -def test_json_backgroundtypechattheme(): - json_dict = json.loads(r'{"type": "fill", "theme_name": "test"}') - result = types.BackgroundTypeChatTheme.de_json(json_dict) - assert result.type == 'fill' - assert result.theme_name == 'test' - assert isinstance(result, types.BackgroundTypeChatTheme) - - -def test_json_backgroundtypefill(): - json_dict = json.loads(r'{"type": "solid", "fill": {"type": "solid", "color": 123456}, "dark_theme_dimming": 0}') - result = types.BackgroundTypeFill.de_json(json_dict) - assert result.type == 'solid' - assert isinstance(result.fill, types.BackgroundFill) - assert result.dark_theme_dimming == 0 - assert isinstance(result, types.BackgroundTypeFill) - - -def test_json_backgroundtypepattern(): - json_dict = json.loads(r'{"type": "pattern", "document": {"file_id": "doc", "file_unique_id": "docu", "mime_type": "application/pdf", "file_name": "test.pdf"}, "fill": {"type": "solid", "color": 123456}, "intensity": 0, "is_inverted": true, "is_moving": true}') - result = types.BackgroundTypePattern.de_json(json_dict) - assert result.type == 'pattern' - assert isinstance(result.document, types.Document) - assert isinstance(result.fill, dict) or result.fill is None - assert result.intensity == 0 - assert result.is_inverted == True - assert result.is_moving == True - assert isinstance(result, types.BackgroundTypePattern) - - -def test_json_backgroundtypewallpaper(): - json_dict = json.loads(r'{"type": "wallpaper", "document": {"file_id": "doc", "file_unique_id": "docu", "mime_type": "application/pdf", "file_name": "test.pdf"}, "dark_theme_dimming": 0, "is_blurred": true, "is_moving": true}') - result = types.BackgroundTypeWallpaper.de_json(json_dict) - assert result.type == 'wallpaper' - assert isinstance(result.document, types.Document) - assert result.dark_theme_dimming == 0 - assert result.is_blurred == True - assert result.is_moving == True - assert isinstance(result, types.BackgroundTypeWallpaper) - - -def test_json_birthdate(): - json_dict = json.loads(r'{"day": "test", "month": "test", "year": 1990}') - result = types.Birthdate.de_json(json_dict) - assert result.day == 'test' - assert result.month == 'test' - assert result.year == 1990 - assert isinstance(result, types.Birthdate) - - -def test_json_botaccesssettings(): - json_dict = json.loads(r'{"is_access_restricted": false, "added_users": [{"id": 1, "is_bot": false, "first_name": "Test"}, {"id": 2, "is_bot": false, "first_name": "User2"}]}') - result = types.BotAccessSettings.de_json(json_dict) - assert result.is_access_restricted == False - assert isinstance(result.added_users, list) - assert len(result.added_users) == 2 - assert isinstance(result.added_users[0], types.User) - assert result.added_users[0].id == 1 - assert isinstance(result, types.BotAccessSettings) - - -def test_json_botsubscriptionupdated(): - json_dict = json.loads(r'{"user": {"id": 1, "is_bot": false, "first_name": "Test"}, "invoice_payload": "test_payload", "state": "default"}') - result = types.BotSubscriptionUpdated.de_json(json_dict) - assert isinstance(result.user, types.User) - assert result.invoice_payload == 'test_payload' - assert result.state == 'default' - assert isinstance(result, types.BotSubscriptionUpdated) - - -def test_json_businessconnection(): - json_dict = json.loads(r'{"id": "1", "user": {"id": 1, "is_bot": false, "first_name": "Test"}, "user_chat_id": 1, "date": 1682189507, "is_enabled": false, "rights": {"can_reply": true, "can_read_messages": true, "can_delete_outgoing_messages": false, "can_delete_all_messages": false, "can_edit_name": true, "can_edit_bio": false, "can_edit_profile_photo": true, "can_edit_username": false, "can_change_gift_settings": true, "can_view_gifts_and_stars": false, "can_convert_gifts_to_stars": true, "can_transfer_and_upgrade_gifts": false, "can_transfer_stars": true, "can_manage_stories": false}}') - result = types.BusinessConnection.de_json(json_dict) - assert result.id == '1' - assert isinstance(result.user, types.User) - assert result.user_chat_id == 1 - assert result.date == 1682189507 - assert result.is_enabled == False - assert isinstance(result.rights, types.BusinessBotRights) - assert result.rights.can_reply == True - assert result.rights.can_read_messages == True - assert result.rights.can_delete_outgoing_messages == False - assert result.rights.can_delete_all_messages == False - assert result.rights.can_edit_name == True - assert result.rights.can_edit_bio == False - assert result.rights.can_edit_profile_photo == True - assert result.rights.can_edit_username == False - assert result.rights.can_change_gift_settings == True - assert result.rights.can_view_gifts_and_stars == False - assert result.rights.can_convert_gifts_to_stars == True - assert result.rights.can_transfer_and_upgrade_gifts == False - assert result.rights.can_transfer_stars == True - assert result.rights.can_manage_stories == False - assert isinstance(result, types.BusinessConnection) - - -def test_json_businesslocation(): - json_dict = json.loads(r'{"address": "NY", "location": {"latitude": 50.45, "longitude": 30.52, "horizontal_accuracy": 1.5}}') - result = types.BusinessLocation.de_json(json_dict) - assert result.address == 'NY' - assert isinstance(result.location, types.Location) - assert result.location.latitude == 50.45 - assert result.location.longitude == 30.52 - assert result.location.horizontal_accuracy == 1.5 - assert isinstance(result, types.BusinessLocation) - - -def test_json_businessmessagesdeleted(): - json_dict = json.loads(r'{"business_connection_id": 1, "chat": {"id": 1, "type": "private", "title": "Test"}, "message_ids": "test"}') - result = types.BusinessMessagesDeleted.de_json(json_dict) - assert result.business_connection_id == 1 - assert isinstance(result.chat, types.Chat) - assert result.message_ids == 'test' - assert isinstance(result, types.BusinessMessagesDeleted) - - -def test_json_businessopeninghours(): - json_dict = json.loads(r'{"time_zone_name": "test", "opening_hours": [{"opening_minute": 0, "closing_minute": 60}]}') - result = types.BusinessOpeningHours.de_json(json_dict) - assert result.time_zone_name == 'test' - assert isinstance(result.opening_hours, list) - assert isinstance(result, types.BusinessOpeningHours) - - -def test_json_businessopeninghoursinterval(): - json_dict = json.loads(r'{"opening_minute": 0, "closing_minute": 60}') - result = types.BusinessOpeningHoursInterval.de_json(json_dict) - assert result.opening_minute == 0 - assert result.closing_minute == 60 - assert isinstance(result, types.BusinessOpeningHoursInterval) - - -def test_json_callbackquery(): - # json_string is internal field, not covered (like Message.options/json_string) - json_dict = json.loads(r'{"id": "cq1", "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "data": "test", "chat_instance": "ci1", "message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "Hello"}, "inline_message_id": "im1", "game_short_name": "game"}') - result = types.CallbackQuery.de_json(json_dict) - assert result.id == 'cq1' - assert isinstance(result.from_user, types.User) - assert result.data == 'test' - assert result.chat_instance == 'ci1' - assert isinstance(result.message, types.Message) - assert result.inline_message_id == 'im1' - assert result.game_short_name == 'game' - assert isinstance(result, types.CallbackQuery) - - -def test_json_chatbackground(): - json_dict = json.loads(r'{"type": {"type": "fill", "fill": {"type": "solid", "color": 123456}, "dark_theme_dimming": 0}}') - result = types.ChatBackground.de_json(json_dict) - assert isinstance(result.type, types.BackgroundTypeFill) or isinstance(result.type, dict) - assert isinstance(result, types.ChatBackground) - assert hasattr(result, 'type') - - -def test_json_chatboostadded(): - json_dict = json.loads(r'{"boost_count": "test"}') - result = types.ChatBoostAdded.de_json(json_dict) - assert result.boost_count == 'test' - assert isinstance(result, types.ChatBoostAdded) - - -def test_json_chatboostremoved(): - json_dict = json.loads(r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "boost_id": 1, "remove_date": 1682189507, "source": {"source": "premium", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}}') - result = types.ChatBoostRemoved.de_json(json_dict) - assert isinstance(result.chat, types.Chat) - assert result.boost_id == 1 - assert result.remove_date == 1682189507 - assert isinstance(result.source, types.ChatBoostSource) - assert isinstance(result, types.ChatBoostRemoved) - - -def test_json_chatboostsource(): - # ChatBoostSource is abstract - test ChatBoostSourcePremium directly - json_dict = json.loads(r'{"source": "premium", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}') - result = types.ChatBoostSourcePremium.de_json(json_dict) - assert isinstance(result, types.ChatBoostSourcePremium) - - -def test_json_chatboostsourcegiftcode(): - json_dict = json.loads(r'{"source": "gift_code", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}') - result = types.ChatBoostSourceGiftCode.de_json(json_dict) - assert result.source == 'gift_code' - assert isinstance(result.user, types.User) - assert isinstance(result, types.ChatBoostSourceGiftCode) - - -def test_json_chatboostsourcegiveaway(): - json_dict = json.loads(r'{"source": "giveaway", "giveaway_message_id": 1, "user": {"id": 1, "is_bot": false, "first_name": "Test"}, "is_unclaimed": false, "prize_star_count": 100}') - result = types.ChatBoostSourceGiveaway.de_json(json_dict) - assert result.source == 'giveaway' - assert result.giveaway_message_id == 1 - assert isinstance(result.user, types.User) - assert result.is_unclaimed == False - assert result.prize_star_count == 100 - assert isinstance(result, types.ChatBoostSourceGiveaway) - - -def test_json_chatboostsourcepremium(): - json_dict = json.loads(r'{"source": "premium", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}') - result = types.ChatBoostSourcePremium.de_json(json_dict) - assert result.source == 'premium' - assert isinstance(result.user, types.User) - assert isinstance(result, types.ChatBoostSourcePremium) - - -def test_json_chatboostupdated(): - json_dict = json.loads(r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "boost": {"boost_item_id": "b1", "add_date": 1682189507, "expiration_date": 1682275907}}') - result = types.ChatBoostUpdated.de_json(json_dict) - assert isinstance(result.chat, types.Chat) - assert isinstance(result.boost, types.ChatBoost) - assert isinstance(result.boost.boost_id, str) or result.boost.boost_id is None - assert isinstance(result.boost.add_date, int) - assert isinstance(result.boost.expiration_date, int) - assert isinstance(result, types.ChatBoostUpdated) - - -def test_json_chatjoinrequest(): - json_dict = json.loads(r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "user_chat_id": 1, "date": 1682189507, "bio": "Hello", "invite_link": {"invite_link": "https://t.me/joinchat/ABC", "creator": {"id": 1, "is_bot": false, "first_name": "Test"}, "is_primary": true, "is_revoked": false, "creates_join_request": false}, "query_id": "query123"}') - result = types.ChatJoinRequest.de_json(json_dict) - assert isinstance(result.chat, types.Chat) - assert isinstance(result.from_user, types.User) - assert result.from_user.id == 1 - assert result.from_user.first_name == 'Test' - assert result.user_chat_id == 1 - assert result.date == 1682189507 - assert result.bio == 'Hello' - assert isinstance(result.invite_link, types.ChatInviteLink) - assert result.query_id == 'query123' - assert isinstance(result, types.ChatJoinRequest) - - -def test_json_chatfullinfo(): - json_dict = json.loads(r'{"id": 1, "type": "private", "title": "Test Chat", "username": "testchat", "first_name": "John", "last_name": "Doe", "photo": {"small_file_id": "s", "small_file_unique_id": "su", "big_file_id": "b", "big_file_unique_id": "bu"}, "bio": "bio text", "has_private_forwards": true, "description": "desc", "pinned_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}}, "permissions": {"can_send_messages": true, "can_send_audios": true, "can_send_documents": true, "can_send_photos": true, "can_send_videos": true, "can_send_video_notes": true, "can_send_voice_notes": true, "can_send_polls": true, "can_send_other_messages": true, "can_add_web_page_previews": true, "can_change_info": true, "can_invite_users": true, "can_pin_messages": true, "can_manage_topics": true}, "slow_mode_delay": 30, "message_auto_delete_time": 86400, "has_protected_content": true, "sticker_set_name": "sticker_set", "can_set_sticker_set": false, "linked_chat_id": 2, "location": {"chat": {"id": 1, "type": "supergroup", "title": "Loc"}, "location": {"latitude": 50.45, "longitude": 30.52}, "address": "Main St"}, "join_to_send_messages": false, "join_by_request": true, "has_restricted_voice_and_video_messages": false, "is_forum": true, "max_reaction_count": 10, "active_usernames": ["test"], "emoji_status_custom_emoji_id": "custom_emoji", "has_hidden_members": false, "has_aggressive_anti_spam_enabled": false, "emoji_status_expiration_date": 1682275907, "available_reactions": ["emoji", "custom_emoji"], "accent_color_id": 1, "background_custom_emoji_id": "bg_emoji", "profile_accent_color_id": 2, "profile_background_custom_emoji_id": "profile_bg", "has_visible_history": true, "unrestrict_boost_count": 5, "custom_emoji_sticker_set_name": "custom_stickers", "personal_chat": {"id": 3, "type": "private", "title": "Personal"}, "birthdate": {"day": "15", "month": "6"}, "can_send_paid_media": true, "is_direct_messages": true, "parent_chat": {"id": 4, "type": "supergroup", "title": "Parent"}, "rating": {"level": "test", "rating": "test", "current_level_rating": "test"}, "paid_message_star_count": 5, "invite_link": "https://t.me/joinchat/ABC", "business_intro": {"title": "B", "description": "D"}, "business_location": {"address": "NY", "has_active_address": true}, "business_opening_hours": {"time_zone_name": "UTC", "opening_hours": [{"opening_minute": 540, "closing_minute": 1020, "day_of_week": 1, "is_recurring": true}]}, "accepted_gift_types": {"unlimited_gifts": false, "limited_gifts": false, "unique_gifts": true, "premium_subscription": false, "gifts_from_channels": false}, "first_profile_audio": {"file_id": "fa1", "file_unique_id": "fa1u", "duration": 30, "mime_type": "audio/ogg"}, "unique_gift_colors": {"model_custom_emoji_id": 1, "symbol_custom_emoji_id": 1, "light_theme_main_color": 333333, "light_theme_other_colors": [444444], "dark_theme_main_color": 555555, "dark_theme_other_colors": [666666]}, "guard_bot": {"id": 2, "is_bot": true, "first_name": "GuardBot"}, "community": {"id": 5, "name": "Community"}}') - result = types.ChatFullInfo.de_json(json_dict) - assert result.id == 1 - assert result.type == 'private' - assert result.title == 'Test Chat' - assert result.username == 'testchat' - assert result.first_name == 'John' - assert result.last_name == 'Doe' - assert isinstance(result.photo, types.ChatPhoto) - assert result.bio == 'bio text' - assert result.has_private_forwards == True - assert result.description == 'desc' - assert result.invite_link == "https://t.me/joinchat/ABC" - assert isinstance(result.pinned_message, types.Message) - assert isinstance(result.permissions, types.ChatPermissions) - assert result.slow_mode_delay == 30 - assert result.message_auto_delete_time == 86400 - assert result.has_protected_content == True - assert result.sticker_set_name == 'sticker_set' - assert result.can_set_sticker_set == False - assert result.linked_chat_id == 2 - assert isinstance(result.location, types.ChatLocation) - assert result.join_to_send_messages == False - assert result.join_by_request == True - assert result.has_restricted_voice_and_video_messages == False - assert result.is_forum == True - assert result.max_reaction_count == 10 - assert result.active_usernames == ['test'] - assert result.emoji_status_custom_emoji_id == 'custom_emoji' - assert result.has_hidden_members == False - assert result.has_aggressive_anti_spam_enabled == False - assert result.emoji_status_expiration_date == 1682275907 - assert isinstance(result.available_reactions, list) - assert result.accent_color_id == 1 - assert result.background_custom_emoji_id == 'bg_emoji' - assert result.profile_accent_color_id == 2 - assert result.profile_background_custom_emoji_id == 'profile_bg' - assert result.has_visible_history == True - assert result.unrestrict_boost_count == 5 - assert result.custom_emoji_sticker_set_name == 'custom_stickers' - assert isinstance(result.business_intro, types.BusinessIntro) - assert isinstance(result.business_location, types.BusinessLocation) - assert isinstance(result.business_opening_hours, types.BusinessOpeningHours) - assert isinstance(result.personal_chat, types.Chat) - assert isinstance(result.birthdate, types.Birthdate) - assert result.can_send_paid_media == True - assert isinstance(result.accepted_gift_types, types.AcceptedGiftTypes) - assert result.is_direct_messages == True - assert isinstance(result.parent_chat, types.Chat) - assert isinstance(result.rating, types.UserRating) - assert result.paid_message_star_count == 5 - assert isinstance(result.unique_gift_colors, types.UniqueGiftColors) - assert isinstance(result.first_profile_audio, types.Audio) - assert isinstance(result.guard_bot, types.User) - assert isinstance(result.community, types.Community) - assert isinstance(result, types.ChatFullInfo) - - -def test_json_chatmember(): - # ChatMember is abstract - test ChatMemberMember directly - json_dict = json.loads(r'{"status": "member", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}') - result = types.ChatMemberMember.de_json(json_dict) - assert isinstance(result.user, types.User) - assert result.status == 'member' - assert isinstance(result, types.ChatMemberMember) - - -def test_json_chatmemberupdated(): - json_dict = json.loads(r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "date": 1682189507, "old_chat_member": {"user": {"id": 1, "is_bot": false, "first_name": "Test"}, "status": "member"}, "new_chat_member": {"user": {"id": 1, "is_bot": false, "first_name": "Test"}, "status": "member"}, "via_join_request": true, "via_chat_folder_invite_link": true, "invite_link": {"invite_link": "https://t.me/joinchat/ABC", "creator": {"id": 1, "is_bot": false, "first_name": "Test"}, "creates_join_request": false, "is_primary": true, "is_revoked": false}}') - result = types.ChatMemberUpdated.de_json(json_dict) - assert isinstance(result.chat, types.Chat) - assert isinstance(result.from_user, types.User) - assert result.date == 1682189507 - assert isinstance(result.old_chat_member, types.ChatMember) - assert isinstance(result.new_chat_member, types.ChatMember) - assert isinstance(result.invite_link, types.ChatInviteLink) - assert result.invite_link.invite_link == 'https://t.me/joinchat/ABC' - assert isinstance(result.invite_link.creator, types.User) - assert result.invite_link.creates_join_request == False - assert result.invite_link.is_primary == True - assert result.invite_link.is_revoked == False - assert result.via_join_request == True - assert result.via_chat_folder_invite_link == True - assert isinstance(result, types.ChatMemberUpdated) - - -def test_json_chatownerchanged(): - json_dict = json.loads(r'{"new_owner": {"id": 1, "is_bot": false, "first_name": "Test"}}') - result = types.ChatOwnerChanged.de_json(json_dict) - assert isinstance(result.new_owner, types.User) - assert isinstance(result, types.ChatOwnerChanged) - - -def test_json_chatphoto(): - json_dict = json.loads(r'{"small_file_id": 1, "small_file_unique_id": 1, "big_file_id": 1, "big_file_unique_id": 1}') - result = types.ChatPhoto.de_json(json_dict) - assert result.small_file_id == 1 - assert result.small_file_unique_id == 1 - assert result.big_file_id == 1 - assert result.big_file_unique_id == 1 - assert isinstance(result, types.ChatPhoto) - - -def test_json_checklist(): - json_dict = json.loads(r'{"title": "test", "tasks": [{"id": 1, "text": "test", "is_checked": false}], "others_can_add_tasks": true, "others_can_mark_tasks_as_done": true, "title_entities": [{"type": "bold", "offset": 0, "length": 4}]}') - result = types.Checklist.de_json(json_dict) - assert result.title == 'test' - assert isinstance(result.tasks, list) - assert isinstance(result.title_entities, list) - assert result.others_can_add_tasks == True - assert result.others_can_mark_tasks_as_done == True - assert isinstance(result, types.Checklist) - - -def test_json_checklisttask(): - json_dict = json.loads(r'{"id": 1, "text": {"type": "bold", "text": "Task text"}, "text_entities": [{"type": "bold", "offset": 0, "length": 9}], "completed_by_user": {"id": 1, "is_bot": false, "first_name": "User"}, "completed_by_chat": {"id": 1, "type": "private"}, "completion_date": 1682189507}') - result = types.ChecklistTask.de_json(json_dict) - assert result.id == 1 - assert result.text == {"type": "bold", "text": "Task text"} - assert isinstance(result.text_entities, list) - assert isinstance(result.completed_by_user, types.User) - assert isinstance(result.completed_by_chat, types.Chat) - assert result.completion_date == 1682189507 - assert isinstance(result, types.ChecklistTask) - - -def test_json_checklisttasksadded(): - json_dict = json.loads(r'{"tasks": [{"id": "t1", "text": "task"}], "checklist_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "checklist"}}') - result = types.ChecklistTasksAdded.de_json(json_dict) - assert isinstance(result.tasks, list) - assert isinstance(result.checklist_message, types.Message) - assert isinstance(result, types.ChecklistTasksAdded) - - -def test_json_choseninlineresult(): - json_dict = json.loads(r'{"result_id": "res1", "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "query": "test", "location": {"latitude": 50.45, "longitude": 30.52, "horizontal_accuracy": 1.5, "live_period": 3600}, "inline_message_id": "im1"}') - result = types.ChosenInlineResult.de_json(json_dict) - assert result.result_id == 'res1' - assert isinstance(result.from_user, types.User) - assert result.query == 'test' - assert isinstance(result.location, types.Location) - assert result.inline_message_id == 'im1' - assert isinstance(result, types.ChosenInlineResult) - - -def test_json_community(): - json_dict = json.loads(r'{"id": 1, "name": "test"}') - result = types.Community.de_json(json_dict) - assert result.id == 1 - assert result.name == 'test' - assert isinstance(result, types.Community) - - -def test_json_directmessagepricechanged(): - json_dict = json.loads(r'{"are_direct_messages_enabled": true, "direct_message_star_count": 5}') - result = types.DirectMessagePriceChanged.de_json(json_dict) - assert result.are_direct_messages_enabled == True - assert result.direct_message_star_count == 5 - assert isinstance(result, types.DirectMessagePriceChanged) - - -def test_json_directmessagestopic(): - json_dict = json.loads(r'{"topic_id": 1, "user": {"id": 1, "is_bot": false, "first_name": "Test"}}') - result = types.DirectMessagesTopic.de_json(json_dict) - assert result.topic_id == 1 - assert isinstance(result.user, types.User) - assert result.user.id == 1 - assert result.user.first_name == 'Test' - assert isinstance(result, types.DirectMessagesTopic) - - -def test_json_externalreplyinfo(): - json_dict = json.loads(r'{"origin": {"type": "user", "date": 1682189507, "sender_user": {"id": 1, "is_bot": false, "first_name": "Test"}}, "chat": {"id": 1, "type": "private"}, "message_id": 42, "link_preview_options": {"url": "https://example.com", "shows_above_caption": true, "enhanced_smileys": true, "prefer_large_media": true}, "animation": {"file_id": "anim", "file_unique_id": "aniu", "width": 100, "height": 100, "duration": 10}, "audio": {"file_id": "au1", "file_unique_id": "au1u", "duration": 30}, "document": {"file_id": "doc1", "file_unique_id": "doc1u", "file_name": "test.pdf"}, "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}], "sticker": {"file_id": "st1", "file_unique_id": "st1u", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "story": {"chat": {"id": 1, "type": "private"}, "id": 1}, "video": {"file_id": "v1", "file_unique_id": "v1u", "width": 640, "height": 480, "duration": 30}, "video_note": {"file_id": "vn1", "file_unique_id": "vn1u", "duration": 10, "length": 512}, "voice": {"file_id": "vo1", "file_unique_id": "vo1u", "duration": 10}, "has_media_spoiler": true, "contact": {"phone_number": "+123", "first_name": "John"}, "dice": {"emoji": "🎲", "value": 5}, "game": {"id": "g1", "title": "Game", "description": "Test", "text": "Play", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}, "giveaway": {"chats": [{"id": 1, "type": "private"}], "winners_selection_date": 1682189507, "winner_count": 1, "only_new_members": false, "has_public_winners": false, "prize_description": "Prize", "premium_subscription_month_count": 0, "prize_star_count": 0}, "giveaway_winners": {"chat": {"id": 1, "type": "private"}, "giveaway_message_id": 1, "winners_selection_date": 1682189507, "winner_count": 1, "winners": [{"id": 1, "is_bot": false, "first_name": "Test"}], "additional_chat_count": 0, "premium_subscription_month_count": 0, "unclaimed_prize_count": 0, "only_new_members": false, "was_refunded": false, "prize_description": "", "prize_star_count": 0}, "invoice": {"title": "Test", "description": "Desc", "start_parameter": "sp", "currency": "USD", "total_amount": 100, "invoice_payload": "payload", "shipping_option_id": "opt", "order_info": {"user_name": "User", "user_phone": "+123", "shipping_address": {"country_code": "US", "state": "CA", "city": "SJ", "street_line1": "123", "street_line2": "", "post_code": "95113"}}, "telegram_payment_charge_id": "chg1", "provider_payment_charge_id": "chg2"}, "location": {"latitude": 50.45, "longitude": 30.52}, "poll": {"id": "p1", "question": "test question", "options": [{"text": "Opt1", "persistent_id": "opt1"}], "type": "quiz"}, "venue": {"location": {"latitude": 50.45, "longitude": 30.52}, "title": "Place", "address": "Addr"}, "paid_media": {"star_count": 10, "paid_media": [{"type": "photo", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}]}, "live_photo": {"file_id": "lp1", "file_unique_id": "lp1u", "width": 100, "height": 100, "duration": 5}, "checklist": {"title": "Check", "tasks": [{"id": "t1", "text": "Task1", "status": "pending"}]}}') - result = types.ExternalReplyInfo.de_json(json_dict) - assert isinstance(result.origin, types.MessageOrigin) - assert isinstance(result.chat, types.Chat) - assert result.message_id == 42 - assert isinstance(result.link_preview_options, types.LinkPreviewOptions) - assert isinstance(result.animation, types.Animation) - assert isinstance(result.audio, types.Audio) - assert isinstance(result.document, types.Document) - assert isinstance(result.photo, list) - assert isinstance(result.sticker, types.Sticker) - assert isinstance(result.story, types.Story) - assert isinstance(result.video, types.Video) - assert isinstance(result.video_note, types.VideoNote) - assert isinstance(result.voice, types.Voice) - assert result.has_media_spoiler == True - assert isinstance(result.contact, types.Contact) - assert isinstance(result.dice, types.Dice) - assert isinstance(result.game, types.Game) - assert isinstance(result.giveaway, types.Giveaway) - assert isinstance(result.giveaway.chats, list) - assert result.giveaway.winner_count == 1 - assert isinstance(result.giveaway_winners, types.GiveawayWinners) - assert isinstance(result.invoice, types.Invoice) - assert isinstance(result.location, types.Location) - assert isinstance(result.poll, types.Poll) - assert result.poll.id == 'p1' - assert result.poll.question == 'test question' - assert isinstance(result.poll.options, list) - assert result.poll.type == 'quiz' - assert isinstance(result.venue, types.Venue) - assert isinstance(result.paid_media, types.PaidMediaInfo) - assert isinstance(result.live_photo, types.LivePhoto) - assert isinstance(result.checklist, types.Checklist) - assert isinstance(result, types.ExternalReplyInfo) - - -def test_json_file(): - json_dict = json.loads(r'{"file_id": "test_file_id", "file_unique_id": "test_unique_id", "file_size": 1024, "file_path": "docs/test.pdf"}') - result = types.File.de_json(json_dict) - assert result.file_id == 'test_file_id' - assert result.file_unique_id == 'test_unique_id' - assert result.file_size == 1024 - assert result.file_path == 'docs/test.pdf' - assert isinstance(result, types.File) - - -def test_json_forumtopiccreated(): - json_dict = json.loads(r'{"name": "test", "icon_color": 4294967295, "icon_custom_emoji_id": "custom_emoji", "is_name_implicit": true}') - result = types.ForumTopicCreated.de_json(json_dict) - assert result.name == 'test' - assert result.icon_color == 4294967295 - assert result.icon_custom_emoji_id == 'custom_emoji' - assert result.is_name_implicit == True - assert isinstance(result, types.ForumTopicCreated) - - -def test_json_game(): - json_dict = json.loads(r'{"id": "1", "title": "test", "description": "test", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}], "text": "game text", "animation": {"file_id": "anim", "file_unique_id": "aniu", "width": 100, "height": 100, "duration": 10}, "text_entities": [{"type": "bold", "offset": 0, "length": 4}]}') - result = types.Game.de_json(json_dict) - assert result.title == 'test' - assert result.description == 'test' - assert isinstance(result.photo, list) - assert result.text == 'game text' - assert isinstance(result.text_entities, list) - assert isinstance(result.animation, types.Animation) - assert isinstance(result, types.Game) - - -def test_json_gamehighscore(): - json_dict = json.loads(r'{"position": 0, "user": {"id": 1, "is_bot": false, "first_name": "Test"}, "score": 1}') - result = types.GameHighScore.de_json(json_dict) - assert result.position == 0 - assert isinstance(result.user, types.User) - assert result.score == 1 - assert isinstance(result, types.GameHighScore) - - -def test_json_giveaway(): - json_dict = json.loads(r'{"chats": [{"id": 1, "type": "private", "title": "Test"}], "winners_selection_date": 1682189507, "winner_count": 1, "only_new_members": true, "has_public_winners": false, "prize_description": "Prize", "country_codes": ["US", "GB"], "premium_subscription_month_count": 3, "prize_star_count": 100}') - result = types.Giveaway.de_json(json_dict) - assert isinstance(result.chats, list) - assert result.winners_selection_date == 1682189507 - assert result.winner_count == 1 - assert result.only_new_members == True - assert result.has_public_winners == False - assert result.prize_description == 'Prize' - assert isinstance(result.country_codes, list) - assert result.premium_subscription_month_count == 3 - assert result.prize_star_count == 100 - assert isinstance(result, types.Giveaway) - - -def test_json_giveawaycompleted(): - json_dict = json.loads(r'{"winner_count": 1, "unclaimed_prize_count": 5, "giveaway_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "giveaway"}, "is_star_giveaway": true}') - result = types.GiveawayCompleted.de_json(json_dict) - assert result.winner_count == 1 - assert result.unclaimed_prize_count == 5 - assert isinstance(result.giveaway_message, types.Message) - assert result.is_star_giveaway == True - assert isinstance(result, types.GiveawayCompleted) - - -def test_json_giveawaywinners(): - json_dict = json.loads(r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "giveaway_message_id": 1, "winners_selection_date": 1682189507, "winner_count": 1, "winners": [{"id": 1, "is_bot": false, "first_name": "Test"}], "additional_chat_count": 5, "premium_subscription_month_count": 3, "unclaimed_prize_count": 10, "only_new_members": true, "was_refunded": false, "prize_description": "Prize desc", "prize_star_count": 100}') - result = types.GiveawayWinners.de_json(json_dict) - assert isinstance(result.chat, types.Chat) - assert result.giveaway_message_id == 1 - assert result.winners_selection_date == 1682189507 - assert result.winner_count == 1 - assert isinstance(result.winners, list) - assert result.additional_chat_count == 5 - assert result.premium_subscription_month_count == 3 - assert result.unclaimed_prize_count == 10 - assert result.only_new_members == True - assert result.was_refunded == False - assert result.prize_description == 'Prize desc' - assert result.prize_star_count == 100 - assert isinstance(result, types.GiveawayWinners) - - -def test_json_groupchat(): - json_dict = json.loads(r'{"id": 1, "title": "test"}') - result = types.GroupChat.de_json(json_dict) - assert result.id == 1 - assert result.title == 'test' - assert isinstance(result, types.GroupChat) - - -def test_json_inaccessiblemessage(): - json_dict = json.loads(r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "message_id": 1, "date": 1682189507}') - result = types.InaccessibleMessage.de_json(json_dict) - assert isinstance(result.chat, types.Chat) - assert result.message_id == 1 - assert result.date == 1682189507 - assert isinstance(result, types.InaccessibleMessage) - - -def test_json_inlinequery(): - json_dict = json.loads(r'{"id": "iq1", "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "query": "test", "offset": "off1", "chat_type": "private", "location": {"latitude": 50.45, "longitude": 30.52, "horizontal_accuracy": 1.5, "live_period": 3600}}') - result = types.InlineQuery.de_json(json_dict) - assert result.id == 'iq1' - assert isinstance(result.from_user, types.User) - assert result.query == 'test' - assert result.offset == 'off1' - assert result.chat_type == 'private' - assert isinstance(result.location, types.Location) - assert isinstance(result, types.InlineQuery) - - -def test_json_invoice(): - json_dict = json.loads(r'{"title": "test", "description": "test", "start_parameter": "test_sp", "currency": "test", "total_amount": 1}') - result = types.Invoice.de_json(json_dict) - assert result.title == 'test' - assert result.description == 'test' - assert result.start_parameter == 'test_sp' - assert result.currency == 'test' - assert result.total_amount == 1 - assert isinstance(result, types.Invoice) - - -def test_json_jsondeserializable(): - # JsonDeserializable is abstract base class, skip - pass - - -def test_json_link(): - json_dict = json.loads(r'{"url": "https://example.com"}') - result = types.Link.de_json(json_dict) - assert result.url == 'https://example.com' - assert isinstance(result, types.Link) - - -def test_json_livephoto(): - json_dict = json.loads(r'{"file_id": "test_file_id", "file_unique_id": "test_unique_id", "width": 100, "height": 100, "duration": 30, "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}], "mime_type": "image/jpeg", "file_size": 20480}') - result = types.LivePhoto.de_json(json_dict) - assert result.file_id == 'test_file_id' - assert result.file_unique_id == 'test_unique_id' - assert result.width == 100 - assert result.height == 100 - assert result.duration == 30 - assert isinstance(result.photo, list) - assert result.mime_type == 'image/jpeg' - assert result.file_size == 20480 - assert isinstance(result, types.LivePhoto) - - -def test_json_managedbotcreated(): - json_dict = json.loads(r'{"bot": {"id": 1, "is_bot": true, "first_name": "Bot"}}') - result = types.ManagedBotCreated.de_json(json_dict) - assert isinstance(result, types.ManagedBotCreated) - assert hasattr(result, 'bot') - - -def test_json_managedbotupdated(): - json_dict = json.loads(r'{"user": {"id": 1, "is_bot": false, "first_name": "Test"}, "bot": {"id": 2, "is_bot": true, "first_name": "Bot"}}') - result = types.ManagedBotUpdated.de_json(json_dict) - assert isinstance(result.user, types.User) - assert result.user.id == 1 - assert isinstance(result.bot, types.User) - assert result.bot.id == 2 - assert isinstance(result, types.ManagedBotUpdated) - - -def test_json_menubutton(): - # MenuButton dispatches on type - test concrete subclass - json_dict = json.loads(r'{"type": "default"}') - result = types.MenuButtonDefault.de_json(json_dict) - assert isinstance(result, types.MenuButtonDefault) - - -def test_json_messageautodeletetimerchanged(): - json_dict = json.loads(r'{"message_auto_delete_time": 60}') - result = types.MessageAutoDeleteTimerChanged.de_json(json_dict) - assert result.message_auto_delete_time == 60 - assert isinstance(result, types.MessageAutoDeleteTimerChanged) - - -def test_json_messageid(): - json_dict = json.loads(r'{"message_id": 1}') - result = types.MessageID.de_json(json_dict) - assert isinstance(result, types.MessageID) - - -def test_json_messageorigin(): - # MessageOrigin is abstract - test MessageOriginUser directly - json_dict = json.loads(r'{"type": "user", "date": 1682189507, "sender_user": {"id": 1, "is_bot": false, "first_name": "Test"}}') - result = types.MessageOriginUser.de_json(json_dict) - assert result.type == 'user' - assert result.date == 1682189507 - assert isinstance(result.sender_user, types.User) - assert result.sender_user.id == 1 - assert result.sender_user.first_name == 'Test' - assert isinstance(result, types.MessageOriginUser) - - -def test_json_messagereactioncountupdated(): - json_dict = json.loads(r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "message_id": 1, "date": 1682189507, "reactions": [{"type": {"type": "emoji", "emoji": "\u2764\ufe0f"}, "total_count": 5}]}') - result = types.MessageReactionCountUpdated.de_json(json_dict) - assert isinstance(result.chat, types.Chat) - assert result.message_id == 1 - assert result.date == 1682189507 - assert isinstance(result.reactions, list) - assert isinstance(result, types.MessageReactionCountUpdated) - - -def test_json_messagereactionupdated(): - json_dict = json.loads(r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "message_id": 1, "date": 1682189507, "old_reaction": [{"type": "emoji", "emoji": "\u0001f600"}], "new_reaction": [{"type": "emoji", "emoji": "\u0001f600"}], "user": {"id": 1, "is_bot": false, "first_name": "Test"}, "actor_chat": {"id": -1, "type": "channel", "title": "Channel"}}') - result = types.MessageReactionUpdated.de_json(json_dict) - assert isinstance(result.chat, types.Chat) - assert result.message_id == 1 - assert result.date == 1682189507 - assert isinstance(result.old_reaction, list) - assert isinstance(result.new_reaction, list) - assert isinstance(result.user, types.User) - assert isinstance(result.actor_chat, types.Chat) - assert isinstance(result, types.MessageReactionUpdated) - - -def test_json_ownedgift(): - # OwnedGift is abstract - test OwnedGiftRegular directly - json_dict = json.loads(r'{"type": "regular", "gift": {"id": 1, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100}}') - result = types.OwnedGiftRegular.de_json(json_dict) - assert result.type == 'regular' - assert isinstance(result, types.OwnedGiftRegular) - - -def test_json_ownedgiftregular(): - json_dict = json.loads(r'{"type": "regular", "gift": {"id": 1, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100}, "owned_gift_id": "og_123", "sender_user": {"id": 1, "is_bot": false, "first_name": "Sender"}, "send_date": 1682189507, "text": {"type": "bold", "text": "Gift text"}, "entities": [{"type": "bold", "offset": 0, "length": 4}], "is_private": false, "is_saved": false, "can_be_upgraded": true, "was_refunded": false, "convert_star_count": 50, "prepaid_upgrade_star_count": 100, "is_upgrade_separate": false, "unique_gift_number": 42}') - result = types.OwnedGiftRegular.de_json(json_dict) - assert result.type == 'regular' - assert isinstance(result.gift, types.Gift) - assert result.owned_gift_id == 'og_123' - assert isinstance(result.sender_user, types.User) - assert result.send_date == 1682189507 - assert isinstance(result.text, dict) - assert isinstance(result.entities, list) - assert result.is_private == False - assert result.is_saved == False - assert result.can_be_upgraded == True - assert result.was_refunded == False - assert result.convert_star_count == 50 - assert result.prepaid_upgrade_star_count == 100 - assert result.is_upgrade_separate == False - assert result.unique_gift_number == 42 - assert isinstance(result, types.OwnedGiftRegular) - - -def test_json_ownedgiftunique(): - json_dict = json.loads(r'{"type": "unique", "gift": {"base_name": "test", "name": "test", "number": 1, "model": {"name": "m", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "symbol": {"name": "s", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "backdrop": {"name": "b", "colors": {"center_color": 123456, "edge_color": 654321, "symbol_color": 111111, "text_color": 222222}, "rarity_per_mille": 1000}, "gift_id": 1}, "gift_id": 1, "owned_gift_id": "og_456", "sender_user": {"id": 2, "is_bot": false, "first_name": "Sender"}, "send_date": 1682189507, "is_saved": false, "can_be_transferred": true, "transfer_star_count": 50, "next_transfer_date": 1704067200}') - result = types.OwnedGiftUnique.de_json(json_dict) - assert result.type == 'unique' - assert isinstance(result.gift, types.UniqueGift) - assert result.owned_gift_id == 'og_456' - assert isinstance(result.sender_user, types.User) - assert result.send_date == 1682189507 - assert result.is_saved == False - assert result.can_be_transferred == True - assert result.transfer_star_count == 50 - assert result.next_transfer_date == 1704067200 - assert isinstance(result, types.OwnedGiftUnique) - - -def test_json_ownedgifts(): - json_dict = json.loads(r'{"total_count": 1, "gifts": [{"type": "regular", "gift": {"id": 1, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100}}], "next_offset": "offset123"}') - result = types.OwnedGifts.de_json(json_dict) - assert result.total_count == 1 - assert isinstance(result.gifts, list) - assert result.next_offset == 'offset123' - assert isinstance(result, types.OwnedGifts) - - -def test_json_paidmedia(): - # PaidMedia is abstract - test PaidMediaPhoto directly - json_dict = json.loads(r'{"type": "photo", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}') - result = types.PaidMediaPhoto.de_json(json_dict) - assert isinstance(result, types.PaidMediaPhoto) - - -def test_json_paidmediainfo(): - json_dict = json.loads(r'{"star_count": 100, "paid_media": [{"type": "photo", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}]}') - result = types.PaidMediaInfo.de_json(json_dict) - assert result.star_count == 100 - assert isinstance(result.paid_media, list) - assert isinstance(result, types.PaidMediaInfo) - - -def test_json_paidmedialivephoto(): - json_dict = json.loads(r'{"type": "live_photo", "live_photo": {"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100, "duration": 10}}') - result = types.PaidMediaLivePhoto.de_json(json_dict) - assert result.type == 'live_photo' - assert isinstance(result.live_photo, types.LivePhoto) - assert isinstance(result, types.PaidMediaLivePhoto) - - -def test_json_paidmediaphoto(): - json_dict = json.loads(r'{"type": "photo", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}') - result = types.PaidMediaPhoto.de_json(json_dict) - assert result.type == 'photo' - assert isinstance(result.photo, list) - assert isinstance(result, types.PaidMediaPhoto) - - -def test_json_paidmediapreview(): - json_dict = json.loads(r'{"type": "default", "width": 640, "height": 480, "duration": 30}') - result = types.PaidMediaPreview.de_json(json_dict) - assert result.type == 'default' - assert result.width == 640 - assert result.height == 480 - assert result.duration == 30 - assert isinstance(result, types.PaidMediaPreview) - - -def test_json_paidmediapurchased(): - json_dict = json.loads(r'{"from_user": {"id": 1, "is_bot": false, "first_name": "Test"}, "paid_media_payload": "test"}') - result = types.PaidMediaPurchased.de_json(json_dict) - assert isinstance(result.from_user, types.User) - assert result.paid_media_payload == 'test' - assert isinstance(result, types.PaidMediaPurchased) - - -def test_json_paidmediavideo(): - json_dict = json.loads(r'{"type": "video", "video": {"file_id": "v", "file_unique_id": "vu", "width": 640, "height": 480, "duration": 30}}') - result = types.PaidMediaVideo.de_json(json_dict) - assert result.type == 'video' - assert isinstance(result.video, types.Video) - assert isinstance(result, types.PaidMediaVideo) - - -def test_json_paidmessagepricechanged(): - json_dict = json.loads(r'{"paid_message_star_count": 1}') - result = types.PaidMessagePriceChanged.de_json(json_dict) - assert isinstance(result, types.PaidMessagePriceChanged) - assert hasattr(result, 'paid_message_star_count') - - -def test_json_poll(): - # Poll.poll_type is deprecated in Telegram API, not covered - json_dict = json.loads(r'{"id": "poll1", "question": "test question", "options": [{"text": "Opt1", "persistent_id": "opt1"}], "total_voter_count": 10, "is_closed": false, "is_anonymous": true, "type": "quiz", "allows_multiple_answers": false, "explanation": "explanation text", "explanation_entities": [{"type": "bold", "offset": 0, "length": 4}], "open_period": 3600, "close_date": 1682193107, "question_entities": [{"type": "bold", "offset": 0, "length": 5}], "correct_option_ids": [0], "allows_revoting": true, "description": "poll desc", "description_entities": [{"type": "italic", "offset": 0, "length": 9}], "members_only": true, "country_codes": ["US", "GB"], "explanation_media": {"file_id": "em1", "file_unique_id": "emu1", "mime_type": "image/jpeg", "file_name": "media.jpg"}}') - result = types.Poll.de_json(json_dict) - # __init__ param is "poll_id" but de_json sets "id" attribute (from JSON "id" key) - # Use Poll.id, NOT Poll.poll_id - assert result.id == "poll1" - assert result.question == "test question" - assert isinstance(result.options, list) - assert result.total_voter_count == 10 - assert result.is_closed == False - assert result.is_anonymous == True - assert result.type == "quiz" - assert result.allows_multiple_answers == False - assert result.explanation == "explanation text" - assert isinstance(result.explanation_entities, list) - assert result.open_period == 3600 - assert result.close_date == 1682193107 - assert isinstance(result.question_entities, list) - assert isinstance(result.correct_option_ids, list) - assert result.allows_revoting == True - assert result.description == "poll desc" - assert isinstance(result.description_entities, list) - assert result.media is None - assert result.members_only == True - assert isinstance(result.country_codes, list) - assert isinstance(result.explanation_media, types.PollMedia) - assert isinstance(result, types.Poll) - - -def test_json_polloption(): - json_dict = json.loads(r'{"text": "test", "persistent_id": 1, "voter_count": 5, "text_entities": [{"type": "bold", "offset": 0, "length": 4}], "added_by_user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "added_by_chat": {"id": -1, "type": "channel", "title": "Channel"}, "addition_date": 1682189507}') - result = types.PollOption.de_json(json_dict) - assert result.text == 'test' - assert result.persistent_id == 1 - assert result.voter_count == 5 - assert isinstance(result.text_entities, list) - assert isinstance(result.added_by_user, types.User) - assert result.added_by_user.id == 12345 - assert isinstance(result.added_by_chat, types.Chat) - assert result.addition_date == 1682189507 - assert result.media is None - assert isinstance(result, types.PollOption) - - -def test_json_polloptionadded(): - json_dict = json.loads(r'{"option_persistent_id": 1, "option_text": "test", "poll_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "poll"}, "option_text_entities": [{"type": "bold", "offset": 0, "length": 4}]}') - result = types.PollOptionAdded.de_json(json_dict) - assert result.option_persistent_id == 1 - assert result.option_text == 'test' - assert isinstance(result.poll_message, types.Message) - assert isinstance(result.option_text_entities, list) - assert isinstance(result, types.PollOptionAdded) - - -def test_json_polloptiondeleted(): - json_dict = json.loads(r'{"option_persistent_id": 1, "option_text": "test", "poll_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "poll"}, "option_text_entities": [{"type": "bold", "offset": 0, "length": 4}]}') - result = types.PollOptionDeleted.de_json(json_dict) - assert result.option_persistent_id == 1 - assert result.option_text == 'test' - assert isinstance(result.poll_message, types.Message) - assert isinstance(result.option_text_entities, list) - assert isinstance(result, types.PollOptionDeleted) - - -def test_json_precheckoutquery(): - json_dict = json.loads(r'{"id": 1, "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "currency": "USD", "total_amount": 1234, "invoice_payload": "test_payload", "shipping_option_id": "opt1", "order_info": {"user_name": "Buyer", "user_phone": "+123", "shipping_address": {"country_code": "US", "state": "CA", "city": "San Jose", "street_line1": "123 Main St", "street_line2": "", "post_code": "95113"}}}') - result = types.PreCheckoutQuery.de_json(json_dict) - assert result.id == 1 - assert isinstance(result.from_user, types.User) - assert result.currency == 'USD' - assert result.total_amount == 1234 - assert result.invoice_payload == 'test_payload' - assert result.shipping_option_id == 'opt1' - assert isinstance(result.order_info, types.OrderInfo) - assert isinstance(result, types.PreCheckoutQuery) - - -def test_json_preparedinlinemessage(): - json_dict = json.loads(r'{"id": "prep1", "expiration_date": 1682189507}') - result = types.PreparedInlineMessage.de_json(json_dict) - assert result.id == 'prep1' - assert result.expiration_date == 1682189507 - assert isinstance(result, types.PreparedInlineMessage) - - -def test_json_preparedkeyboardbutton(): - json_dict = json.loads(r'{"id": 1}') - result = types.PreparedKeyboardButton.de_json(json_dict) - assert result.id == 1 - assert isinstance(result, types.PreparedKeyboardButton) - - -def test_json_proximityalerttriggered(): - json_dict = json.loads(r'{"traveler": {"id": 1, "is_bot": false, "first_name": "Test"}, "watcher": {"id": 1, "is_bot": false, "first_name": "Test"}, "distance": "test"}') - result = types.ProximityAlertTriggered.de_json(json_dict) - assert isinstance(result.traveler, dict) - assert isinstance(result.watcher, dict) - assert result.distance == 'test' - assert isinstance(result, types.ProximityAlertTriggered) - - -def test_json_refundedpayment(): - json_dict = json.loads(r'{"currency": "USD", "total_amount": 100, "invoice_payload": "test_payload", "telegram_payment_charge_id": "chg1", "provider_payment_charge_id": "chg2"}') - result = types.RefundedPayment.de_json(json_dict) - assert result.currency == 'USD' - assert result.total_amount == 100 - assert result.invoice_payload == 'test_payload' - assert result.telegram_payment_charge_id == 'chg1' - assert result.provider_payment_charge_id == 'chg2' - assert isinstance(result, types.RefundedPayment) - - -def test_json_revenuewithdrawalstate(): - # RevenueWithdrawalState is abstract - test RevenueWithdrawalStatePending directly - json_dict = json.loads(r'{"type": "pending"}') - result = types.RevenueWithdrawalStatePending.de_json(json_dict) - assert isinstance(result, types.RevenueWithdrawalStatePending) - - -def test_json_revenuewithdrawalstatefailed(): - json_dict = json.loads(r'{"type": "failed"}') - result = types.RevenueWithdrawalStateFailed.de_json(json_dict) - assert result.type == 'failed' - assert isinstance(result, types.RevenueWithdrawalStateFailed) - - -def test_json_revenuewithdrawalstatepending(): - json_dict = json.loads(r'{"type": "pending"}') - result = types.RevenueWithdrawalStatePending.de_json(json_dict) - assert result.type == 'pending' - assert isinstance(result, types.RevenueWithdrawalStatePending) - - -def test_json_revenuewithdrawalstatesucceeded(): - json_dict = json.loads(r'{"type": "succeeded", "date": 1682189507, "url": "https://example.com"}') - result = types.RevenueWithdrawalStateSucceeded.de_json(json_dict) - assert result.type == 'succeeded' - assert result.date == 1682189507 - assert result.url == 'https://example.com' - assert isinstance(result, types.RevenueWithdrawalStateSucceeded) - - -def test_json_richblockanchor(): - json_dict = json.loads(r'{"name": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockAnchor.de_json(data) - assert result.name == 'test' - assert isinstance(result, types.RichBlockAnchor) - - -def test_json_richblockaudio(): - json_dict = json.loads(r'{"audio": {"file_id": "a", "file_unique_id": "au", "duration": 30}, "caption": {"type": "bold", "text": "audio caption"}}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockAudio.de_json(data) - assert isinstance(result.audio, types.Audio) - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockAudio) - - -def test_json_richblockblockquotation(): - json_dict = json.loads(r'{"blocks": [{"text": "Test"}], "credit": "Credit text"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockBlockQuotation.de_json(data) - assert isinstance(result.blocks, list) - assert result.credit == 'Credit text' - assert isinstance(result, types.RichBlockBlockQuotation) - - -def test_json_richblockcollage(): - json_dict = json.loads(r'{"blocks": [{"text": "Test"}], "caption": {"type": "bold", "text": "Caption"}}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockCollage.de_json(data) - assert isinstance(result.blocks, list) - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockCollage) - - -def test_json_richblocklist(): - json_dict = json.loads(r'{"items": [{"type": "list_item", "label": {"text": "label"}, "blocks": [{"text": "Test"}]}]}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockList.de_json(data) - assert isinstance(result.items, list) - assert isinstance(result, types.RichBlockList) - assert hasattr(result, 'items') - - -def test_json_richblockmap(): - json_dict = json.loads(r'{"location": {"latitude": 50.0, "longitude": 30.0}, "zoom": 1.0, "width": 100, "height": 100, "caption": {"type": "bold", "text": "Map caption"}}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichBlockMap.de_json(data) - assert isinstance(result.location, types.Location) - assert result.zoom == 1.0 - assert result.width == 100 - assert result.height == 100 - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockMap) - - -def test_json_richblockmathematicalexpression(): - json_dict = json.loads(r'{"expression": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockMathematicalExpression.de_json(data) - assert result.expression == 'test' - assert isinstance(result, types.RichBlockMathematicalExpression) - - -def test_json_richblockphoto(): - json_dict = json.loads(r'{"photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}], "has_spoiler": true, "caption": {"type": "bold", "text": "Photo caption"}}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichBlockPhoto.de_json(data) - assert isinstance(result.photo, list) - assert result.has_spoiler == True - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockPhoto) - - -def test_json_richblockpullquotation(): - json_dict = json.loads(r'{"text": "test quote", "credit": "Author Name"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockPullQuotation.de_json(data) - assert result.text == 'test quote' - assert result.credit == 'Author Name' - assert isinstance(result, types.RichBlockPullQuotation) - - -def test_json_richblocksectionheading(): - json_dict = json.loads(r'{"text": "test", "size": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockSectionHeading.de_json(data) - assert result.text == 'test' - assert result.size == 'test' - assert isinstance(result, types.RichBlockSectionHeading) - - -def test_json_richblockslideshow(): - json_dict = json.loads(r'{"blocks": [{"text": "Test"}], "caption": {"type": "bold", "text": "slide caption"}}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockSlideshow.de_json(data) - assert isinstance(result.blocks, list) - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockSlideshow) - assert hasattr(result, 'caption') - assert hasattr(result, 'blocks') - - -def test_json_richblocktable(): - json_dict = json.loads(r'{"cells": [[{"align": "left", "valign": "top", "text": "cell", "is_header": false, "colspan": 1, "rowspan": 1}]], "is_bordered": true, "is_striped": true, "caption": {"type": "bold", "text": "table caption"}}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockTable.de_json(data) - assert isinstance(result.cells, list) - assert result.is_bordered == True - assert result.is_striped == True - assert isinstance(result.caption, types.RichText) - assert isinstance(result, types.RichBlockTable) - assert hasattr(result, 'is_striped') - assert hasattr(result, 'is_bordered') - assert hasattr(result, 'cells') - - -def test_json_richblockthinking(): - json_dict = json.loads(r'{"text": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockThinking.de_json(data) - assert result.text == 'test' - assert isinstance(result, types.RichBlockThinking) - - -def test_json_richblockvideo(): - json_dict = json.loads(r'{"video": {"file_id": "v", "file_unique_id": "vu", "width": 640, "height": 480, "duration": 30}, "has_spoiler": true, "caption": {"type": "bold", "text": "video caption"}}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockVideo.de_json(data) - assert isinstance(result.video, types.Video) - assert result.has_spoiler == True - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockVideo) - assert hasattr(result, 'has_spoiler') - - -def test_json_richmessage(): - json_dict = json.loads(r'{"blocks": [{"type": "text", "text": "Test"}], "is_rtl": true}') - result = types.RichMessage.de_json(json_dict) - assert isinstance(result.blocks, list) - assert result.is_rtl == True - assert isinstance(result, types.RichMessage) - - -def test_json_sentguestmessage(): - json_dict = json.loads(r'{"inline_message_id": 1}') - result = types.SentGuestMessage.de_json(json_dict) - assert result.inline_message_id == 1 - assert isinstance(result, types.SentGuestMessage) - - -def test_json_shippingaddress(): - json_dict = json.loads(r'{"country_code": "US", "state": "CA", "city": "San Jose", "street_line1": "123 Main St", "street_line2": "Apt 4", "post_code": "95113"}') - result = types.ShippingAddress.de_json(json_dict) - assert result.country_code == 'US' - assert result.state == 'CA' - assert result.city == 'San Jose' - assert result.street_line1 == '123 Main St' - assert result.street_line2 == 'Apt 4' - assert result.post_code == '95113' - assert isinstance(result, types.ShippingAddress) - - -def test_json_shippingquery(): - json_dict = json.loads(r'{"id": "1", "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "invoice_payload": "test_payload", "shipping_address": {"country_code": "US", "state": "CA", "city": "Test", "street_line1": "Test St", "street_line2": "", "post_code": "12345"}}') - result = types.ShippingQuery.de_json(json_dict) - assert result.id == '1' - assert isinstance(result.from_user, types.User) - assert result.invoice_payload == 'test_payload' - assert result.shipping_address.country_code == 'US' - assert result.shipping_address.state == 'CA' - assert result.shipping_address.city == 'Test' - assert result.shipping_address.street_line1 == 'Test St' - assert result.shipping_address.street_line2 == '' - assert result.shipping_address.post_code == '12345' - assert isinstance(result, types.ShippingQuery) - - -def test_json_staramount(): - json_dict = json.loads(r'{"amount": "100", "nanostar_amount": 1000000000}') - result = types.StarAmount.de_json(json_dict) - assert result.amount == '100' - assert result.nanostar_amount == 1000000000 - assert isinstance(result, types.StarAmount) - - -def test_json_startransaction(): - json_dict = json.loads(r'{"id": 1, "amount": 100, "date": 1682189507, "source": {"type": "fragment"}, "receiver": {"type": "telegram_ads"}, "nanostar_amount": 10000000}') - result = types.StarTransaction.de_json(json_dict) - assert result.id == 1 - assert result.amount == 100 - assert result.date == 1682189507 - assert isinstance(result.source, types.TransactionPartnerFragment) - assert isinstance(result.receiver, dict) - assert result.receiver['type'] == 'telegram_ads' - assert result.nanostar_amount == 10000000 - assert isinstance(result, types.StarTransaction) - - -def test_json_startransactions(): - json_dict = json.loads(r'{"transactions": [{"id": "tx1", "amount": 100, "date": 1682189507}]}') - result = types.StarTransactions.de_json(json_dict) - assert isinstance(result, types.StarTransactions) - assert hasattr(result, 'transactions') - - -def test_json_story(): - json_dict = json.loads(r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "id": 1}') - result = types.Story.de_json(json_dict) - assert isinstance(result.chat, types.Chat) - assert result.id == 1 - assert isinstance(result, types.Story) - - -def test_json_successfulpayment(): - json_dict = json.loads(r'{"currency": "USD", "total_amount": 1234, "invoice_payload": "test_payload", "shipping_option_id": "opt1", "order_info": {"user_name": "Buyer", "user_phone": "+123", "shipping_address": {"country_code": "US", "state": "CA", "city": "San Jose", "street_line1": "123 Main St", "street_line2": "", "post_code": "95113"}}, "telegram_payment_charge_id": "chg1", "provider_payment_charge_id": "chg2", "subscription_expiration_date": 1704067200, "is_recurring": true, "is_first_recurring": true}') - result = types.SuccessfulPayment.de_json(json_dict) - assert result.currency == 'USD' - assert result.total_amount == 1234 - assert result.invoice_payload == 'test_payload' - assert result.shipping_option_id == 'opt1' - assert isinstance(result.order_info, types.OrderInfo) - assert result.telegram_payment_charge_id == 'chg1' - assert result.provider_payment_charge_id == 'chg2' - assert result.subscription_expiration_date == 1704067200 - assert result.is_recurring == True - assert result.is_first_recurring == True - assert isinstance(result, types.SuccessfulPayment) - - -def test_json_suggestedpostapprovalfailed(): - json_dict = json.loads(r'{"price": {"currency": "USD", "amount": 100}, "suggested_post_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "suggested"}}') - result = types.SuggestedPostApprovalFailed.de_json(json_dict) - assert isinstance(result.price, types.SuggestedPostPrice) - assert isinstance(result.suggested_post_message, types.Message) - assert result.suggested_post_message.message_id == 1 - assert isinstance(result, types.SuggestedPostApprovalFailed) - - -def test_json_suggestedpostapproved(): - json_dict = json.loads(r'{"send_date": 1682189507, "suggested_post_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "suggested"}, "price": {"amount": "100", "currency": "XTR"}}') - result = types.SuggestedPostApproved.de_json(json_dict) - assert result.send_date == 1682189507 - assert isinstance(result.suggested_post_message, types.Message) - assert isinstance(result.price, types.SuggestedPostPrice) - assert isinstance(result, types.SuggestedPostApproved) - - -def test_json_suggestedpostinfo(): - json_dict = json.loads(r'{"state": "default", "price": {"amount": "100", "currency": "XTR"}, "send_date": 1682189507}') - result = types.SuggestedPostInfo.de_json(json_dict) - assert result.state == 'default' - assert isinstance(result.price, types.SuggestedPostPrice) - assert result.send_date == 1682189507 - assert isinstance(result, types.SuggestedPostInfo) - - -def test_json_suggestedpostpaid(): - json_dict = json.loads(r'{"currency": "test", "suggested_post_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "suggested"}, "amount": 100, "star_amount": {"amount": 50}}') - result = types.SuggestedPostPaid.de_json(json_dict) - assert result.currency == 'test' - assert isinstance(result.suggested_post_message, types.Message) - assert result.amount == 100 - assert isinstance(result.star_amount, types.StarAmount) - assert result.star_amount.amount == 50 - assert isinstance(result, types.SuggestedPostPaid) - - -def test_json_suggestedpostrefunded(): - json_dict = json.loads(r'{"reason": "test", "suggested_post_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "suggested"}}') - result = types.SuggestedPostRefunded.de_json(json_dict) - assert result.reason == 'test' - assert isinstance(result.suggested_post_message, types.Message) - assert result.suggested_post_message.message_id == 1 - assert isinstance(result, types.SuggestedPostRefunded) - - -def test_json_textquote(): - json_dict = json.loads(r'{"text": "test", "position": 0, "entities": [{"type": "bold", "offset": 0, "length": 4}], "is_manual": true}') - result = types.TextQuote.de_json(json_dict) - assert result.text == 'test' - assert result.position == 0 - assert isinstance(result.entities, list) - assert result.is_manual == True - assert isinstance(result, types.TextQuote) - - -def test_json_transactionpartner(): - # TransactionPartner is abstract - test TransactionPartnerUser directly - json_dict = json.loads(r'{"type": "user", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}') - result = types.TransactionPartnerUser.de_json(json_dict) - assert isinstance(result, types.TransactionPartnerUser) - - -def test_json_transactionpartneraffiliateprogram(): - json_dict = json.loads(r'{"type": "affiliate_program", "commission_per_mille": 1000, "sponsor_user": {"id": 1, "is_bot": false, "first_name": "Sponsor"}}') - result = types.TransactionPartnerAffiliateProgram.de_json(json_dict) - assert result.type == 'affiliate_program' - assert result.commission_per_mille == 1000 - assert isinstance(result.sponsor_user, types.User) - assert result.sponsor_user.id == 1 - assert isinstance(result, types.TransactionPartnerAffiliateProgram) - - -def test_json_transactionpartnerchat(): - json_dict = json.loads(r'{"type": "chat", "chat": {"id": 1, "type": "private", "title": "Test"}, "gift": {"id": 123456789, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100, "total_count": 5, "remaining_count": 3, "upgrade_star_count": 50, "personal_total_count": 10, "personal_remaining_count": 2, "is_premium": true, "has_colors": true, "publisher_chat": {"id": 1, "type": "channel", "title": "Publisher"}, "unique_gift_variant_count": 3}}') - result = types.TransactionPartnerChat.de_json(json_dict) - assert result.type == 'chat' - assert isinstance(result.chat, types.Chat) - assert isinstance(result.gift, types.Gift) - assert result.gift.id == 123456789 - assert isinstance(result, types.TransactionPartnerChat) - - -def test_json_transactionpartnerfragment(): - json_dict = json.loads(r'{"type": "fragment", "withdrawal_state": {"type": "pending"}}') - result = types.TransactionPartnerFragment.de_json(json_dict) - assert result.type == 'fragment' - assert isinstance(result.withdrawal_state, types.RevenueWithdrawalState) - assert isinstance(result, types.TransactionPartnerFragment) - - -def test_json_transactionpartnerother(): - json_dict = json.loads(r'{"type": "other"}') - result = types.TransactionPartnerOther.de_json(json_dict) - assert result.type == 'other' - assert isinstance(result, types.TransactionPartnerOther) - - -def test_json_transactionpartnertelegramapi(): - json_dict = json.loads(r'{"type": "default", "request_count": 10}') - result = types.TransactionPartnerTelegramApi.de_json(json_dict) - assert result.type == 'default' - assert result.request_count == 10 - assert isinstance(result, types.TransactionPartnerTelegramApi) - - -def test_json_transactionpartneruser(): - json_dict = json.loads(r'{"type": "default", "user": {"id": 1, "is_bot": false, "first_name": "Test"}, "affiliate": {"commission_per_mille": 5500, "amount": 100, "affiliate_user": {"id": 1, "is_bot": false, "first_name": "User"}, "affiliate_chat": {"id": 1, "type": "private"}, "nanostar_amount": 1000000}, "invoice_payload": "payload", "paid_media": [{"type": "photo", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}], "subscription_period": 30, "gift": {"id": 1, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100, "total_count": 1000, "remaining_count": 999, "upgrade_star_count": 50, "personal_total_count": 5, "personal_remaining_count": 3, "is_premium": true, "has_colors": false, "publisher_chat": {"id": 1, "type": "channel", "title": "Pub"}, "unique_gift_variant_count": 10}, "premium_subscription_duration": 12, "transaction_type": "purchase"}') - result = types.TransactionPartnerUser.de_json(json_dict) - assert result.type == 'default' - assert isinstance(result.user, types.User) - assert isinstance(result.affiliate, types.AffiliateInfo) - assert result.invoice_payload == 'payload' - assert isinstance(result.paid_media, list) - assert result.subscription_period == 30 - assert isinstance(result.gift, types.Gift) - assert result.premium_subscription_duration == 12 - assert result.transaction_type == 'purchase' - assert isinstance(result, types.TransactionPartnerUser) - - -def test_json_uniquegift(): - json_dict = json.loads(r'{"base_name": "test", "name": "test", "number": 1, "model": {"name": "model_name", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "symbol": {"name": "symbol_name", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "backdrop": {"name": "backdrop_name", "colors": {"center_color": 123456, "edge_color": 654321, "symbol_color": 111111, "text_color": 222222}, "rarity_per_mille": 1000}, "gift_id": 1, "publisher_chat": {"id": -1001234567890, "type": "channel", "title": "Channel"}, "is_from_blockchain": true, "is_premium": false, "colors": {"model_custom_emoji_id": 1, "symbol_custom_emoji_id": 1, "light_theme_main_color": 333333, "light_theme_other_colors": [444444], "dark_theme_main_color": 555555, "dark_theme_other_colors": [666666]}, "is_burned": false}') - result = types.UniqueGift.de_json(json_dict) - assert result.base_name == 'test' - assert result.name == 'test' - assert result.number == 1 - assert isinstance(result.model, types.UniqueGiftModel) - assert isinstance(result.symbol, types.UniqueGiftSymbol) - assert isinstance(result.backdrop, types.UniqueGiftBackdrop) - assert result.gift_id == 1 - assert isinstance(result.publisher_chat, types.Chat) - assert result.is_from_blockchain == True - assert result.is_premium == False - assert isinstance(result.colors, types.UniqueGiftColors) - assert result.is_burned == False - assert isinstance(result, types.UniqueGift) - - -def test_json_uniquegiftbackdrop(): - json_dict = json.loads(r'{"name": "test", "colors": {"center_color": 123456, "edge_color": 654321, "symbol_color": 111111, "text_color": 222222}, "rarity_per_mille": 1000}') - result = types.UniqueGiftBackdrop.de_json(json_dict) - assert result.name == 'test' - assert isinstance(result.colors, types.UniqueGiftBackdropColors) - assert result.rarity_per_mille == 1000 - assert isinstance(result, types.UniqueGiftBackdrop) - - -def test_json_uniquegiftbackdropcolors(): - json_dict = json.loads(r'{"center_color": 123456, "edge_color": 654321, "symbol_color": 111111, "text_color": 222222}') - result = types.UniqueGiftBackdropColors.de_json(json_dict) - assert result.center_color == 123456 - assert result.edge_color == 654321 - assert result.symbol_color == 111111 - assert result.text_color == 222222 - assert isinstance(result, types.UniqueGiftBackdropColors) - - -def test_json_uniquegiftcolors(): - json_dict = json.loads(r'{"model_custom_emoji_id": 1, "symbol_custom_emoji_id": 1, "light_theme_main_color": 333333, "light_theme_other_colors": [444444], "dark_theme_main_color": 555555, "dark_theme_other_colors": [666666]}') - result = types.UniqueGiftColors.de_json(json_dict) - assert result.model_custom_emoji_id == 1 - assert result.symbol_custom_emoji_id == 1 - assert result.light_theme_main_color == 333333 - assert isinstance(result.light_theme_other_colors, list) - assert result.dark_theme_main_color == 555555 - assert isinstance(result.dark_theme_other_colors, list) - assert isinstance(result, types.UniqueGiftColors) - - -def test_json_uniquegiftinfo(): - json_dict = json.loads(r'{"gift": {"base_name": "b", "name": "n", "number": 1, "model": {"name": "m", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "symbol": {"name": "s", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "backdrop": {"name": "b", "colors": {"center_color": 123456, "edge_color": 654321, "symbol_color": 111111, "text_color": 222222}, "rarity_per_mille": 1000}, "gift_id": 1}, "origin": "test", "owned_gift_id": "og123", "transfer_star_count": 100, "next_transfer_date": 1682189507, "last_resale_currency": "USD", "last_resale_amount": 500}') - result = types.UniqueGiftInfo.de_json(json_dict) - assert isinstance(result.gift, types.UniqueGift) - assert result.origin == 'test' - assert result.owned_gift_id == 'og123' - assert result.transfer_star_count == 100 - assert result.next_transfer_date == 1682189507 - assert result.last_resale_currency == 'USD' - assert result.last_resale_amount == 500 - assert isinstance(result, types.UniqueGiftInfo) - - -def test_json_uniquegiftmodel(): - json_dict = json.loads(r'{"name": "test", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000, "rarity": "common"}') - result = types.UniqueGiftModel.de_json(json_dict) - assert result.name == 'test' - assert isinstance(result.sticker, types.Sticker) - assert result.rarity_per_mille == 1000 - assert result.rarity == 'common' - assert isinstance(result, types.UniqueGiftModel) - - -def test_json_uniquegiftsymbol(): - json_dict = json.loads(r'{"name": "test", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}') - result = types.UniqueGiftSymbol.de_json(json_dict) - assert result.name == 'test' - assert isinstance(result.sticker, types.Sticker) - assert result.rarity_per_mille == 1000 - assert isinstance(result, types.UniqueGiftSymbol) - - -# NOTE: Update is an abstract/registry class that dispatches to specific -# update types (message_update, callback_query_update, etc.). Its __init__ -# only contains 'update_id' in practice; other 'update_type' fields are -# handled by subclasses. Full field coverage is intentionally not required. -def test_json_update(): - json_dict = json.loads(r'{"update_id": 1}') - result = types.Update.de_json(json_dict) - assert result.update_id == 1 - assert isinstance(result, types.Update) - - -def test_json_userchatboosts(): - json_dict = json.loads(r'{"boosts": [{"boost_item_id": "b1", "add_date": 1682189507, "expiration_date": 1682275907}]}') - result = types.UserChatBoosts.de_json(json_dict) - assert isinstance(result.boosts, list) - assert isinstance(result, types.UserChatBoosts) - assert hasattr(result, 'boosts') - - -def test_json_userprofileaudios(): - json_dict = json.loads(r'{"total_count": 1, "audios": [{"file_id": "a1", "file_unique_id": "au1", "duration": 180, "title": "Test", "performer": "Perf", "type": "song"}]}') - result = types.UserProfileAudios.de_json(json_dict) - assert result.total_count == 1 - assert isinstance(result.audios, list) - assert isinstance(result, types.UserProfileAudios) - - -def test_json_userprofilephotos(): - json_dict = json.loads(r'{"total_count": 1, "photos": [[{"file_id": "p1", "file_unique_id": "pu1", "width": 100, "height": 100}]]}') - result = types.UserProfilePhotos.de_json(json_dict) - assert result.total_count == 1 - assert isinstance(result.photos, list) - assert isinstance(result.photos[0], list) - assert isinstance(result.photos[0][0], types.PhotoSize) - assert isinstance(result, types.UserProfilePhotos) - - -def test_json_userrating(): - json_dict = json.loads(r'{"level": "test", "rating": "test", "current_level_rating": "test", "next_level_rating": "next_test"}') - result = types.UserRating.de_json(json_dict) - assert result.level == 'test' - assert result.rating == 'test' - assert result.current_level_rating == 'test' - assert result.next_level_rating == 'next_test' - assert isinstance(result, types.UserRating) - - -def test_json_videochatended(): - json_dict = json.loads(r'{"duration": 30}') - result = types.VideoChatEnded.de_json(json_dict) - assert result.duration == 30 - assert isinstance(result, types.VideoChatEnded) - - -def test_json_videochatscheduled(): - json_dict = json.loads(r'{"start_date": 1682189507}') - result = types.VideoChatScheduled.de_json(json_dict) - assert result.start_date == 1682189507 - assert isinstance(result, types.VideoChatScheduled) - - -def test_json_videonote(): - json_dict = json.loads(r'{"file_id": "test_file_id", "file_unique_id": "test_unique_id", "length": 100, "duration": 30, "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 50, "height": 50}, "file_size": 1024}') - result = types.VideoNote.de_json(json_dict) - assert result.file_id == 'test_file_id' - assert result.file_unique_id == 'test_unique_id' - assert result.length == 100 - assert result.duration == 30 - assert isinstance(result.thumbnail, types.PhotoSize) - assert result.file_size == 1024 - assert isinstance(result, types.VideoNote) - - -def test_json_videoquality(): - json_dict = json.loads(r'{"file_id": "test_file_id", "file_unique_id": "test_unique_id", "width": 100, "height": 100, "codec": "h264", "file_size": 1024}') - result = types.VideoQuality.de_json(json_dict) - assert result.file_id == 'test_file_id' - assert result.file_unique_id == 'test_unique_id' - assert result.width == 100 - assert result.height == 100 - assert result.codec == 'h264' - assert result.file_size == 1024 - assert isinstance(result, types.VideoQuality) - - -def test_json_webhookinfo(): - json_dict = json.loads(r'{"url": "https://example.com", "has_custom_certificate": false, "pending_update_count": 1}') - result = types.WebhookInfo.de_json(json_dict) - assert result.url == 'https://example.com' - assert result.has_custom_certificate == False - assert result.pending_update_count == 1 - assert isinstance(result, types.WebhookInfo) \ No newline at end of file diff --git a/tests/test_types.bak02 b/tests/test_types.bak02 deleted file mode 100644 index 5cda408bc..000000000 --- a/tests/test_types.bak02 +++ /dev/null @@ -1,2689 +0,0 @@ -# -*- coding: utf-8 -*- -import sys - -sys.path.append('../') -from telebot import types -import json - - -def test_json_user(): - json_dict = json.loads(r'{"id": 123456789, "is_bot": false, "first_name": "John", "last_name": "Doe", "username": "@johndoe", "language_code": "en", "can_join_groups": true, "can_read_all_group_messages": false, "supports_inline_queries": true, "is_premium": true, "added_to_attachment_menu": false, "can_connect_to_business": true, "has_main_web_app": false, "has_topics_enabled": true, "allows_users_to_create_topics": true, "can_manage_bots": true, "supports_guest_queries": true, "supports_join_request_queries": true}') - result = types.User.de_json(json_dict) - assert result.id == 123456789 - assert result.is_bot == False - assert result.first_name == 'John' - assert result.last_name == 'Doe' - assert result.username == '@johndoe' - assert result.language_code == 'en' - assert result.can_join_groups == True - assert result.can_read_all_group_messages == False - assert result.supports_inline_queries == True - assert result.is_premium == True - assert result.added_to_attachment_menu == False - assert result.can_connect_to_business == True - assert result.has_main_web_app == False - assert result.has_topics_enabled == True - assert result.allows_users_to_create_topics == True - assert result.can_manage_bots == True - assert result.supports_guest_queries == True - assert result.supports_join_request_queries == True - assert isinstance(result, types.User) - - -def test_json_chat(): - json_dict = json.loads(r'{"id": 12345, "type": "private", "title": "Test Chat", "username": "@testchat", "first_name": "John", "last_name": "Doe", "photo": {"small_file_id": "s", "small_file_unique_id": "su", "big_file_id": "b", "big_file_unique_id": "bu"}, "bio": "bio text", "has_private_forwards": true, "description": "chat description", "invite_link": "https://t.me/joinchat/ABC", "pinned_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "pinned"}, "permissions": {"can_send_messages": true, "can_send_audios": true, "can_send_documents": true, "can_send_photos": true, "can_send_videos": true, "can_send_video_notes": true, "can_send_voice_notes": true, "can_send_polls": true, "can_send_other_messages": true, "can_add_web_page_previews": true, "can_change_info": true, "can_invite_users": true, "can_pin_messages": true, "can_manage_topics": true}, "slow_mode_delay": 30, "message_auto_delete_time": 86400, "has_protected_content": true, "sticker_set_name": "TestStickerSet", "can_set_sticker_set": false, "linked_chat_id": 2, "location": {"chat": {"id": 1, "type": "supergroup", "title": "Loc"}, "location": {"latitude": 50.45, "longitude": 30.52}, "address": "Main St"}, "join_to_send_messages": false, "join_by_request": true, "has_restricted_voice_and_video_messages": false, "is_forum": true, "max_reaction_count": 10, "active_usernames": ["test"], "emoji_status_custom_emoji_id": "custom_emoji", "has_hidden_members": false, "has_aggressive_anti_spam_enabled": false, "emoji_status_expiration_date": 1682275907, "available_reactions": ["emoji", "custom_emoji"], "accent_color_id": 1, "background_custom_emoji_id": "bg_emoji", "profile_accent_color_id": 2, "profile_background_custom_emoji_id": "profile_bg", "has_visible_history": true, "unrestrict_boost_count": 5, "custom_emoji_sticker_set_name": "custom_stickers", "business_intro": {"title": "Business", "description": "Business desc", "has_visible_history": true}, "business_location": {"address": "New York, NY", "has_active_address": true}, "business_opening_hours": {"time_zone_name": "America/New_York", "opening_hours": [{"opening_minute": 540, "closing_minute": 1020, "day_of_week": 1, "is_recurring": true}]}, "personal_chat": {"id": 3, "type": "private", "title": "Personal"}, "birthdate": {"day": "15", "month": "6"}, "can_send_paid_media": true, "accepted_gift_types": {"unlimited_gifts": false, "limited_gifts": false, "unique_gifts": true, "premium_subscription": false, "gifts_from_channels": false}, "is_direct_messages": true, "parent_chat": {"id": 4, "type": "supergroup", "title": "Parent"}, "rating": {"level": "test", "rating": "test", "current_level_rating": "test"}, "paid_message_star_count": 5, "first_profile_audio": {"file_id": "fa1", "file_unique_id": "fa1u", "duration": 30, "mime_type": "audio/ogg"}, "unique_gift_colors": {"model_custom_emoji_id": 1, "symbol_custom_emoji_id": 1, "light_theme_main_color": 333333, "light_theme_other_colors": [444444], "dark_theme_main_color": 555555, "dark_theme_other_colors": [666666]}, "guard_bot": {"id": 2, "is_bot": true, "first_name": "GuardBot"}, "community": {"id": 5, "name": "Community"}}') - result = types.Chat.de_json(json_dict) - assert result.id == 12345 - assert result.type == 'private' - assert result.title == 'Test Chat' - assert result.username == "@testchat" - assert result.first_name == "John" - assert result.last_name == "Doe" - assert isinstance(result.photo, types.ChatPhoto) - assert result.bio == "bio text" - assert result.has_private_forwards == True - assert result.description == "chat description" - assert result.invite_link == "https://t.me/joinchat/ABC" - assert isinstance(result.pinned_message, types.Message) - assert isinstance(result.permissions, types.ChatPermissions) - assert result.slow_mode_delay == 30 - assert result.message_auto_delete_time == 86400 - assert result.has_protected_content == True - assert result.sticker_set_name == "TestStickerSet" - assert result.can_set_sticker_set == False - assert result.linked_chat_id == 2 - assert isinstance(result.location, types.ChatLocation) - assert result.join_to_send_messages == False - assert result.join_by_request == True - assert result.has_restricted_voice_and_video_messages == False - assert result.is_forum == True - assert result.max_reaction_count == 10 - assert isinstance(result.active_usernames, list) - assert result.emoji_status_custom_emoji_id == "custom_emoji" - assert result.has_hidden_members == False - assert result.has_aggressive_anti_spam_enabled == False - assert result.emoji_status_expiration_date == 1682275907 - assert isinstance(result.available_reactions, list) - assert result.accent_color_id == 1 - assert result.background_custom_emoji_id == "bg_emoji" - assert result.profile_accent_color_id == 2 - assert result.profile_background_custom_emoji_id == "profile_bg" - assert result.has_visible_history == True - assert result.unrestrict_boost_count == 5 - assert result.custom_emoji_sticker_set_name == "custom_stickers" - assert isinstance(result.business_intro, types.BusinessIntro) - assert isinstance(result.business_location, types.BusinessLocation) - assert isinstance(result.business_opening_hours, types.BusinessOpeningHours) - assert isinstance(result.personal_chat, types.Chat) - assert isinstance(result.birthdate, types.Birthdate) - assert result.can_send_paid_media == True - assert isinstance(result.accepted_gift_types, types.AcceptedGiftTypes) - assert result.is_direct_messages == True - assert isinstance(result.parent_chat, types.Chat) - assert isinstance(result.rating, types.UserRating) - assert result.paid_message_star_count == 5 - assert isinstance(result.unique_gift_colors, types.UniqueGiftColors) - assert isinstance(result.first_profile_audio, types.Audio) - assert isinstance(result.guard_bot, types.User) - assert isinstance(result.community, types.Community) - assert isinstance(result, types.Chat) - - -# NOTE: Message has internal fields that are not covered by de_json tests: -# - options: internal field, not from JSON -# - json_string: internal field, not from JSON -def test_json_message(): - json_dict = json.loads(r'{"message_id": 1, "date": 1682189507, "chat": {"id": 12345, "type": "private", "title": "Chat"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "Hello", "content_type": "text"}') - result = types.Message.de_json(json_dict) - assert result.message_id == 1 - assert isinstance(result.from_user, types.User) - assert result.date == 1682189507 - assert isinstance(result.chat, types.Chat) - assert result.content_type == 'text' - assert isinstance(result, types.Message) - - -def test_json_location(): - json_dict = json.loads(r'{"latitude": 50.4501, "longitude": 30.5234, "horizontal_accuracy": 1.5, "live_period": 3600, "heading": 45, "proximity_alert_radius": 100}') - result = types.Location.de_json(json_dict) - assert result.longitude == 30.5234 - assert result.latitude == 50.4501 - assert result.horizontal_accuracy == 1.5 - assert result.live_period == 3600 - assert result.heading == 45 - assert result.proximity_alert_radius == 100 - assert isinstance(result, types.Location) - - -def test_json_venue(): - json_dict = json.loads(r'{"location": {"latitude": 50.45, "longitude": 30.52}, "title": "Kyiv", "address": "Khreshchatyk St", "foursquare_id": "12345", "foursquare_type": "restaurant", "google_place_id": "ChI123456", "google_place_type": "locality"}') - result = types.Venue.de_json(json_dict) - assert isinstance(result.location, types.Location) - assert result.title == 'Kyiv' - assert result.address == 'Khreshchatyk St' - assert result.foursquare_id == '12345' - assert result.foursquare_type == 'restaurant' - assert result.google_place_id == 'ChI123456' - assert result.google_place_type == 'locality' - assert isinstance(result, types.Venue) - - -def test_json_contact(): - json_dict = json.loads(r'{"phone_number": "+123****7890", "first_name": "John", "user_id": 12345, "last_name": "Doe", "vcard": "some vcard data"}') - result = types.Contact.de_json(json_dict) - assert result.phone_number == '+123****7890' - assert result.first_name == 'John' - assert result.last_name == 'Doe' - assert result.user_id == 12345 - assert result.vcard == 'some vcard data' - assert isinstance(result, types.Contact) - - -def test_json_document(): - json_dict = json.loads(r'{"file_id": "doc1", "file_unique_id": "du1", "file_name": "test.pdf", "mime_type": "application/pdf", "file_size": 1024, "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 50, "height": 50}}') - result = types.Document.de_json(json_dict) - assert result.file_id == 'doc1' - assert result.file_unique_id == 'du1' - assert isinstance(result.thumbnail, types.PhotoSize) - assert result.file_name == 'test.pdf' - assert result.mime_type == 'application/pdf' - assert result.file_size == 1024 - assert isinstance(result, types.Document) - - -def test_json_photo_size(): - json_dict = json.loads(r'{"file_id": "photo1", "file_unique_id": "pu1", "width": 100, "height": 100, "file_size": 512}') - result = types.PhotoSize.de_json(json_dict) - assert result.file_id == 'photo1' - assert result.file_unique_id == 'pu1' - assert result.width == 100 - assert result.height == 100 - assert result.file_size == 512 - assert isinstance(result, types.PhotoSize) - - -def test_json_video(): - json_dict = json.loads(r'{"file_id": "video1", "file_unique_id": "vu1", "width": 640, "height": 480, "duration": 30, "mime_type": "video/mp4", "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 50, "height": 50}, "file_name": "video.mp4", "file_size": 2048, "start_timestamp": 5, "qualities": [{"file_id": "q1", "file_unique_id": "qu1", "width": 240, "height": 360, "codec": "h264", "file_size": 1024}, {"file_id": "q2", "file_unique_id": "qu2", "width": 640, "height": 480, "codec": "h264", "file_size": 2048}]}') - result = types.Video.de_json(json_dict) - assert result.file_id == 'video1' - assert result.file_unique_id == 'vu1' - assert result.width == 640 - assert result.height == 480 - assert result.duration == 30 - assert isinstance(result.thumbnail, types.PhotoSize) - assert result.file_name == 'video.mp4' - assert result.mime_type == 'video/mp4' - assert result.file_size == 2048 - assert result.cover is None - assert result.start_timestamp == 5 - assert isinstance(result.qualities, list) - assert isinstance(result, types.Video) - - -def test_json_audio(): - json_dict = json.loads(r'{"file_id": "audio1", "file_unique_id": "au1", "duration": 30, "mime_type": "audio/mpeg", "performer": "Artist", "title": "Song Title", "file_name": "song.mp3", "file_size": 512, "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 50, "height": 50}}') - result = types.Audio.de_json(json_dict) - assert result.file_id == 'audio1' - assert result.file_unique_id == 'au1' - assert result.duration == 30 - assert result.performer == 'Artist' - assert result.title == 'Song Title' - assert result.file_name == 'song.mp3' - assert result.mime_type == 'audio/mpeg' - assert result.file_size == 512 - assert isinstance(result.thumbnail, types.PhotoSize) - assert isinstance(result, types.Audio) - - -def test_json_voice(): - json_dict = json.loads(r'{"file_id": "voice1", "file_unique_id": "vu1", "duration": 30, "mime_type": "audio/ogg", "file_size": 256}') - result = types.Voice.de_json(json_dict) - assert result.file_id == 'voice1' - assert result.file_unique_id == 'vu1' - assert result.duration == 30 - assert result.mime_type == 'audio/ogg' - assert result.file_size == 256 - assert isinstance(result, types.Voice) - - -def test_json_animation(): - json_dict = json.loads(r'{"file_id": "anim1", "file_unique_id": "anu1", "width": 100, "height": 100, "duration": 10, "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 50, "height": 50}, "file_name": "anim.mp4", "mime_type": "video/mp4", "file_size": 1024}') - result = types.Animation.de_json(json_dict) - assert result.file_id == 'anim1' - assert result.file_unique_id == 'anu1' - assert result.width == 100 - assert result.height == 100 - assert result.duration == 10 - assert isinstance(result.thumbnail, types.PhotoSize) - assert result.file_name == 'anim.mp4' - assert result.mime_type == 'video/mp4' - assert result.file_size == 1024 - assert isinstance(result, types.Animation) - - -def test_json_sticker(): - json_dict = json.loads(r'{"file_id": "sticker1", "file_unique_id": "stu1", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false, "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 100, "height": 100}, "emoji": "😀", "set_name": "TestSet", "mask_position": {"point": "forehead", "x_shift": 0.0, "y_shift": 0.0, "scale": 0.5}, "file_size": 4096, "premium_animation": {"file_id": "pa1", "file_unique_id": "pa1u"}, "custom_emoji_id": "ce1", "needs_repainting": true}') - result = types.Sticker.de_json(json_dict) - assert result.file_id == 'sticker1' - assert result.file_unique_id == 'stu1' - assert result.type == 'regular' - assert result.width == 512 - assert result.height == 512 - assert result.is_animated == False - assert result.is_video == False - assert isinstance(result.thumbnail, types.PhotoSize) - assert result.emoji == '😀' - assert result.set_name == 'TestSet' - assert isinstance(result.mask_position, types.MaskPosition) - assert result.file_size == 4096 - assert isinstance(result.premium_animation, types.File) - assert result.custom_emoji_id == 'ce1' - assert result.needs_repainting == True - assert isinstance(result, types.Sticker) - - -def test_json_stickerset(): - json_dict = json.loads(r'{"name": "TestName", "title": "Test Title", "sticker_type": "regular", "stickers": [{"file_id": "st1", "file_unique_id": "su1", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}], "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 100, "height": 100}}') - result = types.StickerSet.de_json(json_dict) - assert result.name == 'TestName' - assert result.title == 'Test Title' - assert result.sticker_type == 'regular' - assert isinstance(result.stickers, list) - assert isinstance(result.thumbnail, types.PhotoSize) - assert isinstance(result, types.StickerSet) - - -def test_json_chatlocation(): - json_dict = json.loads(r'{"location": {"latitude": 50.45, "longitude": 30.52}, "address": "New York, NY"}') - result = types.ChatLocation.de_json(json_dict) - assert isinstance(result.location, types.Location) - assert result.address == 'New York, NY' - - -def test_json_reactiontypeemoji(): - json_dict = json.loads(r'{"type": "emoji", "emoji": "\u2764\uFE0F"}') - result = types.ReactionTypeEmoji.de_json(json_dict) - assert result.emoji == '❤️' - assert isinstance(result, types.ReactionTypeEmoji) - - -def test_json_reactiontypecustomemoji(): - json_dict = json.loads(r'{"type": "custom_emoji", "custom_emoji_id": "ce123"}') - result = types.ReactionTypeCustomEmoji.de_json(json_dict) - assert result.custom_emoji_id == 'ce123' - assert isinstance(result, types.ReactionTypeCustomEmoji) - - -def test_json_reactioncount(): - json_dict = json.loads(r'{"type": {"type": "emoji", "emoji": "\u2764\uFE0F"}, "total_count": 5}') - result = types.ReactionCount.de_json(json_dict) - assert isinstance(result.type, types.ReactionType) - assert result.total_count == 5 - assert isinstance(result, types.ReactionCount) - - -def test_json_chatinvitelink(): - json_dict = json.loads(r'{"invite_link": "https://t.me/joinchat/ABC", "creator": {"id": 12345, "is_bot": false, "first_name": "Test"}, "creates_join_request": false, "is_primary": true, "is_revoked": false, "name": "Invite", "expire_date": 1704067200, "member_limit": 10, "pending_join_request_count": 3}') - result = types.ChatInviteLink.de_json(json_dict) - assert result.invite_link == 'https://t.me/joinchat/ABC' - assert isinstance(result.creator, types.User) - assert result.creates_join_request == False - assert result.is_primary == True - assert result.is_revoked == False - assert result.name == 'Invite' - assert result.expire_date == 1704067200 - assert result.member_limit == 10 - assert result.pending_join_request_count == 3 - assert isinstance(result, types.ChatInviteLink) - - -def test_json_forumtopic(): - json_dict = json.loads(r'{"message_thread_id": 42, "name": "Topic", "icon_color": 4294967295, "icon_custom_emoji_id": "emoji1", "is_name_implicit": true}') - result = types.ForumTopic.de_json(json_dict) - assert result.message_thread_id == 42 - assert result.name == 'Topic' - assert result.icon_color == 4294967295 - assert result.icon_custom_emoji_id == 'emoji1' - assert result.is_name_implicit == True - assert isinstance(result, types.ForumTopic) - - -def test_json_loginurl(): - json_dict = json.loads(r'{"url": "https://example.com", "forward_text": "Forward", "bot_username": "botuser", "request_write_access": true}') - result = types.LoginUrl.de_json(json_dict) - assert result.url == 'https://example.com' - assert result.forward_text == 'Forward' - assert result.bot_username == 'botuser' - assert result.request_write_access == True - assert isinstance(result, types.LoginUrl) - - -def test_json_webappinfo(): - json_dict = json.loads(r'{"url": "https://example.com"}') - result = types.WebAppInfo.de_json(json_dict) - assert result.url == 'https://example.com' - assert isinstance(result, types.WebAppInfo) - - -def test_json_webappdata(): - json_dict = json.loads(r'{"data": "test_data", "button_text": "Button"}') - result = types.WebAppData.de_json(json_dict) - assert result.data == 'test_data' - assert result.button_text == 'Button' - assert isinstance(result, types.WebAppData) - - -def test_json_maskposition(): - json_dict = json.loads(r'{"point": "forehead", "x_shift": 0.0, "y_shift": 0.0, "scale": 0.5}') - result = types.MaskPosition.de_json(json_dict) - assert result.point == 'forehead' - assert result.x_shift == 0.0 - assert result.y_shift == 0.0 - assert result.scale == 0.5 - assert isinstance(result, types.MaskPosition) - - -def test_json_messageentity(): - json_dict = json.loads(r'{"type": "bold", "offset": 0, "length": 5, "url": "https://example.com", "language": "en", "unix_time": 1682189507, "date_time_format": "YYYY-MM-DD"}') - result = types.MessageEntity.de_json(json_dict) - assert result.type == 'bold' - assert result.offset == 0 - assert result.length == 5 - assert result.url == 'https://example.com' - assert result.language == 'en' - assert result.unix_time == 1682189507 - assert result.date_time_format == 'YYYY-MM-DD' - assert isinstance(result, types.MessageEntity) - - -def test_json_messageentitycustomemoji(): - json_dict = json.loads(r'{"type": "custom_emoji", "offset": 0, "length": 10, "custom_emoji_id": "ce123"}') - result = types.MessageEntity.de_json(json_dict) - assert result.type == 'custom_emoji' - assert result.offset == 0 - assert result.length == 10 - assert result.custom_emoji_id == 'ce123' - assert isinstance(result, types.MessageEntity) - - -def test_json_messageentitytextmention(): - json_dict = json.loads(r'{"type": "text_mention", "offset": 0, "length": 10, "user": {"id": 12345, "is_bot": false, "first_name": "Test"}}') - result = types.MessageEntity.de_json(json_dict) - assert result.type == 'text_mention' - assert result.offset == 0 - assert result.length == 10 - assert isinstance(result.user, types.User) - assert isinstance(result, types.MessageEntity) - - -def test_json_chatshared(): - json_dict = json.loads(r'{"request_id": 1, "chat_id": 12345, "title": "Chat Title", "photo": {"small_file_id": "s", "small_file_unique_id": "su", "big_file_id": "b", "big_file_unique_id": "bu"}, "username": "chatuser"}') - result = types.ChatShared.de_json(json_dict) - assert result.request_id == 1 - assert result.chat_id == 12345 - assert result.title == 'Chat Title' - # photo is returned as dict in this fork (not parsed to ChatPhoto) - assert isinstance(result.photo, dict) - assert result.photo.get('small_file_id') == 's' - assert result.username == 'chatuser' - assert isinstance(result, types.ChatShared) - - -def test_json_shareduser(): - json_dict = json.loads(r'{"user_id": 12345, "first_name": "Test", "last_name": "User", "username": "testuser", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}') - result = types.SharedUser.de_json(json_dict) - assert result.user_id == 12345 - assert result.first_name == 'Test' - assert result.last_name == 'User' - assert result.username == 'testuser' - assert isinstance(result.photo, list) - assert isinstance(result.photo[0], types.PhotoSize) - assert isinstance(result, types.SharedUser) - - -def test_json_usersshared(): - json_dict = json.loads(r'{"request_id": 1, "users": [{"user_id": 12345, "first_name": "Test", "last_name": "User"}]}') - result = types.UsersShared.de_json(json_dict) - assert result.request_id == 1 - assert isinstance(result.users, list) - assert isinstance(result, types.UsersShared) - - -def test_json_chatboost(): - json_dict = json.loads(r'{"boost_item_id": "b1", "add_date": 1682189507, "expiration_date": 1682275907, "source": {"source": "premium", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}}') - result = types.ChatBoost.de_json(json_dict) - assert result.boost_id is None - assert result.add_date == 1682189507 - assert result.expiration_date == 1682275907 - assert isinstance(result.source, types.ChatBoostSourcePremium) - assert result.source.source == 'premium' - assert isinstance(result.source.user, types.User) - assert isinstance(result, types.ChatBoost) - - -def test_json_gift(): - json_dict = json.loads(r'{"id": 123456789, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100, "total_count": 5, "remaining_count": 3, "upgrade_star_count": 50, "personal_total_count": 10, "personal_remaining_count": 2, "is_premium": true, "has_colors": true, "background": {"center_color": 16777215, "edge_color": 16711680, "text_color": 0}, "publisher_chat": {"id": 1, "type": "channel", "title": "Publisher"}, "unique_gift_variant_count": 3}') - result = types.Gift.de_json(json_dict) - assert result.id == 123456789 - assert isinstance(result.sticker, types.Sticker) - assert result.star_count == 100 - assert result.total_count == 5 - assert result.remaining_count == 3 - assert result.upgrade_star_count == 50 - assert result.personal_total_count == 10 - assert result.personal_remaining_count == 2 - assert result.is_premium == True - assert result.has_colors == True - assert isinstance(result.background, types.GiftBackground) - assert isinstance(result.publisher_chat, types.Chat) - assert result.unique_gift_variant_count == 3 - assert isinstance(result, types.Gift) - - -def test_json_giftinfo(): - json_dict = json.loads(r'{"gift": {"id": 123456789, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100}, "owned_gift_id": "og_123", "convert_star_count": 50, "prepaid_upgrade_star_count": 100, "can_be_upgraded": true, "text": {"type": "bold", "text": "Gift text"}, "entities": [{"type": "bold", "offset": 0, "length": 4}], "is_private": false, "is_upgrade_separate": false, "unique_gift_number": 42}') - result = types.GiftInfo.de_json(json_dict) - assert isinstance(result.gift, types.Gift) - assert result.owned_gift_id == 'og_123' - assert result.convert_star_count == 50 - assert result.prepaid_upgrade_star_count == 100 - assert result.can_be_upgraded == True - assert result.text == {'type': 'bold', 'text': 'Gift text'} - assert isinstance(result.entities, list) - assert result.is_private == False - assert result.is_upgrade_separate == False - assert result.unique_gift_number == 42 - assert isinstance(result, types.GiftInfo) - - -def test_json_gifts(): - json_dict = json.loads(r'{"gifts": [{"id": 123456789, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100}]}') - result = types.Gifts.de_json(json_dict) - assert isinstance(result.gifts, list) - assert isinstance(result, types.Gifts) - - -def test_json_richtextbold(): - json_dict = json.loads(r'{"type": "bold", "text": "Test"}') - result = types.RichText.de_json(json_dict) - assert result.text == 'Test' - assert isinstance(result, types.RichTextBold) - - -def test_json_richtextitalic(): - json_dict = json.loads(r'{"type": "italic", "text": "Test"}') - result = types.RichText.de_json(json_dict) - assert result.text == 'Test' - assert isinstance(result, types.RichTextItalic) - - -def test_json_richtextunderline(): - json_dict = json.loads(r'{"type": "underline", "text": "Test"}') - result = types.RichText.de_json(json_dict) - assert result.text == 'Test' - assert isinstance(result, types.RichTextUnderline) - - -def test_json_richtextstrikethrough(): - json_dict = json.loads(r'{"type": "strikethrough", "text": "Test"}') - result = types.RichText.de_json(json_dict) - assert result.text == 'Test' - assert isinstance(result, types.RichTextStrikethrough) - - -def test_json_richtextspoiler(): - json_dict = json.loads(r'{"type": "spoiler", "text": "Test"}') - result = types.RichText.de_json(json_dict) - assert result.text == 'Test' - assert isinstance(result, types.RichTextSpoiler) - - -def test_json_richtextsubscript(): - json_dict = json.loads(r'{"type": "subscript", "text": "sub"}') - result = types.RichText.de_json(json_dict) - assert result.text == 'sub' - assert isinstance(result, types.RichTextSubscript) - - -def test_json_richtextsuperscript(): - json_dict = json.loads(r'{"type": "superscript", "text": "sup"}') - result = types.RichText.de_json(json_dict) - assert result.text == 'sup' - assert isinstance(result, types.RichTextSuperscript) - - -def test_json_richtextmarked(): - json_dict = json.loads(r'{"type": "marked", "text": "marked"}') - result = types.RichText.de_json(json_dict) - assert result.text == 'marked' - assert isinstance(result, types.RichTextMarked) - - -def test_json_richtextcode(): - json_dict = json.loads(r'{"type": "code", "text": "code"}') - result = types.RichText.de_json(json_dict) - assert result.text == 'code' - assert isinstance(result, types.RichTextCode) - - -def test_json_richtextanchor(): - json_dict = json.loads(r'{"type": "anchor", "name": "anchor"}') - result = types.RichText.de_json(json_dict) - assert result.name == 'anchor' - assert isinstance(result, types.RichTextAnchor) - - -def test_json_richtextdatetime(): - json_dict = json.loads(r'{"type": "date_time", "text": "2024-01-01", "unix_time": 1704067200, "date_time_format": "YYYY-MM-DD"}') - result = types.RichText.de_json(json_dict) - assert result.text == '2024-01-01' - assert result.unix_time == 1704067200 - assert result.date_time_format == 'YYYY-MM-DD' - assert isinstance(result, types.RichTextDateTime) - - -def test_json_richtexttextmention(): - json_dict = json.loads(r'{"type": "text_mention", "text": "test text", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}}') - result = types.RichText.de_json(json_dict) - assert result.text == 'test text' - assert isinstance(result.user, types.User) - assert isinstance(result, types.RichTextTextMention) - - -def test_json_richtextanchorlink(): - json_dict = json.loads(r'{"type": "anchor_link", "text": "Link", "anchor_name": "anchor"}') - result = types.RichText.de_json(json_dict) - assert result.text == 'Link' - assert result.anchor_name == 'anchor' - assert isinstance(result, types.RichTextAnchorLink) - - -def test_json_richtexturl(): - json_dict = json.loads(r'{"type": "url", "text": "click here", "url": "https://example.com"}') - result = types.RichText.de_json(json_dict) - assert result.text == 'click here' - assert result.url == 'https://example.com' - assert isinstance(result, types.RichTextUrl) - - -def test_json_richtextemailaddress(): - json_dict = json.loads(r'{"type": "email_address", "text": "test@example.com", "email_address": "test@example.com"}') - result = types.RichText.de_json(json_dict) - assert result.text == 'test@example.com' - assert result.email_address == 'test@example.com' - assert isinstance(result, types.RichTextEmailAddress) - - -def test_json_richtextphonenumber(): - json_dict = json.loads(r'{"type": "phone_number", "text": "+123****7890", "phone_number": "+123****7890"}') - result = types.RichText.de_json(json_dict) - assert result.text == '+123****7890' - assert result.phone_number == '+123****7890' - assert isinstance(result, types.RichTextPhoneNumber) - - -def test_json_richtextbankcardnumber(): - json_dict = json.loads(r'{"type": "bank_card_number", "text": "1234 5678 9012 3456", "bank_card_number": "1234 5678 9012 3456"}') - result = types.RichText.de_json(json_dict) - assert result.text == '1234 5678 9012 3456' - assert result.bank_card_number == '1234 5678 9012 3456' - assert isinstance(result, types.RichTextBankCardNumber) - - -def test_json_richblockparagraph(): - json_dict = json.loads(r'{"type": "paragraph", "text": "Test"}') - result = types.RichBlock.de_json(json_dict) - assert result.text == 'Test' - assert isinstance(result, types.RichBlockParagraph) - - -def test_json_richblockpreformatted(): - json_dict = json.loads(r'{"type": "pre", "text": "Code", "language": "python"}') - result = types.RichBlock.de_json(json_dict) - assert result.text == 'Code' - assert result.language == 'python' - assert isinstance(result, types.RichBlockPreformatted) - - -def test_json_richblockfooter(): - json_dict = json.loads(r'{"type": "footer", "text": "Footer"}') - result = types.RichBlock.de_json(json_dict) - assert result.text == 'Footer' - assert isinstance(result, types.RichBlockFooter) - - -def test_json_richblockcaption(): - json_dict = json.loads(r'{"type": "caption", "text": "Caption", "credit": "Author"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichBlockCaption.de_json(data) - assert result.text == 'Caption' - assert result.credit == 'Author' - assert isinstance(result, types.RichBlockCaption) - - -def test_json_richblockanimation(): - json_dict = json.loads(r'{"type": "animation", "animation": {"file_id": "anim_id", "file_unique_id": "anim_uid", "width": 100, "height": 100, "duration": 10}, "caption": {"type": "bold", "text": "anim caption"}, "has_spoiler": true}') - result = types.RichBlock.de_json(json_dict) - assert isinstance(result.animation, types.Animation) - assert result.has_spoiler == True - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockAnimation) - - -def test_json_richblockdetails(): - json_dict = json.loads(r'{"type": "details", "summary": {"text": "summary text"}, "blocks": [{"text": "detail"}], "is_open": false}') - result = types.RichBlock.de_json(json_dict) - assert isinstance(result.summary, dict) or result.summary is None - assert isinstance(result.blocks, list) - assert result.is_open == False - assert isinstance(result, types.RichBlockDetails) - - -def test_json_richblocklistitem(): - json_dict = json.loads(r'{"label": {"text": "label text"}, "blocks": [{"text": "item block"}], "has_checkbox": true, "is_checked": true, "value": "item value"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichBlockListItem.de_json(data) - assert isinstance(result.label, dict) - assert isinstance(result.blocks, list) - assert result.has_checkbox == True - assert result.is_checked == True - assert result.value == 'item value' - assert result.type is None - assert isinstance(result, types.RichBlockListItem) - - -def test_json_richblockvoicenote(): - json_dict = json.loads(r'{"type": "voice_note", "voice_note": {"file_id": "voice_id", "file_unique_id": "voice_uid", "duration": 30}, "caption": {"type": "bold", "text": "voice caption"}}') - result = types.RichBlock.de_json(json_dict) - assert isinstance(result.voice_note, types.Voice) - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockVoiceNote) - - -def test_json_chatadministratorrights(): - json_dict = json.loads(r'{"is_anonymous": true, "can_manage_chat": true, "can_delete_messages": true, "can_manage_video_chats": true, "can_restrict_members": true, "can_promote_members": true, "can_change_info": true, "can_invite_users": true, "can_post_messages": true, "can_edit_messages": true, "can_pin_messages": true, "can_manage_topics": true, "can_post_stories": true, "can_edit_stories": true, "can_delete_stories": true, "can_manage_direct_messages": true, "can_manage_tags": true}') - result = types.ChatAdministratorRights.de_json(json_dict) - assert result.is_anonymous == True - assert result.can_manage_chat == True - assert result.can_delete_messages == True - assert result.can_manage_video_chats == True - assert result.can_restrict_members == True - assert result.can_promote_members == True - assert result.can_change_info == True - assert result.can_invite_users == True - assert result.can_post_messages == True - assert result.can_edit_messages == True - assert result.can_pin_messages == True - assert result.can_manage_topics == True - assert result.can_post_stories == True - assert result.can_edit_stories == True - assert result.can_delete_stories == True - assert result.can_manage_direct_messages == True - assert result.can_manage_tags == True - assert isinstance(result, types.ChatAdministratorRights) - - -def test_json_chatpermissions(): - json_dict = json.loads(r'{"can_send_messages": true, "can_send_audios": true, "can_send_documents": true, "can_send_photos": true, "can_send_videos": true, "can_send_video_notes": true, "can_send_voice_notes": true, "can_send_polls": true, "can_send_other_messages": true, "can_add_web_page_previews": true, "can_change_info": true, "can_invite_users": true, "can_pin_messages": true, "can_manage_topics": true, "can_edit_tag": true, "can_react_to_messages": true}') - result = types.ChatPermissions.de_json(json_dict) - assert result.can_send_messages == True - # can_send_media_messages is deprecated in this fork, not a real attribute - assert result.can_send_audios == True - assert result.can_send_documents == True - assert result.can_send_photos == True - assert result.can_send_videos == True - assert result.can_send_video_notes == True - assert result.can_send_voice_notes == True - assert result.can_send_polls == True - assert result.can_send_other_messages == True - assert result.can_add_web_page_previews == True - assert result.can_change_info == True - assert result.can_invite_users == True - assert result.can_pin_messages == True - assert result.can_manage_topics == True - assert result.can_edit_tag == True - assert result.can_react_to_messages == True - assert isinstance(result, types.ChatPermissions) - - -def test_json_chatmembermember(): - json_dict = json.loads(r'{"user": {"id": 1, "is_bot": false, "first_name": "Test"}, "status": "member", "until_date": 1682275907, "tag": "member_tag"}') - result = types.ChatMemberMember.de_json(json_dict) - assert isinstance(result.user, types.User) - assert result.status == 'member' - assert result.until_date == 1682275907 - assert result.tag == 'member_tag' - assert isinstance(result, types.ChatMemberMember) - - -def test_json_chatmemberowner(): - json_dict = json.loads(r'{"status": "creator", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "is_anonymous": false, "custom_title": "Owner"}') - result = types.ChatMemberOwner.de_json(json_dict) - assert isinstance(result.user, types.User) - assert result.status == 'creator' - assert result.is_anonymous == False - assert result.custom_title == 'Owner' - assert isinstance(result, types.ChatMemberOwner) - - -def test_json_chatmemberadministrator(): - json_dict = json.loads(r'{"status": "administrator", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "is_anonymous": true, "can_be_edited": true, "can_manage_chat": true, "can_delete_messages": true, "can_manage_video_chats": true, "can_restrict_members": true, "can_promote_members": true, "can_change_info": true, "can_invite_users": true, "can_post_stories": true, "can_edit_stories": true, "can_delete_stories": true, "can_post_messages": true, "can_edit_messages": true, "can_pin_messages": true, "can_manage_topics": true, "can_manage_direct_messages": true, "can_manage_tags": true, "custom_title": "mod"}') - result = types.ChatMemberAdministrator.de_json(json_dict) - assert isinstance(result.user, types.User) - assert result.status == 'administrator' - assert result.can_be_edited == True - assert result.is_anonymous == True - assert result.can_manage_chat == True - assert result.can_delete_messages == True - assert result.can_manage_video_chats == True - assert result.can_restrict_members == True - assert result.can_promote_members == True - assert result.can_change_info == True - assert result.can_invite_users == True - assert result.can_post_stories == True - assert result.can_edit_stories == True - assert result.can_delete_stories == True - assert result.can_post_messages == True - assert result.can_edit_messages == True - assert result.can_pin_messages == True - assert result.can_manage_topics == True - assert result.custom_title == "mod" - assert result.can_manage_direct_messages == True - assert result.can_manage_tags == True - assert isinstance(result, types.ChatMemberAdministrator) - - -def test_json_chatmemberrestricted(): - json_dict = json.loads(r'{"status": "restricted", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "is_member": true, "can_send_messages": true, "can_send_audios": true, "can_send_documents": true, "can_send_photos": true, "can_send_videos": true, "can_send_video_notes": true, "can_send_voice_notes": true, "can_send_polls": true, "can_send_other_messages": true, "can_add_web_page_previews": true, "can_change_info": false, "can_invite_users": false, "can_pin_messages": false, "can_manage_topics": false, "until_date": 1682189507, "tag": "test_tag", "can_edit_tag": true, "can_react_to_messages": true}') - result = types.ChatMemberRestricted.de_json(json_dict) - assert isinstance(result.user, types.User) - assert result.status == 'restricted' - assert result.is_member == True - assert result.can_send_messages == True - assert result.can_send_audios == True - assert result.can_send_documents == True - assert result.can_send_photos == True - assert result.can_send_videos == True - assert result.can_send_video_notes == True - assert result.can_send_voice_notes == True - assert result.can_send_polls == True - assert result.can_send_other_messages == True - assert result.can_add_web_page_previews == True - assert result.can_change_info == False - assert result.can_invite_users == False - assert result.can_pin_messages == False - assert result.can_manage_topics == False - assert result.until_date == 1682189507 - assert result.tag == 'test_tag' - assert result.can_edit_tag == True - assert result.can_react_to_messages == True - assert isinstance(result, types.ChatMemberRestricted) - - -def test_json_chatmemberleft(): - json_dict = json.loads(r'{"status": "left", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}}') - result = types.ChatMemberLeft.de_json(json_dict) - assert isinstance(result.user, types.User) - assert result.status == 'left' - assert isinstance(result, types.ChatMemberLeft) - - -def test_json_chatmemberbanned(): - json_dict = json.loads(r'{"status": "kicked", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "until_date": 1682189507}') - result = types.ChatMemberBanned.de_json(json_dict) - assert isinstance(result.user, types.User) - assert result.status == 'kicked' - assert result.until_date == 1682189507 - assert isinstance(result, types.ChatMemberBanned) - - -def test_json_botcommand(): - json_dict = json.loads(r'{"command": "/start", "description": "Start command", "is_ephemeral": true}') - result = types.BotCommand.de_json(json_dict) - assert result.command == '/start' - assert result.description == 'Start command' - assert result.is_ephemeral == True - assert isinstance(result, types.BotCommand) - - -def test_json_botdescription(): - json_dict = json.loads(r'{"language_code": "en", "description": "Bot description"}') - result = types.BotDescription.de_json(json_dict) - assert result.description == 'Bot description' - assert isinstance(result, types.BotDescription) - - -def test_json_botname(): - json_dict = json.loads(r'{"language_code": "en", "name": "Bot Name"}') - result = types.BotName.de_json(json_dict) - assert result.name == 'Bot Name' - assert isinstance(result, types.BotName) - - -def test_json_botshortdescription(): - json_dict = json.loads(r'{"language_code": "en", "short_description": "Short"}') - result = types.BotShortDescription.de_json(json_dict) - assert result.short_description == 'Short' - assert isinstance(result, types.BotShortDescription) - - -def test_json_inlinekeyboardbutton(): - json_dict = json.loads(r'{"text": "Button", "url": "https://example.com", "callback_data": "data", "web_app": {"url": "https://example.com"}, "switch_inline_query": "query", "switch_inline_query_current_chat": "query", "switch_inline_query_chosen_chat": {"query": "q", "allow_user_chats": true, "allow_bot_chats": true, "allow_group_chats": true, "allow_channel_chats": true}, "callback_game": {"type": "test"}, "pay": true, "login_url": {"url": "https://example.com", "forward_text": "Forward", "bot_username": "bot", "request_write_access": true}, "copy_text": {"text": "copy"}, "icon_custom_emoji_id": "emoji123", "style": "primary"}') - result = types.InlineKeyboardButton.de_json(json_dict) - assert result.text == 'Button' - assert result.url == 'https://example.com' - assert result.callback_data == 'data' - assert isinstance(result.web_app, types.WebAppInfo) - assert result.switch_inline_query == 'query' - assert result.switch_inline_query_current_chat == 'query' - assert isinstance(result.switch_inline_query_chosen_chat, types.SwitchInlineQueryChosenChat) - assert isinstance(result.callback_game, dict) - assert result.pay == True - assert isinstance(result.login_url, types.LoginUrl) - assert isinstance(result.copy_text, types.CopyTextButton) - assert result.icon_custom_emoji_id == 'emoji123' - assert result.style == 'primary' - assert isinstance(result, types.InlineKeyboardButton) - - -def test_json_menubuttoncommands(): - json_dict = json.loads(r'{"type": "commands", "default_width": 100}') - result = types.MenuButtonCommands.de_json(json_dict) - assert result.type == 'commands' - assert isinstance(result, types.MenuButtonCommands) - - -def test_json_menubuttondefault(): - json_dict = json.loads(r'{"type": "default"}') - result = types.MenuButtonDefault.de_json(json_dict) - assert result.type == 'default' - assert isinstance(result, types.MenuButtonDefault) - - -def test_json_menubuttonwebapp(): - json_dict = json.loads(r'{"type": "web_app", "text": "Open App", "web_app": {"url": "https://example.com"}}') - result = types.MenuButtonWebApp.de_json(json_dict) - assert result.type == 'web_app' - assert result.text == 'Open App' - assert isinstance(result.web_app, dict) - assert isinstance(result, types.MenuButtonWebApp) - - -def test_json_pollanswer(): - json_dict = json.loads(r'{"poll_id": "poll_id", "option_ids": [0], "option_persistent_ids": [0], "user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "voter_chat": {"id": 67890, "type": "channel", "title": "Channel"}}') - result = types.PollAnswer.de_json(json_dict) - assert result.poll_id == 'poll_id' - assert isinstance(result.option_ids, list) - assert isinstance(result.option_persistent_ids, list) - assert isinstance(result.user, types.User) - assert isinstance(result.voter_chat, types.Chat) - assert isinstance(result, types.PollAnswer) - - -def test_json_reactiontype(): - json_dict = json.loads(r'{"type": "emoji", "emoji": "\u2764\uFE0F"}') - result = types.ReactionType.de_json(json_dict) - assert result.type == 'emoji' - assert isinstance(result, types.ReactionType) - - -def test_linkpreviewoptionsto_dict(): - obj = types.LinkPreviewOptions(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_sentwebappmessageto_dict(): - obj = types.SentWebAppMessage(message_id=1) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_json_reactiontypepaid(): - json_dict = json.loads(r'{"type": "paid"}') - result = types.ReactionTypePaid.de_json(json_dict) - assert isinstance(result, types.ReactionTypePaid) - - -def test_json_businessbotrights(): - result = types.BusinessBotRights.de_json({}) - assert result.can_reply is None - assert result.can_read_messages is None - assert result.can_delete_outgoing_messages is None - assert result.can_delete_all_messages is None - assert result.can_edit_name is None - assert result.can_edit_bio is None - assert result.can_edit_profile_photo is None - assert result.can_edit_username is None - assert result.can_change_gift_settings is None - assert result.can_view_gifts_and_stars is None - assert result.can_convert_gifts_to_stars is None - assert result.can_transfer_and_upgrade_gifts is None - assert result.can_transfer_stars is None - assert result.can_manage_stories is None - assert isinstance(result, types.BusinessBotRights) - - -def test_json_businessintro(): - json_dict = json.loads(r'{"title": "Business Title", "message": "Business message text", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}}') - result = types.BusinessIntro.de_json(json_dict) - assert result.title == 'Business Title' - assert result.message == 'Business message text' - assert isinstance(result.sticker, types.Sticker) - assert isinstance(result, types.BusinessIntro) - - -def test_json_chatownerleft(): - result = types.ChatOwnerLeft.de_json({}) - assert isinstance(result, types.ChatOwnerLeft) or result is None - assert result.new_owner is None - - -def test_json_checklisttasksdone(): - json_dict = json.loads(r'{"checklist_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "checklist"}, "marked_as_done_task_ids": [1, 2], "marked_as_not_done_task_ids": [3]}') - result = types.ChecklistTasksDone.de_json(json_dict) - assert isinstance(result.checklist_message, types.Message) - assert isinstance(result.marked_as_done_task_ids, list) - assert result.marked_as_done_task_ids == [1, 2] - assert isinstance(result.marked_as_not_done_task_ids, list) - assert result.marked_as_not_done_task_ids == [3] - assert isinstance(result, types.ChecklistTasksDone) - - -def test_json_communitychatadded(): - result = types.CommunityChatAdded.de_json({}) - assert isinstance(result, types.CommunityChatAdded) or result is None - assert result.community is None - - -def test_json_communitychatremoved(): - result = types.CommunityChatRemoved.de_json({}) - assert isinstance(result, types.CommunityChatRemoved) or result is None - - -def test_json_forumtopicclosed(): - result = types.ForumTopicClosed.de_json({}) - assert isinstance(result, types.ForumTopicClosed) or result is None - - -def test_json_forumtopicedited(): - result = types.ForumTopicEdited.de_json({'name': 'New Name', 'icon_custom_emoji_id': 'custom_emoji'}) - assert result.name == 'New Name' - assert result.icon_custom_emoji_id == 'custom_emoji' - assert isinstance(result, types.ForumTopicEdited) - - -def test_json_forumtopicreopened(): - result = types.ForumTopicReopened.de_json({}) - assert isinstance(result, types.ForumTopicReopened) or result is None - - -def test_json_generalforumtopichidden(): - result = types.GeneralForumTopicHidden.de_json({}) - assert isinstance(result, types.GeneralForumTopicHidden) or result is None - - -def test_json_generalforumtopicunhidden(): - result = types.GeneralForumTopicUnhidden.de_json({}) - assert isinstance(result, types.GeneralForumTopicUnhidden) or result is None - - -def test_json_giveawaycreated(): - result = types.GiveawayCreated.de_json({}) - assert isinstance(result, types.GiveawayCreated) or result is None - assert hasattr(result, 'prize_star_count') - - -def test_json_linkpreviewoptions(): - result = types.LinkPreviewOptions.de_json({}) - assert result.is_disabled is None - assert result.url is None - assert result.prefer_small_media is None - assert result.prefer_large_media is None - assert result.show_above_text is None - assert isinstance(result, types.LinkPreviewOptions) - - -def test_json_orderinfo(): - json_dict = {'name': 'John', 'phone_number': '+1234567890', 'email': 'john@example.com', 'shipping_address': {'country_code': 'US', 'city': 'New York', 'street_line1': '123 Main St', 'street_line2': 'Apt 4B', 'postal_code': '10001', 'state': 'NY', 'post_code': '10001'}} - result = types.OrderInfo.de_json(json_dict) - assert result.name == 'John' - assert result.phone_number == '+1234567890' - assert result.email == 'john@example.com' - assert isinstance(result.shipping_address, types.ShippingAddress) - assert isinstance(result, types.OrderInfo) or result is None - assert hasattr(result, 'name') - assert hasattr(result, 'phone_number') - assert hasattr(result, 'email') - - -def test_json_pollmedia(): - json_dict = json.loads(r'{"animation": {"file_id": "a", "file_unique_id": "au", "width": 100, "height": 100, "duration": 10}, "audio": {"file_id": "au1", "file_unique_id": "au1u", "duration": 30}, "document": {"file_id": "d", "file_unique_id": "du", "file_name": "test.pdf"}, "live_photo": {"file_id": "lp", "file_unique_id": "lpu", "width": 100, "height": 100, "duration": 5}, "location": {"latitude": 50.45, "longitude": 30.52}, "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}], "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "venue": {"location": {"latitude": 50.45, "longitude": 30.52}, "title": "Place", "address": "Addr"}, "video": {"file_id": "v", "file_unique_id": "vu", "width": 640, "height": 480, "duration": 30}, "link": {"url": "https://example.com", "shows_above_caption": true, "enhanced_smileys": true, "prefer_large_media": true}}') - result = types.PollMedia.de_json(json_dict) - assert isinstance(result.animation, types.Animation) - assert isinstance(result.audio, types.Audio) - assert isinstance(result.document, types.Document) - assert isinstance(result.live_photo, types.LivePhoto) - assert isinstance(result.location, types.Location) - assert isinstance(result.photo, list) - assert isinstance(result.sticker, types.Sticker) - assert isinstance(result.venue, types.Venue) - assert isinstance(result.video, types.Video) - assert isinstance(result.link, types.Link) - assert isinstance(result, types.PollMedia) - - -def test_json_richblockdivider(): - json_dict = json.loads(r'{"type": "divider"}') - result = types.RichBlock.de_json(json_dict) - assert isinstance(result, types.RichBlockDivider) - - -def test_json_sentwebappmessage(): - result = types.SentWebAppMessage.de_json({}) - assert isinstance(result, types.SentWebAppMessage) or result is None - assert hasattr(result, 'inline_message_id') - - -def test_json_suggestedpostdeclined(): - json_dict = json.loads(r'{"suggested_post_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "suggested"}, "comment": "declined reason"}') - result = types.SuggestedPostDeclined.de_json(json_dict) - assert isinstance(result.suggested_post_message, types.Message) - assert result.comment == 'declined reason' - assert isinstance(result, types.SuggestedPostDeclined) - - -def test_json_switchinlinequerychosenchat(): - json_dict = json.loads(r'{"query": "test", "allow_user_chats": true, "allow_bot_chats": true, "allow_group_chats": true, "allow_channel_chats": true}') - result = types.SwitchInlineQueryChosenChat.de_json(json_dict) - assert result.query == 'test' - assert result.allow_user_chats == True - assert result.allow_bot_chats == True - assert result.allow_group_chats == True - assert result.allow_channel_chats == True - assert isinstance(result, types.SwitchInlineQueryChosenChat) - - -def test_json_transactionpartnertelegramads(): - result = types.TransactionPartnerTelegramAds.de_json(None) - assert isinstance(result, types.TransactionPartnerTelegramAds) or result is None - - -def test_json_videochatstarted(): - result = types.VideoChatStarted.de_json({}) - assert isinstance(result, types.VideoChatStarted) or result is None - - -def test_json_voicechatstarted(): - result = types.VoiceChatStarted.de_json({}) - assert isinstance(result, types.VoiceChatStarted) or result is None - - -def test_json_writeaccessallowed(): - result = types.WriteAccessAllowed.de_json({'from_request': True, 'web_app_name': 'TestApp', 'from_attachment_menu': False}) - assert result.from_request == True - assert result.web_app_name == 'TestApp' - assert result.from_attachment_menu == False - assert isinstance(result, types.WriteAccessAllowed) - - -def test_json_acceptedgifttypes(): - json_dict = json.loads(r'{"unlimited_gifts": "test", "limited_gifts": "test", "unique_gifts": "test", "premium_subscription": "test", "gifts_from_channels": "test"}') - result = types.AcceptedGiftTypes.de_json(json_dict) - assert result.unlimited_gifts == 'test' - assert result.limited_gifts == 'test' - assert result.unique_gifts == 'test' - assert result.premium_subscription == 'test' - assert result.gifts_from_channels == 'test' - assert isinstance(result, types.AcceptedGiftTypes) - - -def test_json_copytextbutton(): - json_dict = json.loads(r'{"text": "Test"}') - result = types.CopyTextButton.de_json(json_dict) - assert result.text == 'Test' - assert isinstance(result, types.CopyTextButton) - - -def test_json_dice(): - json_dict = json.loads(r'{"value": "test", "emoji": "😀"}') - result = types.Dice.de_json(json_dict) - assert result.value == 'test' - assert result.emoji == '😀' - assert isinstance(result, types.Dice) - - -def test_json_richblocktablecell(): - json_dict = json.loads(r'{"align": "test", "valign": "test", "text": "Test", "is_header": true, "colspan": "test", "rowspan": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockTableCell.de_json(data) - assert result.align == 'test' - assert result.valign == 'test' - assert result.text == 'Test' - assert result.is_header == True - assert result.colspan == 'test' - assert result.rowspan == 'test' - assert isinstance(result, types.RichBlockTableCell) - - -def test_json_richtextbotcommand(): - json_dict = json.loads(r'{"type": "bot_command", "text": "Test", "bot_command": "test"}') - result = types.RichText.de_json(json_dict) - assert result.text == 'Test' - assert result.bot_command == 'test' - assert isinstance(result, types.RichTextBotCommand) - - -def test_json_richtextcashtag(): - json_dict = json.loads(r'{"type": "cashtag", "text": "Test", "cashtag": "test"}') - result = types.RichText.de_json(json_dict) - assert result.text == 'Test' - assert result.cashtag == 'test' - assert isinstance(result, types.RichTextCashtag) - - -def test_json_richtextcustomemoji(): - json_dict = json.loads(r'{"type": "custom_emoji", "custom_emoji_id": "test", "alternative_text": "test"}') - result = types.RichText.de_json(json_dict) - assert result.custom_emoji_id == 'test' - assert result.alternative_text == 'test' - assert isinstance(result, types.RichTextCustomEmoji) - - -def test_json_richtexthashtag(): - json_dict = json.loads(r'{"type": "hashtag", "text": "Test", "hashtag": "test"}') - result = types.RichText.de_json(json_dict) - assert result.text == 'Test' - assert result.hashtag == 'test' - assert isinstance(result, types.RichTextHashtag) - - -def test_json_richtextmathematicalexpression(): - json_dict = json.loads(r'{"type": "mathematical_expression", "expression": "test"}') - result = types.RichText.de_json(json_dict) - assert result.expression == 'test' - assert isinstance(result, types.RichTextMathematicalExpression) - - -def test_json_richtextmention(): - json_dict = json.loads(r'{"type": "mention", "text": "Test", "username": "test"}') - result = types.RichText.de_json(json_dict) - assert result.text == 'Test' - assert result.username == 'test' - assert isinstance(result, types.RichTextMention) - - -def test_json_richtextreference(): - json_dict = json.loads(r'{"type": "reference", "text": "Test", "name": "Test"}') - result = types.RichText.de_json(json_dict) - assert result.text == 'Test' - assert result.name == 'Test' - assert isinstance(result, types.RichTextReference) - - -def test_json_richtextreferencelink(): - json_dict = json.loads(r'{"type": "reference_link", "text": "Test", "reference_name": "test"}') - result = types.RichText.de_json(json_dict) - assert result.text == 'Test' - assert result.reference_name == 'test' - assert isinstance(result, types.RichTextReferenceLink) - - -def test_json_suggestedpostprice(): - json_dict = json.loads(r'{"currency": "en", "amount": 1}') - result = types.SuggestedPostPrice.de_json(json_dict) - assert result.currency == 'en' - assert result.amount == 1 - assert isinstance(result, types.SuggestedPostPrice) - - -def test_json_affiliateinfo(): - json_dict = json.loads(r'{"commission_per_mille": 1000, "amount": 100, "affiliate_user": {"id": 1, "is_bot": false, "first_name": "User"}, "affiliate_chat": {"id": -1001234567890, "type": "channel", "title": "Channel"}, "nanostar_amount": 10000000}') - result = types.AffiliateInfo.de_json(json_dict) - assert result.commission_per_mille == 1000 - assert result.amount == 100 - assert isinstance(result.affiliate_user, types.User) - assert isinstance(result.affiliate_chat, types.Chat) - assert result.nanostar_amount == 10000000 - assert isinstance(result, types.AffiliateInfo) - - -def test_json_backgroundfill(): - # BackgroundFill is abstract - test BackgroundFillSolid directly - json_dict = json.loads(r'{"type": "solid", "color": 123456}') - result = types.BackgroundFillSolid.de_json(json_dict) - assert isinstance(result, types.BackgroundFillSolid) - - -def test_json_backgroundfillfreeformgradient(): - json_dict = json.loads(r'{"type": "freeform_gradient", "colors": [123456, 654321, 111222]}') - result = types.BackgroundFillFreeformGradient.de_json(json_dict) - assert result.type == 'freeform_gradient' - assert isinstance(result.colors, list) - assert isinstance(result, types.BackgroundFillFreeformGradient) - - -def test_json_backgroundfillgradient(): - json_dict = json.loads(r'{"type": "gradient", "top_color": 123456, "bottom_color": 654321, "rotation_angle": 180}') - result = types.BackgroundFillGradient.de_json(json_dict) - assert result.type == 'gradient' - assert result.top_color == 123456 - assert result.bottom_color == 654321 - assert result.rotation_angle == 180 - assert isinstance(result, types.BackgroundFillGradient) - - -def test_json_backgroundfillsolid(): - json_dict = json.loads(r'{"type": "solid", "color": 123456}') - result = types.BackgroundFillSolid.de_json(json_dict) - assert result.type == 'solid' - assert result.color == 123456 - assert isinstance(result, types.BackgroundFillSolid) - - -def test_json_backgroundtype(): - # BackgroundType is abstract - test BackgroundTypeFill directly - json_dict = json.loads(r'{"type": "fill", "fill": {"type": "solid", "color": 123456}, "dark_theme_dimming": 0}') - result = types.BackgroundTypeFill.de_json(json_dict) - assert isinstance(result, types.BackgroundTypeFill) - - -def test_json_backgroundtypechattheme(): - json_dict = json.loads(r'{"type": "fill", "theme_name": "test"}') - result = types.BackgroundTypeChatTheme.de_json(json_dict) - assert result.type == 'fill' - assert result.theme_name == 'test' - assert isinstance(result, types.BackgroundTypeChatTheme) - - -def test_json_backgroundtypefill(): - json_dict = json.loads(r'{"type": "solid", "fill": {"type": "solid", "color": 123456}, "dark_theme_dimming": 0}') - result = types.BackgroundTypeFill.de_json(json_dict) - assert result.type == 'solid' - assert isinstance(result.fill, types.BackgroundFill) - assert result.dark_theme_dimming == 0 - assert isinstance(result, types.BackgroundTypeFill) - - -def test_json_backgroundtypepattern(): - json_dict = json.loads(r'{"type": "pattern", "document": {"file_id": "doc", "file_unique_id": "docu", "mime_type": "application/pdf", "file_name": "test.pdf"}, "fill": {"type": "solid", "color": 123456}, "intensity": 0, "is_inverted": true, "is_moving": true}') - result = types.BackgroundTypePattern.de_json(json_dict) - assert result.type == 'pattern' - assert isinstance(result.document, types.Document) - assert isinstance(result.fill, dict) or result.fill is None - assert result.intensity == 0 - assert result.is_inverted == True - assert result.is_moving == True - assert isinstance(result, types.BackgroundTypePattern) - - -def test_json_backgroundtypewallpaper(): - json_dict = json.loads(r'{"type": "wallpaper", "document": {"file_id": "doc", "file_unique_id": "docu", "mime_type": "application/pdf", "file_name": "test.pdf"}, "dark_theme_dimming": 0, "is_blurred": true, "is_moving": true}') - result = types.BackgroundTypeWallpaper.de_json(json_dict) - assert result.type == 'wallpaper' - assert isinstance(result.document, types.Document) - assert result.dark_theme_dimming == 0 - assert result.is_blurred == True - assert result.is_moving == True - assert isinstance(result, types.BackgroundTypeWallpaper) - - -def test_json_birthdate(): - json_dict = json.loads(r'{"day": "test", "month": "test", "year": 1990}') - result = types.Birthdate.de_json(json_dict) - assert result.day == 'test' - assert result.month == 'test' - assert result.year == 1990 - assert isinstance(result, types.Birthdate) - - -def test_json_botaccesssettings(): - json_dict = json.loads(r'{"is_access_restricted": false, "added_users": [{"id": 1, "is_bot": false, "first_name": "Test"}, {"id": 2, "is_bot": false, "first_name": "User2"}]}') - result = types.BotAccessSettings.de_json(json_dict) - assert result.is_access_restricted == False - assert isinstance(result.added_users, list) - assert len(result.added_users) == 2 - assert isinstance(result.added_users[0], types.User) - assert result.added_users[0].id == 1 - assert isinstance(result, types.BotAccessSettings) - - -def test_json_botsubscriptionupdated(): - json_dict = json.loads(r'{"user": {"id": 1, "is_bot": false, "first_name": "Test"}, "invoice_payload": "test_payload", "state": "default"}') - result = types.BotSubscriptionUpdated.de_json(json_dict) - assert isinstance(result.user, types.User) - assert result.invoice_payload == 'test_payload' - assert result.state == 'default' - assert isinstance(result, types.BotSubscriptionUpdated) - - -def test_json_businessconnection(): - json_dict = json.loads(r'{"id": "1", "user": {"id": 1, "is_bot": false, "first_name": "Test"}, "user_chat_id": 1, "date": 1682189507, "is_enabled": false, "rights": {"can_reply": true, "can_read_messages": true, "can_delete_outgoing_messages": false, "can_delete_all_messages": false, "can_edit_name": true, "can_edit_bio": false, "can_edit_profile_photo": true, "can_edit_username": false, "can_change_gift_settings": true, "can_view_gifts_and_stars": false, "can_convert_gifts_to_stars": true, "can_transfer_and_upgrade_gifts": false, "can_transfer_stars": true, "can_manage_stories": false}}') - result = types.BusinessConnection.de_json(json_dict) - assert result.id == '1' - assert isinstance(result.user, types.User) - assert result.user_chat_id == 1 - assert result.date == 1682189507 - assert result.is_enabled == False - assert isinstance(result.rights, types.BusinessBotRights) - assert result.rights.can_reply == True - assert result.rights.can_read_messages == True - assert result.rights.can_delete_outgoing_messages == False - assert result.rights.can_delete_all_messages == False - assert result.rights.can_edit_name == True - assert result.rights.can_edit_bio == False - assert result.rights.can_edit_profile_photo == True - assert result.rights.can_edit_username == False - assert result.rights.can_change_gift_settings == True - assert result.rights.can_view_gifts_and_stars == False - assert result.rights.can_convert_gifts_to_stars == True - assert result.rights.can_transfer_and_upgrade_gifts == False - assert result.rights.can_transfer_stars == True - assert result.rights.can_manage_stories == False - assert isinstance(result, types.BusinessConnection) - - -def test_json_businesslocation(): - json_dict = json.loads(r'{"address": "NY", "location": {"latitude": 50.45, "longitude": 30.52, "horizontal_accuracy": 1.5}}') - result = types.BusinessLocation.de_json(json_dict) - assert result.address == 'NY' - assert isinstance(result.location, types.Location) - assert result.location.latitude == 50.45 - assert result.location.longitude == 30.52 - assert result.location.horizontal_accuracy == 1.5 - assert isinstance(result, types.BusinessLocation) - - -def test_json_businessmessagesdeleted(): - json_dict = json.loads(r'{"business_connection_id": 1, "chat": {"id": 1, "type": "private", "title": "Test"}, "message_ids": "test"}') - result = types.BusinessMessagesDeleted.de_json(json_dict) - assert result.business_connection_id == 1 - assert isinstance(result.chat, types.Chat) - assert result.message_ids == 'test' - assert isinstance(result, types.BusinessMessagesDeleted) - - -def test_json_businessopeninghours(): - json_dict = json.loads(r'{"time_zone_name": "test", "opening_hours": [{"opening_minute": 0, "closing_minute": 60}]}') - result = types.BusinessOpeningHours.de_json(json_dict) - assert result.time_zone_name == 'test' - assert isinstance(result.opening_hours, list) - assert isinstance(result, types.BusinessOpeningHours) - - -def test_json_businessopeninghoursinterval(): - json_dict = json.loads(r'{"opening_minute": 0, "closing_minute": 60}') - result = types.BusinessOpeningHoursInterval.de_json(json_dict) - assert result.opening_minute == 0 - assert result.closing_minute == 60 - assert isinstance(result, types.BusinessOpeningHoursInterval) - - -def test_json_callbackquery(): - # json_string is internal field, not covered (like Message.options/json_string) - json_dict = json.loads(r'{"id": "cq1", "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "data": "test", "chat_instance": "ci1", "message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "Hello"}, "inline_message_id": "im1", "game_short_name": "game"}') - result = types.CallbackQuery.de_json(json_dict) - assert result.id == 'cq1' - assert isinstance(result.from_user, types.User) - assert result.data == 'test' - assert result.chat_instance == 'ci1' - assert isinstance(result.message, types.Message) - assert result.inline_message_id == 'im1' - assert result.game_short_name == 'game' - assert isinstance(result, types.CallbackQuery) - - -def test_json_chatbackground(): - json_dict = json.loads(r'{"type": {"type": "fill", "fill": {"type": "solid", "color": 123456}, "dark_theme_dimming": 0}}') - result = types.ChatBackground.de_json(json_dict) - assert isinstance(result.type, types.BackgroundTypeFill) or isinstance(result.type, dict) - assert isinstance(result, types.ChatBackground) - assert hasattr(result, 'type') - - -def test_json_chatboostadded(): - json_dict = json.loads(r'{"boost_count": "test"}') - result = types.ChatBoostAdded.de_json(json_dict) - assert result.boost_count == 'test' - assert isinstance(result, types.ChatBoostAdded) - - -def test_json_chatboostremoved(): - json_dict = json.loads(r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "boost_id": 1, "remove_date": 1682189507, "source": {"source": "premium", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}}') - result = types.ChatBoostRemoved.de_json(json_dict) - assert isinstance(result.chat, types.Chat) - assert result.boost_id == 1 - assert result.remove_date == 1682189507 - assert isinstance(result.source, types.ChatBoostSource) - assert isinstance(result, types.ChatBoostRemoved) - - -def test_json_chatboostsource(): - # ChatBoostSource is abstract - test ChatBoostSourcePremium directly - json_dict = json.loads(r'{"source": "premium", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}') - result = types.ChatBoostSourcePremium.de_json(json_dict) - assert isinstance(result, types.ChatBoostSourcePremium) - - -def test_json_chatboostsourcegiftcode(): - json_dict = json.loads(r'{"source": "gift_code", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}') - result = types.ChatBoostSourceGiftCode.de_json(json_dict) - assert result.source == 'gift_code' - assert isinstance(result.user, types.User) - assert isinstance(result, types.ChatBoostSourceGiftCode) - - -def test_json_chatboostsourcegiveaway(): - json_dict = json.loads(r'{"source": "giveaway", "giveaway_message_id": 1, "user": {"id": 1, "is_bot": false, "first_name": "Test"}, "is_unclaimed": false, "prize_star_count": 100}') - result = types.ChatBoostSourceGiveaway.de_json(json_dict) - assert result.source == 'giveaway' - assert result.giveaway_message_id == 1 - assert isinstance(result.user, types.User) - assert result.is_unclaimed == False - assert result.prize_star_count == 100 - assert isinstance(result, types.ChatBoostSourceGiveaway) - - -def test_json_chatboostsourcepremium(): - json_dict = json.loads(r'{"source": "premium", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}') - result = types.ChatBoostSourcePremium.de_json(json_dict) - assert result.source == 'premium' - assert isinstance(result.user, types.User) - assert isinstance(result, types.ChatBoostSourcePremium) - - -def test_json_chatboostupdated(): - json_dict = json.loads(r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "boost": {"boost_item_id": "b1", "add_date": 1682189507, "expiration_date": 1682275907}}') - result = types.ChatBoostUpdated.de_json(json_dict) - assert isinstance(result.chat, types.Chat) - assert isinstance(result.boost, types.ChatBoost) - assert isinstance(result.boost.boost_id, str) or result.boost.boost_id is None - assert isinstance(result.boost.add_date, int) - assert isinstance(result.boost.expiration_date, int) - assert isinstance(result, types.ChatBoostUpdated) - - -def test_json_chatjoinrequest(): - json_dict = json.loads(r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "user_chat_id": 1, "date": 1682189507, "bio": "Hello", "invite_link": {"invite_link": "https://t.me/joinchat/ABC", "creator": {"id": 1, "is_bot": false, "first_name": "Test"}, "is_primary": true, "is_revoked": false, "creates_join_request": false}, "query_id": "query123"}') - result = types.ChatJoinRequest.de_json(json_dict) - assert isinstance(result.chat, types.Chat) - assert isinstance(result.from_user, types.User) - assert result.from_user.id == 1 - assert result.from_user.first_name == 'Test' - assert result.user_chat_id == 1 - assert result.date == 1682189507 - assert result.bio == 'Hello' - assert isinstance(result.invite_link, types.ChatInviteLink) - assert result.query_id == 'query123' - assert isinstance(result, types.ChatJoinRequest) - - -def test_json_chatfullinfo(): - json_dict = json.loads(r'{"id": 1, "type": "private", "title": "Test Chat", "username": "testchat", "first_name": "John", "last_name": "Doe", "photo": {"small_file_id": "s", "small_file_unique_id": "su", "big_file_id": "b", "big_file_unique_id": "bu"}, "bio": "bio text", "has_private_forwards": true, "description": "desc", "pinned_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}}, "permissions": {"can_send_messages": true, "can_send_audios": true, "can_send_documents": true, "can_send_photos": true, "can_send_videos": true, "can_send_video_notes": true, "can_send_voice_notes": true, "can_send_polls": true, "can_send_other_messages": true, "can_add_web_page_previews": true, "can_change_info": true, "can_invite_users": true, "can_pin_messages": true, "can_manage_topics": true}, "slow_mode_delay": 30, "message_auto_delete_time": 86400, "has_protected_content": true, "sticker_set_name": "sticker_set", "can_set_sticker_set": false, "linked_chat_id": 2, "location": {"chat": {"id": 1, "type": "supergroup", "title": "Loc"}, "location": {"latitude": 50.45, "longitude": 30.52}, "address": "Main St"}, "join_to_send_messages": false, "join_by_request": true, "has_restricted_voice_and_video_messages": false, "is_forum": true, "max_reaction_count": 10, "active_usernames": ["test"], "emoji_status_custom_emoji_id": "custom_emoji", "has_hidden_members": false, "has_aggressive_anti_spam_enabled": false, "emoji_status_expiration_date": 1682275907, "available_reactions": ["emoji", "custom_emoji"], "accent_color_id": 1, "background_custom_emoji_id": "bg_emoji", "profile_accent_color_id": 2, "profile_background_custom_emoji_id": "profile_bg", "has_visible_history": true, "unrestrict_boost_count": 5, "custom_emoji_sticker_set_name": "custom_stickers", "personal_chat": {"id": 3, "type": "private", "title": "Personal"}, "birthdate": {"day": "15", "month": "6"}, "can_send_paid_media": true, "is_direct_messages": true, "parent_chat": {"id": 4, "type": "supergroup", "title": "Parent"}, "rating": {"level": "test", "rating": "test", "current_level_rating": "test"}, "paid_message_star_count": 5, "invite_link": "https://t.me/joinchat/ABC", "business_intro": {"title": "B", "description": "D"}, "business_location": {"address": "NY", "has_active_address": true}, "business_opening_hours": {"time_zone_name": "UTC", "opening_hours": [{"opening_minute": 540, "closing_minute": 1020, "day_of_week": 1, "is_recurring": true}]}, "accepted_gift_types": {"unlimited_gifts": false, "limited_gifts": false, "unique_gifts": true, "premium_subscription": false, "gifts_from_channels": false}, "first_profile_audio": {"file_id": "fa1", "file_unique_id": "fa1u", "duration": 30, "mime_type": "audio/ogg"}, "unique_gift_colors": {"model_custom_emoji_id": 1, "symbol_custom_emoji_id": 1, "light_theme_main_color": 333333, "light_theme_other_colors": [444444], "dark_theme_main_color": 555555, "dark_theme_other_colors": [666666]}, "guard_bot": {"id": 2, "is_bot": true, "first_name": "GuardBot"}, "community": {"id": 5, "name": "Community"}}') - result = types.ChatFullInfo.de_json(json_dict) - assert result.id == 1 - assert result.type == 'private' - assert result.title == 'Test Chat' - assert result.username == 'testchat' - assert result.first_name == 'John' - assert result.last_name == 'Doe' - assert isinstance(result.photo, types.ChatPhoto) - assert result.bio == 'bio text' - assert result.has_private_forwards == True - assert result.description == 'desc' - assert result.invite_link == "https://t.me/joinchat/ABC" - assert isinstance(result.pinned_message, types.Message) - assert isinstance(result.permissions, types.ChatPermissions) - assert result.slow_mode_delay == 30 - assert result.message_auto_delete_time == 86400 - assert result.has_protected_content == True - assert result.sticker_set_name == 'sticker_set' - assert result.can_set_sticker_set == False - assert result.linked_chat_id == 2 - assert isinstance(result.location, types.ChatLocation) - assert result.join_to_send_messages == False - assert result.join_by_request == True - assert result.has_restricted_voice_and_video_messages == False - assert result.is_forum == True - assert result.max_reaction_count == 10 - assert result.active_usernames == ['test'] - assert result.emoji_status_custom_emoji_id == 'custom_emoji' - assert result.has_hidden_members == False - assert result.has_aggressive_anti_spam_enabled == False - assert result.emoji_status_expiration_date == 1682275907 - assert isinstance(result.available_reactions, list) - assert result.accent_color_id == 1 - assert result.background_custom_emoji_id == 'bg_emoji' - assert result.profile_accent_color_id == 2 - assert result.profile_background_custom_emoji_id == 'profile_bg' - assert result.has_visible_history == True - assert result.unrestrict_boost_count == 5 - assert result.custom_emoji_sticker_set_name == 'custom_stickers' - assert isinstance(result.business_intro, types.BusinessIntro) - assert isinstance(result.business_location, types.BusinessLocation) - assert isinstance(result.business_opening_hours, types.BusinessOpeningHours) - assert isinstance(result.personal_chat, types.Chat) - assert isinstance(result.birthdate, types.Birthdate) - assert result.can_send_paid_media == True - assert isinstance(result.accepted_gift_types, types.AcceptedGiftTypes) - assert result.is_direct_messages == True - assert isinstance(result.parent_chat, types.Chat) - assert isinstance(result.rating, types.UserRating) - assert result.paid_message_star_count == 5 - assert isinstance(result.unique_gift_colors, types.UniqueGiftColors) - assert isinstance(result.first_profile_audio, types.Audio) - assert isinstance(result.guard_bot, types.User) - assert isinstance(result.community, types.Community) - assert isinstance(result, types.ChatFullInfo) - - -def test_json_chatmember(): - # ChatMember is abstract - test ChatMemberMember directly - json_dict = json.loads(r'{"status": "member", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}') - result = types.ChatMemberMember.de_json(json_dict) - assert isinstance(result.user, types.User) - assert result.status == 'member' - assert isinstance(result, types.ChatMemberMember) - - -def test_json_chatmemberupdated(): - json_dict = json.loads(r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "date": 1682189507, "old_chat_member": {"user": {"id": 1, "is_bot": false, "first_name": "Test"}, "status": "member"}, "new_chat_member": {"user": {"id": 1, "is_bot": false, "first_name": "Test"}, "status": "member"}, "via_join_request": true, "via_chat_folder_invite_link": true, "invite_link": {"invite_link": "https://t.me/joinchat/ABC", "creator": {"id": 1, "is_bot": false, "first_name": "Test"}, "creates_join_request": false, "is_primary": true, "is_revoked": false}}') - result = types.ChatMemberUpdated.de_json(json_dict) - assert isinstance(result.chat, types.Chat) - assert isinstance(result.from_user, types.User) - assert result.date == 1682189507 - assert isinstance(result.old_chat_member, types.ChatMember) - assert isinstance(result.new_chat_member, types.ChatMember) - assert isinstance(result.invite_link, types.ChatInviteLink) - assert result.invite_link.invite_link == 'https://t.me/joinchat/ABC' - assert isinstance(result.invite_link.creator, types.User) - assert result.invite_link.creates_join_request == False - assert result.invite_link.is_primary == True - assert result.invite_link.is_revoked == False - assert result.via_join_request == True - assert result.via_chat_folder_invite_link == True - assert isinstance(result, types.ChatMemberUpdated) - - -def test_json_chatownerchanged(): - json_dict = json.loads(r'{"new_owner": {"id": 1, "is_bot": false, "first_name": "Test"}}') - result = types.ChatOwnerChanged.de_json(json_dict) - assert isinstance(result.new_owner, types.User) - assert isinstance(result, types.ChatOwnerChanged) - - -def test_json_chatphoto(): - json_dict = json.loads(r'{"small_file_id": 1, "small_file_unique_id": 1, "big_file_id": 1, "big_file_unique_id": 1}') - result = types.ChatPhoto.de_json(json_dict) - assert result.small_file_id == 1 - assert result.small_file_unique_id == 1 - assert result.big_file_id == 1 - assert result.big_file_unique_id == 1 - assert isinstance(result, types.ChatPhoto) - - -def test_json_checklist(): - json_dict = json.loads(r'{"title": "test", "tasks": [{"id": 1, "text": "test", "is_checked": false}], "others_can_add_tasks": true, "others_can_mark_tasks_as_done": true, "title_entities": [{"type": "bold", "offset": 0, "length": 4}]}') - result = types.Checklist.de_json(json_dict) - assert result.title == 'test' - assert isinstance(result.tasks, list) - assert isinstance(result.title_entities, list) - assert result.others_can_add_tasks == True - assert result.others_can_mark_tasks_as_done == True - assert isinstance(result, types.Checklist) - - -def test_json_checklisttask(): - json_dict = json.loads(r'{"id": 1, "text": {"type": "bold", "text": "Task text"}, "text_entities": [{"type": "bold", "offset": 0, "length": 9}], "completed_by_user": {"id": 1, "is_bot": false, "first_name": "User"}, "completed_by_chat": {"id": 1, "type": "private"}, "completion_date": 1682189507}') - result = types.ChecklistTask.de_json(json_dict) - assert result.id == 1 - assert result.text == {"type": "bold", "text": "Task text"} - assert isinstance(result.text_entities, list) - assert isinstance(result.completed_by_user, types.User) - assert isinstance(result.completed_by_chat, types.Chat) - assert result.completion_date == 1682189507 - assert isinstance(result, types.ChecklistTask) - - -def test_json_checklisttasksadded(): - json_dict = json.loads(r'{"tasks": [{"id": "t1", "text": "task"}], "checklist_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "checklist"}}') - result = types.ChecklistTasksAdded.de_json(json_dict) - assert isinstance(result.tasks, list) - assert isinstance(result.checklist_message, types.Message) - assert isinstance(result, types.ChecklistTasksAdded) - - -def test_json_choseninlineresult(): - json_dict = json.loads(r'{"result_id": "res1", "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "query": "test", "location": {"latitude": 50.45, "longitude": 30.52, "horizontal_accuracy": 1.5, "live_period": 3600}, "inline_message_id": "im1"}') - result = types.ChosenInlineResult.de_json(json_dict) - assert result.result_id == 'res1' - assert isinstance(result.from_user, types.User) - assert result.query == 'test' - assert isinstance(result.location, types.Location) - assert result.inline_message_id == 'im1' - assert isinstance(result, types.ChosenInlineResult) - - -def test_json_community(): - json_dict = json.loads(r'{"id": 1, "name": "test"}') - result = types.Community.de_json(json_dict) - assert result.id == 1 - assert result.name == 'test' - assert isinstance(result, types.Community) - - -def test_json_directmessagepricechanged(): - json_dict = json.loads(r'{"are_direct_messages_enabled": true, "direct_message_star_count": 5}') - result = types.DirectMessagePriceChanged.de_json(json_dict) - assert result.are_direct_messages_enabled == True - assert result.direct_message_star_count == 5 - assert isinstance(result, types.DirectMessagePriceChanged) - - -def test_json_directmessagestopic(): - json_dict = json.loads(r'{"topic_id": 1, "user": {"id": 1, "is_bot": false, "first_name": "Test"}}') - result = types.DirectMessagesTopic.de_json(json_dict) - assert result.topic_id == 1 - assert isinstance(result.user, types.User) - assert result.user.id == 1 - assert result.user.first_name == 'Test' - assert isinstance(result, types.DirectMessagesTopic) - - -def test_json_externalreplyinfo(): - json_dict = json.loads(r'{"origin": {"type": "user", "date": 1682189507, "sender_user": {"id": 1, "is_bot": false, "first_name": "Test"}}, "chat": {"id": 1, "type": "private"}, "message_id": 42, "link_preview_options": {"url": "https://example.com", "shows_above_caption": true, "enhanced_smileys": true, "prefer_large_media": true}, "animation": {"file_id": "anim", "file_unique_id": "aniu", "width": 100, "height": 100, "duration": 10}, "audio": {"file_id": "au1", "file_unique_id": "au1u", "duration": 30}, "document": {"file_id": "doc1", "file_unique_id": "doc1u", "file_name": "test.pdf"}, "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}], "sticker": {"file_id": "st1", "file_unique_id": "st1u", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "story": {"chat": {"id": 1, "type": "private"}, "id": 1}, "video": {"file_id": "v1", "file_unique_id": "v1u", "width": 640, "height": 480, "duration": 30}, "video_note": {"file_id": "vn1", "file_unique_id": "vn1u", "duration": 10, "length": 512}, "voice": {"file_id": "vo1", "file_unique_id": "vo1u", "duration": 10}, "has_media_spoiler": true, "contact": {"phone_number": "+123", "first_name": "John"}, "dice": {"emoji": "🎲", "value": 5}, "game": {"id": "g1", "title": "Game", "description": "Test", "text": "Play", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}, "giveaway": {"chats": [{"id": 1, "type": "private"}], "winners_selection_date": 1682189507, "winner_count": 1, "only_new_members": false, "has_public_winners": false, "prize_description": "Prize", "premium_subscription_month_count": 0, "prize_star_count": 0}, "giveaway_winners": {"chat": {"id": 1, "type": "private"}, "giveaway_message_id": 1, "winners_selection_date": 1682189507, "winner_count": 1, "winners": [{"id": 1, "is_bot": false, "first_name": "Test"}], "additional_chat_count": 0, "premium_subscription_month_count": 0, "unclaimed_prize_count": 0, "only_new_members": false, "was_refunded": false, "prize_description": "", "prize_star_count": 0}, "invoice": {"title": "Test", "description": "Desc", "start_parameter": "sp", "currency": "USD", "total_amount": 100, "invoice_payload": "payload", "shipping_option_id": "opt", "order_info": {"user_name": "User", "user_phone": "+123", "shipping_address": {"country_code": "US", "state": "CA", "city": "SJ", "street_line1": "123", "street_line2": "", "post_code": "95113"}}, "telegram_payment_charge_id": "chg1", "provider_payment_charge_id": "chg2"}, "location": {"latitude": 50.45, "longitude": 30.52}, "poll": {"id": "p1", "question": "test question", "options": [{"text": "Opt1", "persistent_id": "opt1"}], "type": "quiz"}, "venue": {"location": {"latitude": 50.45, "longitude": 30.52}, "title": "Place", "address": "Addr"}, "paid_media": {"star_count": 10, "paid_media": [{"type": "photo", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}]}, "live_photo": {"file_id": "lp1", "file_unique_id": "lp1u", "width": 100, "height": 100, "duration": 5}, "checklist": {"title": "Check", "tasks": [{"id": "t1", "text": "Task1", "status": "pending"}]}}') - result = types.ExternalReplyInfo.de_json(json_dict) - assert isinstance(result.origin, types.MessageOrigin) - assert isinstance(result.chat, types.Chat) - assert result.message_id == 42 - assert isinstance(result.link_preview_options, types.LinkPreviewOptions) - assert isinstance(result.animation, types.Animation) - assert isinstance(result.audio, types.Audio) - assert isinstance(result.document, types.Document) - assert isinstance(result.photo, list) - assert isinstance(result.sticker, types.Sticker) - assert isinstance(result.story, types.Story) - assert isinstance(result.video, types.Video) - assert isinstance(result.video_note, types.VideoNote) - assert isinstance(result.voice, types.Voice) - assert result.has_media_spoiler == True - assert isinstance(result.contact, types.Contact) - assert isinstance(result.dice, types.Dice) - assert isinstance(result.game, types.Game) - assert isinstance(result.giveaway, types.Giveaway) - assert isinstance(result.giveaway.chats, list) - assert result.giveaway.winner_count == 1 - assert isinstance(result.giveaway_winners, types.GiveawayWinners) - assert isinstance(result.invoice, types.Invoice) - assert isinstance(result.location, types.Location) - assert isinstance(result.poll, types.Poll) - assert result.poll.id == 'p1' - assert result.poll.question == 'test question' - assert isinstance(result.poll.options, list) - assert result.poll.type == 'quiz' - assert isinstance(result.venue, types.Venue) - assert isinstance(result.paid_media, types.PaidMediaInfo) - assert isinstance(result.live_photo, types.LivePhoto) - assert isinstance(result.checklist, types.Checklist) - assert isinstance(result, types.ExternalReplyInfo) - - -def test_json_file(): - json_dict = json.loads(r'{"file_id": "test_file_id", "file_unique_id": "test_unique_id", "file_size": 1024, "file_path": "docs/test.pdf"}') - result = types.File.de_json(json_dict) - assert result.file_id == 'test_file_id' - assert result.file_unique_id == 'test_unique_id' - assert result.file_size == 1024 - assert result.file_path == 'docs/test.pdf' - assert isinstance(result, types.File) - - -def test_json_forumtopiccreated(): - json_dict = json.loads(r'{"name": "test", "icon_color": 4294967295, "icon_custom_emoji_id": "custom_emoji", "is_name_implicit": true}') - result = types.ForumTopicCreated.de_json(json_dict) - assert result.name == 'test' - assert result.icon_color == 4294967295 - assert result.icon_custom_emoji_id == 'custom_emoji' - assert result.is_name_implicit == True - assert isinstance(result, types.ForumTopicCreated) - - -def test_json_game(): - json_dict = json.loads(r'{"id": "1", "title": "test", "description": "test", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}], "text": "game text", "animation": {"file_id": "anim", "file_unique_id": "aniu", "width": 100, "height": 100, "duration": 10}, "text_entities": [{"type": "bold", "offset": 0, "length": 4}]}') - result = types.Game.de_json(json_dict) - assert result.title == 'test' - assert result.description == 'test' - assert isinstance(result.photo, list) - assert result.text == 'game text' - assert isinstance(result.text_entities, list) - assert isinstance(result.animation, types.Animation) - assert isinstance(result, types.Game) - - -def test_json_gamehighscore(): - json_dict = json.loads(r'{"position": 0, "user": {"id": 1, "is_bot": false, "first_name": "Test"}, "score": 1}') - result = types.GameHighScore.de_json(json_dict) - assert result.position == 0 - assert isinstance(result.user, types.User) - assert result.score == 1 - assert isinstance(result, types.GameHighScore) - - -def test_json_giveaway(): - json_dict = json.loads(r'{"chats": [{"id": 1, "type": "private", "title": "Test"}], "winners_selection_date": 1682189507, "winner_count": 1, "only_new_members": true, "has_public_winners": false, "prize_description": "Prize", "country_codes": ["US", "GB"], "premium_subscription_month_count": 3, "prize_star_count": 100}') - result = types.Giveaway.de_json(json_dict) - assert isinstance(result.chats, list) - assert result.winners_selection_date == 1682189507 - assert result.winner_count == 1 - assert result.only_new_members == True - assert result.has_public_winners == False - assert result.prize_description == 'Prize' - assert isinstance(result.country_codes, list) - assert result.premium_subscription_month_count == 3 - assert result.prize_star_count == 100 - assert isinstance(result, types.Giveaway) - - -def test_json_giveawaycompleted(): - json_dict = json.loads(r'{"winner_count": 1, "unclaimed_prize_count": 5, "giveaway_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "giveaway"}, "is_star_giveaway": true}') - result = types.GiveawayCompleted.de_json(json_dict) - assert result.winner_count == 1 - assert result.unclaimed_prize_count == 5 - assert isinstance(result.giveaway_message, types.Message) - assert result.is_star_giveaway == True - assert isinstance(result, types.GiveawayCompleted) - - -def test_json_giveawaywinners(): - json_dict = json.loads(r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "giveaway_message_id": 1, "winners_selection_date": 1682189507, "winner_count": 1, "winners": [{"id": 1, "is_bot": false, "first_name": "Test"}], "additional_chat_count": 5, "premium_subscription_month_count": 3, "unclaimed_prize_count": 10, "only_new_members": true, "was_refunded": false, "prize_description": "Prize desc", "prize_star_count": 100}') - result = types.GiveawayWinners.de_json(json_dict) - assert isinstance(result.chat, types.Chat) - assert result.giveaway_message_id == 1 - assert result.winners_selection_date == 1682189507 - assert result.winner_count == 1 - assert isinstance(result.winners, list) - assert result.additional_chat_count == 5 - assert result.premium_subscription_month_count == 3 - assert result.unclaimed_prize_count == 10 - assert result.only_new_members == True - assert result.was_refunded == False - assert result.prize_description == 'Prize desc' - assert result.prize_star_count == 100 - assert isinstance(result, types.GiveawayWinners) - - -def test_json_groupchat(): - json_dict = json.loads(r'{"id": 1, "title": "test"}') - result = types.GroupChat.de_json(json_dict) - assert result.id == 1 - assert result.title == 'test' - assert isinstance(result, types.GroupChat) - - -def test_json_inaccessiblemessage(): - json_dict = json.loads(r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "message_id": 1, "date": 1682189507}') - result = types.InaccessibleMessage.de_json(json_dict) - assert isinstance(result.chat, types.Chat) - assert result.message_id == 1 - assert result.date == 1682189507 - assert isinstance(result, types.InaccessibleMessage) - - -def test_json_inlinequery(): - json_dict = json.loads(r'{"id": "iq1", "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "query": "test", "offset": "off1", "chat_type": "private", "location": {"latitude": 50.45, "longitude": 30.52, "horizontal_accuracy": 1.5, "live_period": 3600}}') - result = types.InlineQuery.de_json(json_dict) - assert result.id == 'iq1' - assert isinstance(result.from_user, types.User) - assert result.query == 'test' - assert result.offset == 'off1' - assert result.chat_type == 'private' - assert isinstance(result.location, types.Location) - assert isinstance(result, types.InlineQuery) - - -def test_json_invoice(): - json_dict = json.loads(r'{"title": "test", "description": "test", "start_parameter": "test_sp", "currency": "test", "total_amount": 1}') - result = types.Invoice.de_json(json_dict) - assert result.title == 'test' - assert result.description == 'test' - assert result.start_parameter == 'test_sp' - assert result.currency == 'test' - assert result.total_amount == 1 - assert isinstance(result, types.Invoice) - - -def test_json_jsondeserializable(): - # JsonDeserializable is abstract base class, skip - pass - - -def test_json_link(): - json_dict = json.loads(r'{"url": "https://example.com"}') - result = types.Link.de_json(json_dict) - assert result.url == 'https://example.com' - assert isinstance(result, types.Link) - - -def test_json_livephoto(): - json_dict = json.loads(r'{"file_id": "test_file_id", "file_unique_id": "test_unique_id", "width": 100, "height": 100, "duration": 30, "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}], "mime_type": "image/jpeg", "file_size": 20480}') - result = types.LivePhoto.de_json(json_dict) - assert result.file_id == 'test_file_id' - assert result.file_unique_id == 'test_unique_id' - assert result.width == 100 - assert result.height == 100 - assert result.duration == 30 - assert isinstance(result.photo, list) - assert result.mime_type == 'image/jpeg' - assert result.file_size == 20480 - assert isinstance(result, types.LivePhoto) - - -def test_json_managedbotcreated(): - json_dict = json.loads(r'{"bot": {"id": 1, "is_bot": true, "first_name": "Bot"}}') - result = types.ManagedBotCreated.de_json(json_dict) - assert isinstance(result, types.ManagedBotCreated) - assert hasattr(result, 'bot') - - -def test_json_managedbotupdated(): - json_dict = json.loads(r'{"user": {"id": 1, "is_bot": false, "first_name": "Test"}, "bot": {"id": 2, "is_bot": true, "first_name": "Bot"}}') - result = types.ManagedBotUpdated.de_json(json_dict) - assert isinstance(result.user, types.User) - assert result.user.id == 1 - assert isinstance(result.bot, types.User) - assert result.bot.id == 2 - assert isinstance(result, types.ManagedBotUpdated) - - -def test_json_menubutton(): - # MenuButton dispatches on type - test concrete subclass - json_dict = json.loads(r'{"type": "default"}') - result = types.MenuButtonDefault.de_json(json_dict) - assert isinstance(result, types.MenuButtonDefault) - - -def test_json_messageautodeletetimerchanged(): - json_dict = json.loads(r'{"message_auto_delete_time": 60}') - result = types.MessageAutoDeleteTimerChanged.de_json(json_dict) - assert result.message_auto_delete_time == 60 - assert isinstance(result, types.MessageAutoDeleteTimerChanged) - - -def test_json_messageid(): - json_dict = json.loads(r'{"message_id": 1}') - result = types.MessageID.de_json(json_dict) - assert isinstance(result, types.MessageID) - - -def test_json_messageorigin(): - # MessageOrigin is abstract - test MessageOriginUser directly - json_dict = json.loads(r'{"type": "user", "date": 1682189507, "sender_user": {"id": 1, "is_bot": false, "first_name": "Test"}}') - result = types.MessageOriginUser.de_json(json_dict) - assert result.type == 'user' - assert result.date == 1682189507 - assert isinstance(result.sender_user, types.User) - assert result.sender_user.id == 1 - assert result.sender_user.first_name == 'Test' - assert isinstance(result, types.MessageOriginUser) - - -def test_json_messagereactioncountupdated(): - json_dict = json.loads(r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "message_id": 1, "date": 1682189507, "reactions": [{"type": {"type": "emoji", "emoji": "\u2764\ufe0f"}, "total_count": 5}]}') - result = types.MessageReactionCountUpdated.de_json(json_dict) - assert isinstance(result.chat, types.Chat) - assert result.message_id == 1 - assert result.date == 1682189507 - assert isinstance(result.reactions, list) - assert isinstance(result, types.MessageReactionCountUpdated) - - -def test_json_messagereactionupdated(): - json_dict = json.loads(r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "message_id": 1, "date": 1682189507, "old_reaction": [{"type": "emoji", "emoji": "\u0001f600"}], "new_reaction": [{"type": "emoji", "emoji": "\u0001f600"}], "user": {"id": 1, "is_bot": false, "first_name": "Test"}, "actor_chat": {"id": -1, "type": "channel", "title": "Channel"}}') - result = types.MessageReactionUpdated.de_json(json_dict) - assert isinstance(result.chat, types.Chat) - assert result.message_id == 1 - assert result.date == 1682189507 - assert isinstance(result.old_reaction, list) - assert isinstance(result.new_reaction, list) - assert isinstance(result.user, types.User) - assert isinstance(result.actor_chat, types.Chat) - assert isinstance(result, types.MessageReactionUpdated) - - -def test_json_ownedgift(): - # OwnedGift is abstract - test OwnedGiftRegular directly - json_dict = json.loads(r'{"type": "regular", "gift": {"id": 1, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100}}') - result = types.OwnedGiftRegular.de_json(json_dict) - assert result.type == 'regular' - assert isinstance(result, types.OwnedGiftRegular) - - -def test_json_ownedgiftregular(): - json_dict = json.loads(r'{"type": "regular", "gift": {"id": 1, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100}, "owned_gift_id": "og_123", "sender_user": {"id": 1, "is_bot": false, "first_name": "Sender"}, "send_date": 1682189507, "text": {"type": "bold", "text": "Gift text"}, "entities": [{"type": "bold", "offset": 0, "length": 4}], "is_private": false, "is_saved": false, "can_be_upgraded": true, "was_refunded": false, "convert_star_count": 50, "prepaid_upgrade_star_count": 100, "is_upgrade_separate": false, "unique_gift_number": 42}') - result = types.OwnedGiftRegular.de_json(json_dict) - assert result.type == 'regular' - assert isinstance(result.gift, types.Gift) - assert result.owned_gift_id == 'og_123' - assert isinstance(result.sender_user, types.User) - assert result.send_date == 1682189507 - assert isinstance(result.text, dict) - assert isinstance(result.entities, list) - assert result.is_private == False - assert result.is_saved == False - assert result.can_be_upgraded == True - assert result.was_refunded == False - assert result.convert_star_count == 50 - assert result.prepaid_upgrade_star_count == 100 - assert result.is_upgrade_separate == False - assert result.unique_gift_number == 42 - assert isinstance(result, types.OwnedGiftRegular) - - -def test_json_ownedgiftunique(): - json_dict = json.loads(r'{"type": "unique", "gift": {"base_name": "test", "name": "test", "number": 1, "model": {"name": "m", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "symbol": {"name": "s", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "backdrop": {"name": "b", "colors": {"center_color": 123456, "edge_color": 654321, "symbol_color": 111111, "text_color": 222222}, "rarity_per_mille": 1000}, "gift_id": 1}, "gift_id": 1, "owned_gift_id": "og_456", "sender_user": {"id": 2, "is_bot": false, "first_name": "Sender"}, "send_date": 1682189507, "is_saved": false, "can_be_transferred": true, "transfer_star_count": 50, "next_transfer_date": 1704067200}') - result = types.OwnedGiftUnique.de_json(json_dict) - assert result.type == 'unique' - assert isinstance(result.gift, types.UniqueGift) - assert result.owned_gift_id == 'og_456' - assert isinstance(result.sender_user, types.User) - assert result.send_date == 1682189507 - assert result.is_saved == False - assert result.can_be_transferred == True - assert result.transfer_star_count == 50 - assert result.next_transfer_date == 1704067200 - assert isinstance(result, types.OwnedGiftUnique) - - -def test_json_ownedgifts(): - json_dict = json.loads(r'{"total_count": 1, "gifts": [{"type": "regular", "gift": {"id": 1, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100}}], "next_offset": "offset123"}') - result = types.OwnedGifts.de_json(json_dict) - assert result.total_count == 1 - assert isinstance(result.gifts, list) - assert result.next_offset == 'offset123' - assert isinstance(result, types.OwnedGifts) - - -def test_json_paidmedia(): - # PaidMedia is abstract - test PaidMediaPhoto directly - json_dict = json.loads(r'{"type": "photo", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}') - result = types.PaidMediaPhoto.de_json(json_dict) - assert isinstance(result, types.PaidMediaPhoto) - - -def test_json_paidmediainfo(): - json_dict = json.loads(r'{"star_count": 100, "paid_media": [{"type": "photo", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}]}') - result = types.PaidMediaInfo.de_json(json_dict) - assert result.star_count == 100 - assert isinstance(result.paid_media, list) - assert isinstance(result, types.PaidMediaInfo) - - -def test_json_paidmedialivephoto(): - json_dict = json.loads(r'{"type": "live_photo", "live_photo": {"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100, "duration": 10}}') - result = types.PaidMediaLivePhoto.de_json(json_dict) - assert result.type == 'live_photo' - assert isinstance(result.live_photo, types.LivePhoto) - assert isinstance(result, types.PaidMediaLivePhoto) - - -def test_json_paidmediaphoto(): - json_dict = json.loads(r'{"type": "photo", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}') - result = types.PaidMediaPhoto.de_json(json_dict) - assert result.type == 'photo' - assert isinstance(result.photo, list) - assert isinstance(result, types.PaidMediaPhoto) - - -def test_json_paidmediapreview(): - json_dict = json.loads(r'{"type": "default", "width": 640, "height": 480, "duration": 30}') - result = types.PaidMediaPreview.de_json(json_dict) - assert result.type == 'default' - assert result.width == 640 - assert result.height == 480 - assert result.duration == 30 - assert isinstance(result, types.PaidMediaPreview) - - -def test_json_paidmediapurchased(): - json_dict = json.loads(r'{"from_user": {"id": 1, "is_bot": false, "first_name": "Test"}, "paid_media_payload": "test"}') - result = types.PaidMediaPurchased.de_json(json_dict) - assert isinstance(result.from_user, types.User) - assert result.paid_media_payload == 'test' - assert isinstance(result, types.PaidMediaPurchased) - - -def test_json_paidmediavideo(): - json_dict = json.loads(r'{"type": "video", "video": {"file_id": "v", "file_unique_id": "vu", "width": 640, "height": 480, "duration": 30}}') - result = types.PaidMediaVideo.de_json(json_dict) - assert result.type == 'video' - assert isinstance(result.video, types.Video) - assert isinstance(result, types.PaidMediaVideo) - - -def test_json_paidmessagepricechanged(): - json_dict = json.loads(r'{"paid_message_star_count": 1}') - result = types.PaidMessagePriceChanged.de_json(json_dict) - assert isinstance(result, types.PaidMessagePriceChanged) - assert hasattr(result, 'paid_message_star_count') - - -def test_json_poll(): - # Poll.poll_type is deprecated in Telegram API, not covered - json_dict = json.loads(r'{"id": "poll1", "question": "test question", "options": [{"text": "Opt1", "persistent_id": "opt1"}], "total_voter_count": 10, "is_closed": false, "is_anonymous": true, "type": "quiz", "allows_multiple_answers": false, "explanation": "explanation text", "explanation_entities": [{"type": "bold", "offset": 0, "length": 4}], "open_period": 3600, "close_date": 1682193107, "question_entities": [{"type": "bold", "offset": 0, "length": 5}], "correct_option_ids": [0], "allows_revoting": true, "description": "poll desc", "description_entities": [{"type": "italic", "offset": 0, "length": 9}], "members_only": true, "country_codes": ["US", "GB"], "explanation_media": {"file_id": "em1", "file_unique_id": "emu1", "mime_type": "image/jpeg", "file_name": "media.jpg"}}') - result = types.Poll.de_json(json_dict) - # __init__ param is "poll_id" but de_json sets "id" attribute (from JSON "id" key) - # Use Poll.id, NOT Poll.poll_id - assert result.id == "poll1" - assert result.question == "test question" - assert isinstance(result.options, list) - assert result.total_voter_count == 10 - assert result.is_closed == False - assert result.is_anonymous == True - assert result.type == "quiz" - assert result.allows_multiple_answers == False - assert result.explanation == "explanation text" - assert isinstance(result.explanation_entities, list) - assert result.open_period == 3600 - assert result.close_date == 1682193107 - assert isinstance(result.question_entities, list) - assert isinstance(result.correct_option_ids, list) - assert result.allows_revoting == True - assert result.description == "poll desc" - assert isinstance(result.description_entities, list) - assert result.media is None - assert result.members_only == True - assert isinstance(result.country_codes, list) - assert isinstance(result.explanation_media, types.PollMedia) - assert isinstance(result, types.Poll) - - -def test_json_polloption(): - json_dict = json.loads(r'{"text": "test", "persistent_id": 1, "voter_count": 5, "text_entities": [{"type": "bold", "offset": 0, "length": 4}], "added_by_user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "added_by_chat": {"id": -1, "type": "channel", "title": "Channel"}, "addition_date": 1682189507}') - result = types.PollOption.de_json(json_dict) - assert result.text == 'test' - assert result.persistent_id == 1 - assert result.voter_count == 5 - assert isinstance(result.text_entities, list) - assert isinstance(result.added_by_user, types.User) - assert result.added_by_user.id == 12345 - assert isinstance(result.added_by_chat, types.Chat) - assert result.addition_date == 1682189507 - assert result.media is None - assert isinstance(result, types.PollOption) - - -def test_json_polloptionadded(): - json_dict = json.loads(r'{"option_persistent_id": 1, "option_text": "test", "poll_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "poll"}, "option_text_entities": [{"type": "bold", "offset": 0, "length": 4}]}') - result = types.PollOptionAdded.de_json(json_dict) - assert result.option_persistent_id == 1 - assert result.option_text == 'test' - assert isinstance(result.poll_message, types.Message) - assert isinstance(result.option_text_entities, list) - assert isinstance(result, types.PollOptionAdded) - - -def test_json_polloptiondeleted(): - json_dict = json.loads(r'{"option_persistent_id": 1, "option_text": "test", "poll_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "poll"}, "option_text_entities": [{"type": "bold", "offset": 0, "length": 4}]}') - result = types.PollOptionDeleted.de_json(json_dict) - assert result.option_persistent_id == 1 - assert result.option_text == 'test' - assert isinstance(result.poll_message, types.Message) - assert isinstance(result.option_text_entities, list) - assert isinstance(result, types.PollOptionDeleted) - - -def test_json_precheckoutquery(): - json_dict = json.loads(r'{"id": 1, "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "currency": "USD", "total_amount": 1234, "invoice_payload": "test_payload", "shipping_option_id": "opt1", "order_info": {"user_name": "Buyer", "user_phone": "+123", "shipping_address": {"country_code": "US", "state": "CA", "city": "San Jose", "street_line1": "123 Main St", "street_line2": "", "post_code": "95113"}}}') - result = types.PreCheckoutQuery.de_json(json_dict) - assert result.id == 1 - assert isinstance(result.from_user, types.User) - assert result.currency == 'USD' - assert result.total_amount == 1234 - assert result.invoice_payload == 'test_payload' - assert result.shipping_option_id == 'opt1' - assert isinstance(result.order_info, types.OrderInfo) - assert isinstance(result, types.PreCheckoutQuery) - - -def test_json_preparedinlinemessage(): - json_dict = json.loads(r'{"id": "prep1", "expiration_date": 1682189507}') - result = types.PreparedInlineMessage.de_json(json_dict) - assert result.id == 'prep1' - assert result.expiration_date == 1682189507 - assert isinstance(result, types.PreparedInlineMessage) - - -def test_json_preparedkeyboardbutton(): - json_dict = json.loads(r'{"id": 1}') - result = types.PreparedKeyboardButton.de_json(json_dict) - assert result.id == 1 - assert isinstance(result, types.PreparedKeyboardButton) - - -def test_json_proximityalerttriggered(): - json_dict = json.loads(r'{"traveler": {"id": 1, "is_bot": false, "first_name": "Test"}, "watcher": {"id": 1, "is_bot": false, "first_name": "Test"}, "distance": "test"}') - result = types.ProximityAlertTriggered.de_json(json_dict) - assert isinstance(result.traveler, dict) - assert isinstance(result.watcher, dict) - assert result.distance == 'test' - assert isinstance(result, types.ProximityAlertTriggered) - - -def test_json_refundedpayment(): - json_dict = json.loads(r'{"currency": "USD", "total_amount": 100, "invoice_payload": "test_payload", "telegram_payment_charge_id": "chg1", "provider_payment_charge_id": "chg2"}') - result = types.RefundedPayment.de_json(json_dict) - assert result.currency == 'USD' - assert result.total_amount == 100 - assert result.invoice_payload == 'test_payload' - assert result.telegram_payment_charge_id == 'chg1' - assert result.provider_payment_charge_id == 'chg2' - assert isinstance(result, types.RefundedPayment) - - -def test_json_revenuewithdrawalstate(): - # RevenueWithdrawalState is abstract - test RevenueWithdrawalStatePending directly - json_dict = json.loads(r'{"type": "pending"}') - result = types.RevenueWithdrawalStatePending.de_json(json_dict) - assert isinstance(result, types.RevenueWithdrawalStatePending) - - -def test_json_revenuewithdrawalstatefailed(): - json_dict = json.loads(r'{"type": "failed"}') - result = types.RevenueWithdrawalStateFailed.de_json(json_dict) - assert result.type == 'failed' - assert isinstance(result, types.RevenueWithdrawalStateFailed) - - -def test_json_revenuewithdrawalstatepending(): - json_dict = json.loads(r'{"type": "pending"}') - result = types.RevenueWithdrawalStatePending.de_json(json_dict) - assert result.type == 'pending' - assert isinstance(result, types.RevenueWithdrawalStatePending) - - -def test_json_revenuewithdrawalstatesucceeded(): - json_dict = json.loads(r'{"type": "succeeded", "date": 1682189507, "url": "https://example.com"}') - result = types.RevenueWithdrawalStateSucceeded.de_json(json_dict) - assert result.type == 'succeeded' - assert result.date == 1682189507 - assert result.url == 'https://example.com' - assert isinstance(result, types.RevenueWithdrawalStateSucceeded) - - -def test_json_richblockanchor(): - json_dict = json.loads(r'{"name": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockAnchor.de_json(data) - assert result.name == 'test' - assert isinstance(result, types.RichBlockAnchor) - - -def test_json_richblockaudio(): - json_dict = json.loads(r'{"type": "audio", "audio": {"file_id": "a", "file_unique_id": "au", "duration": 30}, "caption": {"type": "bold", "text": "audio caption"}}') - result = types.RichBlock.de_json(json_dict) - assert isinstance(result.audio, types.Audio) - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockAudio) - - -def test_json_richblockblockquotation(): - json_dict = json.loads(r'{"blocks": [{"text": "Test"}], "credit": "Credit text"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockBlockQuotation.de_json(data) - assert isinstance(result.blocks, list) - assert result.credit == 'Credit text' - assert isinstance(result, types.RichBlockBlockQuotation) - - -def test_json_richblockcollage(): - json_dict = json.loads(r'{"type": "collage", "blocks": [{"text": "Test"}], "caption": {"type": "bold", "text": "Caption"}}') - result = types.RichBlock.de_json(json_dict) - assert isinstance(result.blocks, list) - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockCollage) - - -def test_json_richblocklist(): - json_dict = json.loads(r'{"type": "list", "items": [{"type": "list_item", "label": {"text": "label"}, "blocks": [{"text": "Test"}]}]}') - result = types.RichBlock.de_json(json_dict) - assert isinstance(result.items, list) - assert isinstance(result, types.RichBlockList) - assert hasattr(result, 'items') - - -def test_json_richblockmap(): - json_dict = json.loads(r'{"type": "map", "location": {"latitude": 50.0, "longitude": 30.0}, "zoom": 1.0, "width": 100, "height": 100, "caption": {"type": "bold", "text": "Map caption"}}') - result = types.RichBlock.de_json(json_dict) - assert isinstance(result.location, types.Location) - assert result.zoom == 1.0 - assert result.width == 100 - assert result.height == 100 - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockMap) - - -def test_json_richblockmathematicalexpression(): - json_dict = json.loads(r'{"expression": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockMathematicalExpression.de_json(data) - assert result.expression == 'test' - assert isinstance(result, types.RichBlockMathematicalExpression) - - -def test_json_richblockphoto(): - json_dict = json.loads(r'{"type": "photo", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}], "has_spoiler": true, "caption": {"type": "bold", "text": "Photo caption"}}') - result = types.RichBlock.de_json(json_dict) - assert isinstance(result.photo, list) - assert result.has_spoiler == True - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockPhoto) - - -def test_json_richblockpullquotation(): - json_dict = json.loads(r'{"text": "test quote", "credit": "Author Name"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockPullQuotation.de_json(data) - assert result.text == 'test quote' - assert result.credit == 'Author Name' - assert isinstance(result, types.RichBlockPullQuotation) - - -def test_json_richblocksectionheading(): - json_dict = json.loads(r'{"text": "test", "size": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockSectionHeading.de_json(data) - assert result.text == 'test' - assert result.size == 'test' - assert isinstance(result, types.RichBlockSectionHeading) - - -def test_json_richblockslideshow(): - json_dict = json.loads(r'{"type": "slideshow", "blocks": [{"text": "Test"}], "caption": {"type": "bold", "text": "slide caption"}}') - result = types.RichBlock.de_json(json_dict) - assert isinstance(result.blocks, list) - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockSlideshow) - assert hasattr(result, 'caption') - assert hasattr(result, 'blocks') - - -def test_json_richblocktable(): - json_dict = json.loads(r'{"type": "table", "cells": [[{"align": "left", "valign": "top", "text": "cell", "is_header": false, "colspan": 1, "rowspan": 1}]], "is_bordered": true, "is_striped": true, "caption": {"type": "bold", "text": "table caption"}}') - result = types.RichBlock.de_json(json_dict) - assert isinstance(result.cells, list) - assert result.is_bordered == True - assert result.is_striped == True - assert isinstance(result.caption, types.RichText) - assert isinstance(result, types.RichBlockTable) - assert hasattr(result, 'is_striped') - assert hasattr(result, 'is_bordered') - assert hasattr(result, 'cells') - - -def test_json_richblockthinking(): - json_dict = json.loads(r'{"text": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockThinking.de_json(data) - assert result.text == 'test' - assert isinstance(result, types.RichBlockThinking) - - -def test_json_richblockvideo(): - json_dict = json.loads(r'{"type": "video", "video": {"file_id": "v", "file_unique_id": "vu", "width": 640, "height": 480, "duration": 30}, "has_spoiler": true, "caption": {"type": "bold", "text": "video caption"}}') - result = types.RichBlock.de_json(json_dict) - assert isinstance(result.video, types.Video) - assert result.has_spoiler == True - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockVideo) - assert hasattr(result, 'has_spoiler') - - -def test_json_richmessage(): - json_dict = json.loads(r'{"blocks": [{"type": "text", "text": "Test"}], "is_rtl": true}') - result = types.RichMessage.de_json(json_dict) - assert isinstance(result.blocks, list) - assert result.is_rtl == True - assert isinstance(result, types.RichMessage) - - -def test_json_sentguestmessage(): - json_dict = json.loads(r'{"inline_message_id": 1}') - result = types.SentGuestMessage.de_json(json_dict) - assert result.inline_message_id == 1 - assert isinstance(result, types.SentGuestMessage) - - -def test_json_shippingaddress(): - json_dict = json.loads(r'{"country_code": "US", "state": "CA", "city": "San Jose", "street_line1": "123 Main St", "street_line2": "Apt 4", "post_code": "95113"}') - result = types.ShippingAddress.de_json(json_dict) - assert result.country_code == 'US' - assert result.state == 'CA' - assert result.city == 'San Jose' - assert result.street_line1 == '123 Main St' - assert result.street_line2 == 'Apt 4' - assert result.post_code == '95113' - assert isinstance(result, types.ShippingAddress) - - -def test_json_shippingquery(): - json_dict = json.loads(r'{"id": "1", "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "invoice_payload": "test_payload", "shipping_address": {"country_code": "US", "state": "CA", "city": "Test", "street_line1": "Test St", "street_line2": "", "post_code": "12345"}}') - result = types.ShippingQuery.de_json(json_dict) - assert result.id == '1' - assert isinstance(result.from_user, types.User) - assert result.invoice_payload == 'test_payload' - assert result.shipping_address.country_code == 'US' - assert result.shipping_address.state == 'CA' - assert result.shipping_address.city == 'Test' - assert result.shipping_address.street_line1 == 'Test St' - assert result.shipping_address.street_line2 == '' - assert result.shipping_address.post_code == '12345' - assert isinstance(result, types.ShippingQuery) - - -def test_json_staramount(): - json_dict = json.loads(r'{"amount": "100", "nanostar_amount": 1000000000}') - result = types.StarAmount.de_json(json_dict) - assert result.amount == '100' - assert result.nanostar_amount == 1000000000 - assert isinstance(result, types.StarAmount) - - -def test_json_startransaction(): - json_dict = json.loads(r'{"id": 1, "amount": 100, "date": 1682189507, "source": {"type": "fragment"}, "receiver": {"type": "telegram_ads"}, "nanostar_amount": 10000000}') - result = types.StarTransaction.de_json(json_dict) - assert result.id == 1 - assert result.amount == 100 - assert result.date == 1682189507 - assert isinstance(result.source, types.TransactionPartnerFragment) - assert isinstance(result.receiver, dict) - assert result.receiver['type'] == 'telegram_ads' - assert result.nanostar_amount == 10000000 - assert isinstance(result, types.StarTransaction) - - -def test_json_startransactions(): - json_dict = json.loads(r'{"transactions": [{"id": "tx1", "amount": 100, "date": 1682189507}]}') - result = types.StarTransactions.de_json(json_dict) - assert isinstance(result, types.StarTransactions) - assert hasattr(result, 'transactions') - - -def test_json_story(): - json_dict = json.loads(r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "id": 1}') - result = types.Story.de_json(json_dict) - assert isinstance(result.chat, types.Chat) - assert result.id == 1 - assert isinstance(result, types.Story) - - -def test_json_successfulpayment(): - json_dict = json.loads(r'{"currency": "USD", "total_amount": 1234, "invoice_payload": "test_payload", "shipping_option_id": "opt1", "order_info": {"user_name": "Buyer", "user_phone": "+123", "shipping_address": {"country_code": "US", "state": "CA", "city": "San Jose", "street_line1": "123 Main St", "street_line2": "", "post_code": "95113"}}, "telegram_payment_charge_id": "chg1", "provider_payment_charge_id": "chg2", "subscription_expiration_date": 1704067200, "is_recurring": true, "is_first_recurring": true}') - result = types.SuccessfulPayment.de_json(json_dict) - assert result.currency == 'USD' - assert result.total_amount == 1234 - assert result.invoice_payload == 'test_payload' - assert result.shipping_option_id == 'opt1' - assert isinstance(result.order_info, types.OrderInfo) - assert result.telegram_payment_charge_id == 'chg1' - assert result.provider_payment_charge_id == 'chg2' - assert result.subscription_expiration_date == 1704067200 - assert result.is_recurring == True - assert result.is_first_recurring == True - assert isinstance(result, types.SuccessfulPayment) - - -def test_json_suggestedpostapprovalfailed(): - json_dict = json.loads(r'{"price": {"currency": "USD", "amount": 100}, "suggested_post_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "suggested"}}') - result = types.SuggestedPostApprovalFailed.de_json(json_dict) - assert isinstance(result.price, types.SuggestedPostPrice) - assert isinstance(result.suggested_post_message, types.Message) - assert result.suggested_post_message.message_id == 1 - assert isinstance(result, types.SuggestedPostApprovalFailed) - - -def test_json_suggestedpostapproved(): - json_dict = json.loads(r'{"send_date": 1682189507, "suggested_post_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "suggested"}, "price": {"amount": "100", "currency": "XTR"}}') - result = types.SuggestedPostApproved.de_json(json_dict) - assert result.send_date == 1682189507 - assert isinstance(result.suggested_post_message, types.Message) - assert isinstance(result.price, types.SuggestedPostPrice) - assert isinstance(result, types.SuggestedPostApproved) - - -def test_json_suggestedpostinfo(): - json_dict = json.loads(r'{"state": "default", "price": {"amount": "100", "currency": "XTR"}, "send_date": 1682189507}') - result = types.SuggestedPostInfo.de_json(json_dict) - assert result.state == 'default' - assert isinstance(result.price, types.SuggestedPostPrice) - assert result.send_date == 1682189507 - assert isinstance(result, types.SuggestedPostInfo) - - -def test_json_suggestedpostpaid(): - json_dict = json.loads(r'{"currency": "test", "suggested_post_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "suggested"}, "amount": 100, "star_amount": {"amount": 50}}') - result = types.SuggestedPostPaid.de_json(json_dict) - assert result.currency == 'test' - assert isinstance(result.suggested_post_message, types.Message) - assert result.amount == 100 - assert isinstance(result.star_amount, types.StarAmount) - assert result.star_amount.amount == 50 - assert isinstance(result, types.SuggestedPostPaid) - - -def test_json_suggestedpostrefunded(): - json_dict = json.loads(r'{"reason": "test", "suggested_post_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "suggested"}}') - result = types.SuggestedPostRefunded.de_json(json_dict) - assert result.reason == 'test' - assert isinstance(result.suggested_post_message, types.Message) - assert result.suggested_post_message.message_id == 1 - assert isinstance(result, types.SuggestedPostRefunded) - - -def test_json_textquote(): - json_dict = json.loads(r'{"text": "test", "position": 0, "entities": [{"type": "bold", "offset": 0, "length": 4}], "is_manual": true}') - result = types.TextQuote.de_json(json_dict) - assert result.text == 'test' - assert result.position == 0 - assert isinstance(result.entities, list) - assert result.is_manual == True - assert isinstance(result, types.TextQuote) - - -def test_json_transactionpartner(): - # TransactionPartner is abstract - test TransactionPartnerUser directly - json_dict = json.loads(r'{"type": "user", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}') - result = types.TransactionPartnerUser.de_json(json_dict) - assert isinstance(result, types.TransactionPartnerUser) - - -def test_json_transactionpartneraffiliateprogram(): - json_dict = json.loads(r'{"type": "affiliate_program", "commission_per_mille": 1000, "sponsor_user": {"id": 1, "is_bot": false, "first_name": "Sponsor"}}') - result = types.TransactionPartnerAffiliateProgram.de_json(json_dict) - assert result.type == 'affiliate_program' - assert result.commission_per_mille == 1000 - assert isinstance(result.sponsor_user, types.User) - assert result.sponsor_user.id == 1 - assert isinstance(result, types.TransactionPartnerAffiliateProgram) - - -def test_json_transactionpartnerchat(): - json_dict = json.loads(r'{"type": "chat", "chat": {"id": 1, "type": "private", "title": "Test"}, "gift": {"id": 123456789, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100, "total_count": 5, "remaining_count": 3, "upgrade_star_count": 50, "personal_total_count": 10, "personal_remaining_count": 2, "is_premium": true, "has_colors": true, "publisher_chat": {"id": 1, "type": "channel", "title": "Publisher"}, "unique_gift_variant_count": 3}}') - result = types.TransactionPartnerChat.de_json(json_dict) - assert result.type == 'chat' - assert isinstance(result.chat, types.Chat) - assert isinstance(result.gift, types.Gift) - assert result.gift.id == 123456789 - assert isinstance(result, types.TransactionPartnerChat) - - -def test_json_transactionpartnerfragment(): - json_dict = json.loads(r'{"type": "fragment", "withdrawal_state": {"type": "pending"}}') - result = types.TransactionPartnerFragment.de_json(json_dict) - assert result.type == 'fragment' - assert isinstance(result.withdrawal_state, types.RevenueWithdrawalState) - assert isinstance(result, types.TransactionPartnerFragment) - - -def test_json_transactionpartnerother(): - json_dict = json.loads(r'{"type": "other"}') - result = types.TransactionPartnerOther.de_json(json_dict) - assert result.type == 'other' - assert isinstance(result, types.TransactionPartnerOther) - - -def test_json_transactionpartnertelegramapi(): - json_dict = json.loads(r'{"type": "default", "request_count": 10}') - result = types.TransactionPartnerTelegramApi.de_json(json_dict) - assert result.type == 'default' - assert result.request_count == 10 - assert isinstance(result, types.TransactionPartnerTelegramApi) - - -def test_json_transactionpartneruser(): - json_dict = json.loads(r'{"type": "default", "user": {"id": 1, "is_bot": false, "first_name": "Test"}, "affiliate": {"commission_per_mille": 5500, "amount": 100, "affiliate_user": {"id": 1, "is_bot": false, "first_name": "User"}, "affiliate_chat": {"id": 1, "type": "private"}, "nanostar_amount": 1000000}, "invoice_payload": "payload", "paid_media": [{"type": "photo", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}], "subscription_period": 30, "gift": {"id": 1, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100, "total_count": 1000, "remaining_count": 999, "upgrade_star_count": 50, "personal_total_count": 5, "personal_remaining_count": 3, "is_premium": true, "has_colors": false, "publisher_chat": {"id": 1, "type": "channel", "title": "Pub"}, "unique_gift_variant_count": 10}, "premium_subscription_duration": 12, "transaction_type": "purchase"}') - result = types.TransactionPartnerUser.de_json(json_dict) - assert result.type == 'default' - assert isinstance(result.user, types.User) - assert isinstance(result.affiliate, types.AffiliateInfo) - assert result.invoice_payload == 'payload' - assert isinstance(result.paid_media, list) - assert result.subscription_period == 30 - assert isinstance(result.gift, types.Gift) - assert result.premium_subscription_duration == 12 - assert result.transaction_type == 'purchase' - assert isinstance(result, types.TransactionPartnerUser) - - -def test_json_uniquegift(): - json_dict = json.loads(r'{"base_name": "test", "name": "test", "number": 1, "model": {"name": "model_name", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "symbol": {"name": "symbol_name", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "backdrop": {"name": "backdrop_name", "colors": {"center_color": 123456, "edge_color": 654321, "symbol_color": 111111, "text_color": 222222}, "rarity_per_mille": 1000}, "gift_id": 1, "publisher_chat": {"id": -1001234567890, "type": "channel", "title": "Channel"}, "is_from_blockchain": true, "is_premium": false, "colors": {"model_custom_emoji_id": 1, "symbol_custom_emoji_id": 1, "light_theme_main_color": 333333, "light_theme_other_colors": [444444], "dark_theme_main_color": 555555, "dark_theme_other_colors": [666666]}, "is_burned": false}') - result = types.UniqueGift.de_json(json_dict) - assert result.base_name == 'test' - assert result.name == 'test' - assert result.number == 1 - assert isinstance(result.model, types.UniqueGiftModel) - assert isinstance(result.symbol, types.UniqueGiftSymbol) - assert isinstance(result.backdrop, types.UniqueGiftBackdrop) - assert result.gift_id == 1 - assert isinstance(result.publisher_chat, types.Chat) - assert result.is_from_blockchain == True - assert result.is_premium == False - assert isinstance(result.colors, types.UniqueGiftColors) - assert result.is_burned == False - assert isinstance(result, types.UniqueGift) - - -def test_json_uniquegiftbackdrop(): - json_dict = json.loads(r'{"name": "test", "colors": {"center_color": 123456, "edge_color": 654321, "symbol_color": 111111, "text_color": 222222}, "rarity_per_mille": 1000}') - result = types.UniqueGiftBackdrop.de_json(json_dict) - assert result.name == 'test' - assert isinstance(result.colors, types.UniqueGiftBackdropColors) - assert result.rarity_per_mille == 1000 - assert isinstance(result, types.UniqueGiftBackdrop) - - -def test_json_uniquegiftbackdropcolors(): - json_dict = json.loads(r'{"center_color": 123456, "edge_color": 654321, "symbol_color": 111111, "text_color": 222222}') - result = types.UniqueGiftBackdropColors.de_json(json_dict) - assert result.center_color == 123456 - assert result.edge_color == 654321 - assert result.symbol_color == 111111 - assert result.text_color == 222222 - assert isinstance(result, types.UniqueGiftBackdropColors) - - -def test_json_uniquegiftcolors(): - json_dict = json.loads(r'{"model_custom_emoji_id": 1, "symbol_custom_emoji_id": 1, "light_theme_main_color": 333333, "light_theme_other_colors": [444444], "dark_theme_main_color": 555555, "dark_theme_other_colors": [666666]}') - result = types.UniqueGiftColors.de_json(json_dict) - assert result.model_custom_emoji_id == 1 - assert result.symbol_custom_emoji_id == 1 - assert result.light_theme_main_color == 333333 - assert isinstance(result.light_theme_other_colors, list) - assert result.dark_theme_main_color == 555555 - assert isinstance(result.dark_theme_other_colors, list) - assert isinstance(result, types.UniqueGiftColors) - - -def test_json_uniquegiftinfo(): - json_dict = json.loads(r'{"gift": {"base_name": "b", "name": "n", "number": 1, "model": {"name": "m", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "symbol": {"name": "s", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "backdrop": {"name": "b", "colors": {"center_color": 123456, "edge_color": 654321, "symbol_color": 111111, "text_color": 222222}, "rarity_per_mille": 1000}, "gift_id": 1}, "origin": "test", "owned_gift_id": "og123", "transfer_star_count": 100, "next_transfer_date": 1682189507, "last_resale_currency": "USD", "last_resale_amount": 500}') - result = types.UniqueGiftInfo.de_json(json_dict) - assert isinstance(result.gift, types.UniqueGift) - assert result.origin == 'test' - assert result.owned_gift_id == 'og123' - assert result.transfer_star_count == 100 - assert result.next_transfer_date == 1682189507 - assert result.last_resale_currency == 'USD' - assert result.last_resale_amount == 500 - assert isinstance(result, types.UniqueGiftInfo) - - -def test_json_uniquegiftmodel(): - json_dict = json.loads(r'{"name": "test", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000, "rarity": "common"}') - result = types.UniqueGiftModel.de_json(json_dict) - assert result.name == 'test' - assert isinstance(result.sticker, types.Sticker) - assert result.rarity_per_mille == 1000 - assert result.rarity == 'common' - assert isinstance(result, types.UniqueGiftModel) - - -def test_json_uniquegiftsymbol(): - json_dict = json.loads(r'{"name": "test", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}') - result = types.UniqueGiftSymbol.de_json(json_dict) - assert result.name == 'test' - assert isinstance(result.sticker, types.Sticker) - assert result.rarity_per_mille == 1000 - assert isinstance(result, types.UniqueGiftSymbol) - - -# NOTE: Update is an abstract/registry class that dispatches to specific -# update types (message_update, callback_query_update, etc.). Its __init__ -# only contains 'update_id' in practice; other 'update_type' fields are -# handled by subclasses. Full field coverage is intentionally not required. -def test_json_update(): - json_dict = json.loads(r'{"update_id": 1}') - result = types.Update.de_json(json_dict) - assert result.update_id == 1 - assert isinstance(result, types.Update) - - -def test_json_userchatboosts(): - json_dict = json.loads(r'{"boosts": [{"boost_item_id": "b1", "add_date": 1682189507, "expiration_date": 1682275907}]}') - result = types.UserChatBoosts.de_json(json_dict) - assert isinstance(result.boosts, list) - assert isinstance(result, types.UserChatBoosts) - assert hasattr(result, 'boosts') - - -def test_json_userprofileaudios(): - json_dict = json.loads(r'{"total_count": 1, "audios": [{"file_id": "a1", "file_unique_id": "au1", "duration": 180, "title": "Test", "performer": "Perf", "type": "song"}]}') - result = types.UserProfileAudios.de_json(json_dict) - assert result.total_count == 1 - assert isinstance(result.audios, list) - assert isinstance(result, types.UserProfileAudios) - - -def test_json_userprofilephotos(): - json_dict = json.loads(r'{"total_count": 1, "photos": [[{"file_id": "p1", "file_unique_id": "pu1", "width": 100, "height": 100}]]}') - result = types.UserProfilePhotos.de_json(json_dict) - assert result.total_count == 1 - assert isinstance(result.photos, list) - assert isinstance(result.photos[0], list) - assert isinstance(result.photos[0][0], types.PhotoSize) - assert isinstance(result, types.UserProfilePhotos) - - -def test_json_userrating(): - json_dict = json.loads(r'{"level": "test", "rating": "test", "current_level_rating": "test", "next_level_rating": "next_test"}') - result = types.UserRating.de_json(json_dict) - assert result.level == 'test' - assert result.rating == 'test' - assert result.current_level_rating == 'test' - assert result.next_level_rating == 'next_test' - assert isinstance(result, types.UserRating) - - -def test_json_videochatended(): - json_dict = json.loads(r'{"duration": 30}') - result = types.VideoChatEnded.de_json(json_dict) - assert result.duration == 30 - assert isinstance(result, types.VideoChatEnded) - - -def test_json_videochatscheduled(): - json_dict = json.loads(r'{"start_date": 1682189507}') - result = types.VideoChatScheduled.de_json(json_dict) - assert result.start_date == 1682189507 - assert isinstance(result, types.VideoChatScheduled) - - -def test_json_videonote(): - json_dict = json.loads(r'{"file_id": "test_file_id", "file_unique_id": "test_unique_id", "length": 100, "duration": 30, "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 50, "height": 50}, "file_size": 1024}') - result = types.VideoNote.de_json(json_dict) - assert result.file_id == 'test_file_id' - assert result.file_unique_id == 'test_unique_id' - assert result.length == 100 - assert result.duration == 30 - assert isinstance(result.thumbnail, types.PhotoSize) - assert result.file_size == 1024 - assert isinstance(result, types.VideoNote) - - -def test_json_videoquality(): - json_dict = json.loads(r'{"file_id": "test_file_id", "file_unique_id": "test_unique_id", "width": 100, "height": 100, "codec": "h264", "file_size": 1024}') - result = types.VideoQuality.de_json(json_dict) - assert result.file_id == 'test_file_id' - assert result.file_unique_id == 'test_unique_id' - assert result.width == 100 - assert result.height == 100 - assert result.codec == 'h264' - assert result.file_size == 1024 - assert isinstance(result, types.VideoQuality) - - -def test_json_webhookinfo(): - json_dict = json.loads(r'{"url": "https://example.com", "has_custom_certificate": false, "pending_update_count": 1}') - result = types.WebhookInfo.de_json(json_dict) - assert result.url == 'https://example.com' - assert result.has_custom_certificate == False - assert result.pending_update_count == 1 - assert isinstance(result, types.WebhookInfo) \ No newline at end of file diff --git a/tests/test_types.bak03 b/tests/test_types.bak03 deleted file mode 100644 index d4e325e71..000000000 --- a/tests/test_types.bak03 +++ /dev/null @@ -1,2679 +0,0 @@ -# -*- coding: utf-8 -*- -import sys - -sys.path.append('../') -from telebot import types - - -def test_json_user(): - json_str = r'{"id": 123456789, "is_bot": false, "first_name": "John", "last_name": "Doe", "username": "@johndoe", "language_code": "en", "can_join_groups": true, "can_read_all_group_messages": false, "supports_inline_queries": true, "is_premium": true, "added_to_attachment_menu": false, "can_connect_to_business": true, "has_main_web_app": false, "has_topics_enabled": true, "allows_users_to_create_topics": true, "can_manage_bots": true, "supports_guest_queries": true, "supports_join_request_queries": true}' - result = types.User.de_json(json_str) - assert result.id == 123456789 - assert result.is_bot == False - assert result.first_name == 'John' - assert result.last_name == 'Doe' - assert result.username == '@johndoe' - assert result.language_code == 'en' - assert result.can_join_groups == True - assert result.can_read_all_group_messages == False - assert result.supports_inline_queries == True - assert result.is_premium == True - assert result.added_to_attachment_menu == False - assert result.can_connect_to_business == True - assert result.has_main_web_app == False - assert result.has_topics_enabled == True - assert result.allows_users_to_create_topics == True - assert result.can_manage_bots == True - assert result.supports_guest_queries == True - assert result.supports_join_request_queries == True - assert isinstance(result, types.User) - - -def test_json_chat(): - json_str = r'{"id": 12345, "type": "private", "title": "Test Chat", "username": "@testchat", "first_name": "John", "last_name": "Doe", "photo": {"small_file_id": "s", "small_file_unique_id": "su", "big_file_id": "b", "big_file_unique_id": "bu"}, "bio": "bio text", "has_private_forwards": true, "description": "chat description", "invite_link": "https://t.me/joinchat/ABC", "pinned_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "pinned"}, "permissions": {"can_send_messages": true, "can_send_audios": true, "can_send_documents": true, "can_send_photos": true, "can_send_videos": true, "can_send_video_notes": true, "can_send_voice_notes": true, "can_send_polls": true, "can_send_other_messages": true, "can_add_web_page_previews": true, "can_change_info": true, "can_invite_users": true, "can_pin_messages": true, "can_manage_topics": true}, "slow_mode_delay": 30, "message_auto_delete_time": 86400, "has_protected_content": true, "sticker_set_name": "TestStickerSet", "can_set_sticker_set": false, "linked_chat_id": 2, "location": {"chat": {"id": 1, "type": "supergroup", "title": "Loc"}, "location": {"latitude": 50.45, "longitude": 30.52}, "address": "Main St"}, "join_to_send_messages": false, "join_by_request": true, "has_restricted_voice_and_video_messages": false, "is_forum": true, "max_reaction_count": 10, "active_usernames": ["test"], "emoji_status_custom_emoji_id": "custom_emoji", "has_hidden_members": false, "has_aggressive_anti_spam_enabled": false, "emoji_status_expiration_date": 1682275907, "available_reactions": ["emoji", "custom_emoji"], "accent_color_id": 1, "background_custom_emoji_id": "bg_emoji", "profile_accent_color_id": 2, "profile_background_custom_emoji_id": "profile_bg", "has_visible_history": true, "unrestrict_boost_count": 5, "custom_emoji_sticker_set_name": "custom_stickers", "business_intro": {"title": "Business", "description": "Business desc", "has_visible_history": true}, "business_location": {"address": "New York, NY", "has_active_address": true}, "business_opening_hours": {"time_zone_name": "America/New_York", "opening_hours": [{"opening_minute": 540, "closing_minute": 1020, "day_of_week": 1, "is_recurring": true}]}, "personal_chat": {"id": 3, "type": "private", "title": "Personal"}, "birthdate": {"day": "15", "month": "6"}, "can_send_paid_media": true, "accepted_gift_types": {"unlimited_gifts": false, "limited_gifts": false, "unique_gifts": true, "premium_subscription": false, "gifts_from_channels": false}, "is_direct_messages": true, "parent_chat": {"id": 4, "type": "supergroup", "title": "Parent"}, "rating": {"level": "test", "rating": "test", "current_level_rating": "test"}, "paid_message_star_count": 5, "first_profile_audio": {"file_id": "fa1", "file_unique_id": "fa1u", "duration": 30, "mime_type": "audio/ogg"}, "unique_gift_colors": {"model_custom_emoji_id": 1, "symbol_custom_emoji_id": 1, "light_theme_main_color": 333333, "light_theme_other_colors": [444444], "dark_theme_main_color": 555555, "dark_theme_other_colors": [666666]}, "guard_bot": {"id": 2, "is_bot": true, "first_name": "GuardBot"}, "community": {"id": 5, "name": "Community"}}' - result = types.Chat.de_json(json_str) - assert result.id == 12345 - assert result.type == 'private' - assert result.title == 'Test Chat' - assert result.username == "@testchat" - assert result.first_name == "John" - assert result.last_name == "Doe" - assert isinstance(result.photo, types.ChatPhoto) - assert result.bio == "bio text" - assert result.has_private_forwards == True - assert result.description == "chat description" - assert result.invite_link == "https://t.me/joinchat/ABC" - assert isinstance(result.pinned_message, types.Message) - assert isinstance(result.permissions, types.ChatPermissions) - assert result.slow_mode_delay == 30 - assert result.message_auto_delete_time == 86400 - assert result.has_protected_content == True - assert result.sticker_set_name == "TestStickerSet" - assert result.can_set_sticker_set == False - assert result.linked_chat_id == 2 - assert isinstance(result.location, types.ChatLocation) - assert result.join_to_send_messages == False - assert result.join_by_request == True - assert result.has_restricted_voice_and_video_messages == False - assert result.is_forum == True - assert result.max_reaction_count == 10 - assert isinstance(result.active_usernames, list) - assert result.emoji_status_custom_emoji_id == "custom_emoji" - assert result.has_hidden_members == False - assert result.has_aggressive_anti_spam_enabled == False - assert result.emoji_status_expiration_date == 1682275907 - assert isinstance(result.available_reactions, list) - assert result.accent_color_id == 1 - assert result.background_custom_emoji_id == "bg_emoji" - assert result.profile_accent_color_id == 2 - assert result.profile_background_custom_emoji_id == "profile_bg" - assert result.has_visible_history == True - assert result.unrestrict_boost_count == 5 - assert result.custom_emoji_sticker_set_name == "custom_stickers" - assert isinstance(result.business_intro, types.BusinessIntro) - assert isinstance(result.business_location, types.BusinessLocation) - assert isinstance(result.business_opening_hours, types.BusinessOpeningHours) - assert isinstance(result.personal_chat, types.Chat) - assert isinstance(result.birthdate, types.Birthdate) - assert result.can_send_paid_media == True - assert isinstance(result.accepted_gift_types, types.AcceptedGiftTypes) - assert result.is_direct_messages == True - assert isinstance(result.parent_chat, types.Chat) - assert isinstance(result.rating, types.UserRating) - assert result.paid_message_star_count == 5 - assert isinstance(result.unique_gift_colors, types.UniqueGiftColors) - assert isinstance(result.first_profile_audio, types.Audio) - assert isinstance(result.guard_bot, types.User) - assert isinstance(result.community, types.Community) - assert isinstance(result, types.Chat) - - -# NOTE: Message has internal fields that are not covered by de_json tests: -# - options: internal field, not from JSON -# - json_string: internal field, not from JSON -def test_json_message(): - json_str = r'{"message_id": 1, "date": 1682189507, "chat": {"id": 12345, "type": "private", "title": "Chat"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "Hello", "content_type": "text"}' - result = types.Message.de_json(json_str) - assert result.message_id == 1 - assert isinstance(result.from_user, types.User) - assert result.date == 1682189507 - assert isinstance(result.chat, types.Chat) - assert result.content_type == 'text' - assert isinstance(result, types.Message) - - -def test_json_location(): - json_str = r'{"latitude": 50.4501, "longitude": 30.5234, "horizontal_accuracy": 1.5, "live_period": 3600, "heading": 45, "proximity_alert_radius": 100}' - result = types.Location.de_json(json_str) - assert result.longitude == 30.5234 - assert result.latitude == 50.4501 - assert result.horizontal_accuracy == 1.5 - assert result.live_period == 3600 - assert result.heading == 45 - assert result.proximity_alert_radius == 100 - assert isinstance(result, types.Location) - - -def test_json_venue(): - json_str = r'{"location": {"latitude": 50.45, "longitude": 30.52}, "title": "Kyiv", "address": "Khreshchatyk St", "foursquare_id": "12345", "foursquare_type": "restaurant", "google_place_id": "ChI123456", "google_place_type": "locality"}' - result = types.Venue.de_json(json_str) - assert isinstance(result.location, types.Location) - assert result.title == 'Kyiv' - assert result.address == 'Khreshchatyk St' - assert result.foursquare_id == '12345' - assert result.foursquare_type == 'restaurant' - assert result.google_place_id == 'ChI123456' - assert result.google_place_type == 'locality' - assert isinstance(result, types.Venue) - - -def test_json_contact(): - json_str = r'{"phone_number": "+123****7890", "first_name": "John", "user_id": 12345, "last_name": "Doe", "vcard": "some vcard data"}' - result = types.Contact.de_json(json_str) - assert result.phone_number == '+123****7890' - assert result.first_name == 'John' - assert result.last_name == 'Doe' - assert result.user_id == 12345 - assert result.vcard == 'some vcard data' - assert isinstance(result, types.Contact) - - -def test_json_document(): - json_str = r'{"file_id": "doc1", "file_unique_id": "du1", "file_name": "test.pdf", "mime_type": "application/pdf", "file_size": 1024, "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 50, "height": 50}}' - result = types.Document.de_json(json_str) - assert result.file_id == 'doc1' - assert result.file_unique_id == 'du1' - assert isinstance(result.thumbnail, types.PhotoSize) - assert result.file_name == 'test.pdf' - assert result.mime_type == 'application/pdf' - assert result.file_size == 1024 - assert isinstance(result, types.Document) - - -def test_json_photo_size(): - json_str = r'{"file_id": "photo1", "file_unique_id": "pu1", "width": 100, "height": 100, "file_size": 512}' - result = types.PhotoSize.de_json(json_str) - assert result.file_id == 'photo1' - assert result.file_unique_id == 'pu1' - assert result.width == 100 - assert result.height == 100 - assert result.file_size == 512 - assert isinstance(result, types.PhotoSize) - - -def test_json_video(): - json_str = r'{"file_id": "video1", "file_unique_id": "vu1", "width": 640, "height": 480, "duration": 30, "mime_type": "video/mp4", "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 50, "height": 50}, "file_name": "video.mp4", "file_size": 2048, "start_timestamp": 5, "qualities": [{"file_id": "q1", "file_unique_id": "qu1", "width": 240, "height": 360, "codec": "h264", "file_size": 1024}, {"file_id": "q2", "file_unique_id": "qu2", "width": 640, "height": 480, "codec": "h264", "file_size": 2048}]}' - result = types.Video.de_json(json_str) - assert result.file_id == 'video1' - assert result.file_unique_id == 'vu1' - assert result.width == 640 - assert result.height == 480 - assert result.duration == 30 - assert isinstance(result.thumbnail, types.PhotoSize) - assert result.file_name == 'video.mp4' - assert result.mime_type == 'video/mp4' - assert result.file_size == 2048 - assert result.cover is None - assert result.start_timestamp == 5 - assert isinstance(result.qualities, list) - assert isinstance(result, types.Video) - - -def test_json_audio(): - json_str = r'{"file_id": "audio1", "file_unique_id": "au1", "duration": 30, "mime_type": "audio/mpeg", "performer": "Artist", "title": "Song Title", "file_name": "song.mp3", "file_size": 512, "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 50, "height": 50}}' - result = types.Audio.de_json(json_str) - assert result.file_id == 'audio1' - assert result.file_unique_id == 'au1' - assert result.duration == 30 - assert result.performer == 'Artist' - assert result.title == 'Song Title' - assert result.file_name == 'song.mp3' - assert result.mime_type == 'audio/mpeg' - assert result.file_size == 512 - assert isinstance(result.thumbnail, types.PhotoSize) - assert isinstance(result, types.Audio) - - -def test_json_voice(): - json_str = r'{"file_id": "voice1", "file_unique_id": "vu1", "duration": 30, "mime_type": "audio/ogg", "file_size": 256}' - result = types.Voice.de_json(json_str) - assert result.file_id == 'voice1' - assert result.file_unique_id == 'vu1' - assert result.duration == 30 - assert result.mime_type == 'audio/ogg' - assert result.file_size == 256 - assert isinstance(result, types.Voice) - - -def test_json_animation(): - json_str = r'{"file_id": "anim1", "file_unique_id": "anu1", "width": 100, "height": 100, "duration": 10, "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 50, "height": 50}, "file_name": "anim.mp4", "mime_type": "video/mp4", "file_size": 1024}' - result = types.Animation.de_json(json_str) - assert result.file_id == 'anim1' - assert result.file_unique_id == 'anu1' - assert result.width == 100 - assert result.height == 100 - assert result.duration == 10 - assert isinstance(result.thumbnail, types.PhotoSize) - assert result.file_name == 'anim.mp4' - assert result.mime_type == 'video/mp4' - assert result.file_size == 1024 - assert isinstance(result, types.Animation) - - -def test_json_sticker(): - json_str = r'{"file_id": "sticker1", "file_unique_id": "stu1", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false, "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 100, "height": 100}, "emoji": "😀", "set_name": "TestSet", "mask_position": {"point": "forehead", "x_shift": 0.0, "y_shift": 0.0, "scale": 0.5}, "file_size": 4096, "premium_animation": {"file_id": "pa1", "file_unique_id": "pa1u"}, "custom_emoji_id": "ce1", "needs_repainting": true}' - result = types.Sticker.de_json(json_str) - assert result.file_id == 'sticker1' - assert result.file_unique_id == 'stu1' - assert result.type == 'regular' - assert result.width == 512 - assert result.height == 512 - assert result.is_animated == False - assert result.is_video == False - assert isinstance(result.thumbnail, types.PhotoSize) - assert result.emoji == '😀' - assert result.set_name == 'TestSet' - assert isinstance(result.mask_position, types.MaskPosition) - assert result.file_size == 4096 - assert isinstance(result.premium_animation, types.File) - assert result.custom_emoji_id == 'ce1' - assert result.needs_repainting == True - assert isinstance(result, types.Sticker) - - -def test_json_stickerset(): - json_str = r'{"name": "TestName", "title": "Test Title", "sticker_type": "regular", "stickers": [{"file_id": "st1", "file_unique_id": "su1", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}], "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 100, "height": 100}}' - result = types.StickerSet.de_json(json_str) - assert result.name == 'TestName' - assert result.title == 'Test Title' - assert result.sticker_type == 'regular' - assert isinstance(result.stickers, list) - assert isinstance(result.thumbnail, types.PhotoSize) - assert isinstance(result, types.StickerSet) - - -def test_json_chatlocation(): - json_str = r'{"location": {"latitude": 50.45, "longitude": 30.52}, "address": "New York, NY"}' - result = types.ChatLocation.de_json(json_str) - assert isinstance(result.location, types.Location) - assert result.address == 'New York, NY' - - -def test_json_reactiontypeemoji(): - json_str = r'{"type": "emoji", "emoji": "\u2764\uFE0F"}' - result = types.ReactionTypeEmoji.de_json(json_str) - assert result.emoji == '❤️' - assert isinstance(result, types.ReactionTypeEmoji) - - -def test_json_reactiontypecustomemoji(): - json_str = r'{"type": "custom_emoji", "custom_emoji_id": "ce123"}' - result = types.ReactionTypeCustomEmoji.de_json(json_str) - assert result.custom_emoji_id == 'ce123' - assert isinstance(result, types.ReactionTypeCustomEmoji) - - -def test_json_reactioncount(): - json_str = r'{"type": {"type": "emoji", "emoji": "\u2764\uFE0F"}, "total_count": 5}' - result = types.ReactionCount.de_json(json_str) - assert isinstance(result.type, types.ReactionType) - assert result.total_count == 5 - assert isinstance(result, types.ReactionCount) - - -def test_json_chatinvitelink(): - json_str = r'{"invite_link": "https://t.me/joinchat/ABC", "creator": {"id": 12345, "is_bot": false, "first_name": "Test"}, "creates_join_request": false, "is_primary": true, "is_revoked": false, "name": "Invite", "expire_date": 1704067200, "member_limit": 10, "pending_join_request_count": 3}' - result = types.ChatInviteLink.de_json(json_str) - assert result.invite_link == 'https://t.me/joinchat/ABC' - assert isinstance(result.creator, types.User) - assert result.creates_join_request == False - assert result.is_primary == True - assert result.is_revoked == False - assert result.name == 'Invite' - assert result.expire_date == 1704067200 - assert result.member_limit == 10 - assert result.pending_join_request_count == 3 - assert isinstance(result, types.ChatInviteLink) - - -def test_json_forumtopic(): - json_str = r'{"message_thread_id": 42, "name": "Topic", "icon_color": 4294967295, "icon_custom_emoji_id": "emoji1", "is_name_implicit": true}' - result = types.ForumTopic.de_json(json_str) - assert result.message_thread_id == 42 - assert result.name == 'Topic' - assert result.icon_color == 4294967295 - assert result.icon_custom_emoji_id == 'emoji1' - assert result.is_name_implicit == True - assert isinstance(result, types.ForumTopic) - - -def test_json_loginurl(): - json_str = r'{"url": "https://example.com", "forward_text": "Forward", "bot_username": "botuser", "request_write_access": true}' - result = types.LoginUrl.de_json(json_str) - assert result.url == 'https://example.com' - assert result.forward_text == 'Forward' - assert result.bot_username == 'botuser' - assert result.request_write_access == True - assert isinstance(result, types.LoginUrl) - - -def test_json_webappinfo(): - json_str = r'{"url": "https://example.com"}' - result = types.WebAppInfo.de_json(json_str) - assert result.url == 'https://example.com' - assert isinstance(result, types.WebAppInfo) - - -def test_json_webappdata(): - json_str = r'{"data": "test_data", "button_text": "Button"}' - result = types.WebAppData.de_json(json_str) - assert result.data == 'test_data' - assert result.button_text == 'Button' - assert isinstance(result, types.WebAppData) - - -def test_json_maskposition(): - json_str = r'{"point": "forehead", "x_shift": 0.0, "y_shift": 0.0, "scale": 0.5}' - result = types.MaskPosition.de_json(json_str) - assert result.point == 'forehead' - assert result.x_shift == 0.0 - assert result.y_shift == 0.0 - assert result.scale == 0.5 - assert isinstance(result, types.MaskPosition) - - -def test_json_messageentity(): - json_str = r'{"type": "bold", "offset": 0, "length": 5, "url": "https://example.com", "language": "en", "unix_time": 1682189507, "date_time_format": "YYYY-MM-DD"}' - result = types.MessageEntity.de_json(json_str) - assert result.type == 'bold' - assert result.offset == 0 - assert result.length == 5 - assert result.url == 'https://example.com' - assert result.language == 'en' - assert result.unix_time == 1682189507 - assert result.date_time_format == 'YYYY-MM-DD' - assert isinstance(result, types.MessageEntity) - - -def test_json_messageentitycustomemoji(): - json_str = r'{"type": "custom_emoji", "offset": 0, "length": 10, "custom_emoji_id": "ce123"}' - result = types.MessageEntity.de_json(json_str) - assert result.type == 'custom_emoji' - assert result.offset == 0 - assert result.length == 10 - assert result.custom_emoji_id == 'ce123' - assert isinstance(result, types.MessageEntity) - - -def test_json_messageentitytextmention(): - json_str = r'{"type": "text_mention", "offset": 0, "length": 10, "user": {"id": 12345, "is_bot": false, "first_name": "Test"}}' - result = types.MessageEntity.de_json(json_str) - assert result.type == 'text_mention' - assert result.offset == 0 - assert result.length == 10 - assert isinstance(result.user, types.User) - assert isinstance(result, types.MessageEntity) - - -def test_json_chatshared(): - json_str = r'{"request_id": 1, "chat_id": 12345, "title": "Chat Title", "photo": {"small_file_id": "s", "small_file_unique_id": "su", "big_file_id": "b", "big_file_unique_id": "bu"}, "username": "chatuser"}' - result = types.ChatShared.de_json(json_str) - assert result.request_id == 1 - assert result.chat_id == 12345 - assert result.title == 'Chat Title' - # photo is returned as dict in this fork (not parsed to ChatPhoto) - assert isinstance(result.photo, dict) - assert result.photo.get('small_file_id') == 's' - assert result.username == 'chatuser' - assert isinstance(result, types.ChatShared) - - -def test_json_shareduser(): - json_str = r'{"user_id": 12345, "first_name": "Test", "last_name": "User", "username": "testuser", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}' - result = types.SharedUser.de_json(json_str) - assert result.user_id == 12345 - assert result.first_name == 'Test' - assert result.last_name == 'User' - assert result.username == 'testuser' - assert isinstance(result.photo, list) - assert isinstance(result.photo[0], types.PhotoSize) - assert isinstance(result, types.SharedUser) - - -def test_json_usersshared(): - json_str = r'{"request_id": 1, "users": [{"user_id": 12345, "first_name": "Test", "last_name": "User"}]}' - result = types.UsersShared.de_json(json_str) - assert result.request_id == 1 - assert isinstance(result.users, list) - assert isinstance(result, types.UsersShared) - - -def test_json_chatboost(): - json_str = r'{"boost_item_id": "b1", "add_date": 1682189507, "expiration_date": 1682275907, "source": {"source": "premium", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}}' - result = types.ChatBoost.de_json(json_str) - assert result.boost_id is None - assert result.add_date == 1682189507 - assert result.expiration_date == 1682275907 - assert isinstance(result.source, types.ChatBoostSourcePremium) - assert result.source.source == 'premium' - assert isinstance(result.source.user, types.User) - assert isinstance(result, types.ChatBoost) - - -def test_json_gift(): - json_str = r'{"id": 123456789, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100, "total_count": 5, "remaining_count": 3, "upgrade_star_count": 50, "personal_total_count": 10, "personal_remaining_count": 2, "is_premium": true, "has_colors": true, "background": {"center_color": 16777215, "edge_color": 16711680, "text_color": 0}, "publisher_chat": {"id": 1, "type": "channel", "title": "Publisher"}, "unique_gift_variant_count": 3}' - result = types.Gift.de_json(json_str) - assert result.id == 123456789 - assert isinstance(result.sticker, types.Sticker) - assert result.star_count == 100 - assert result.total_count == 5 - assert result.remaining_count == 3 - assert result.upgrade_star_count == 50 - assert result.personal_total_count == 10 - assert result.personal_remaining_count == 2 - assert result.is_premium == True - assert result.has_colors == True - assert isinstance(result.background, types.GiftBackground) - assert isinstance(result.publisher_chat, types.Chat) - assert result.unique_gift_variant_count == 3 - assert isinstance(result, types.Gift) - - -def test_json_giftinfo(): - json_str = r'{"gift": {"id": 123456789, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100}, "owned_gift_id": "og_123", "convert_star_count": 50, "prepaid_upgrade_star_count": 100, "can_be_upgraded": true, "text": {"type": "bold", "text": "Gift text"}, "entities": [{"type": "bold", "offset": 0, "length": 4}], "is_private": false, "is_upgrade_separate": false, "unique_gift_number": 42}' - result = types.GiftInfo.de_json(json_str) - assert isinstance(result.gift, types.Gift) - assert result.owned_gift_id == 'og_123' - assert result.convert_star_count == 50 - assert result.prepaid_upgrade_star_count == 100 - assert result.can_be_upgraded == True - assert result.text == {'type': 'bold', 'text': 'Gift text'} - assert isinstance(result.entities, list) - assert result.is_private == False - assert result.is_upgrade_separate == False - assert result.unique_gift_number == 42 - assert isinstance(result, types.GiftInfo) - - -def test_json_gifts(): - json_str = r'{"gifts": [{"id": 123456789, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100}]}' - result = types.Gifts.de_json(json_str) - assert isinstance(result.gifts, list) - assert isinstance(result, types.Gifts) - - -def test_json_richtextbold(): - json_str = r'{"type": "bold", "text": "Test"}' - result = types.RichText.de_json(json_str) - assert result.text == 'Test' - assert isinstance(result, types.RichTextBold) - - -def test_json_richtextitalic(): - json_str = r'{"type": "italic", "text": "Test"}' - result = types.RichText.de_json(json_str) - assert result.text == 'Test' - assert isinstance(result, types.RichTextItalic) - - -def test_json_richtextunderline(): - json_str = r'{"type": "underline", "text": "Test"}' - result = types.RichText.de_json(json_str) - assert result.text == 'Test' - assert isinstance(result, types.RichTextUnderline) - - -def test_json_richtextstrikethrough(): - json_str = r'{"type": "strikethrough", "text": "Test"}' - result = types.RichText.de_json(json_str) - assert result.text == 'Test' - assert isinstance(result, types.RichTextStrikethrough) - - -def test_json_richtextspoiler(): - json_str = r'{"type": "spoiler", "text": "Test"}' - result = types.RichText.de_json(json_str) - assert result.text == 'Test' - assert isinstance(result, types.RichTextSpoiler) - - -def test_json_richtextsubscript(): - json_str = r'{"type": "subscript", "text": "sub"}' - result = types.RichText.de_json(json_str) - assert result.text == 'sub' - assert isinstance(result, types.RichTextSubscript) - - -def test_json_richtextsuperscript(): - json_str = r'{"type": "superscript", "text": "sup"}' - result = types.RichText.de_json(json_str) - assert result.text == 'sup' - assert isinstance(result, types.RichTextSuperscript) - - -def test_json_richtextmarked(): - json_str = r'{"type": "marked", "text": "marked"}' - result = types.RichText.de_json(json_str) - assert result.text == 'marked' - assert isinstance(result, types.RichTextMarked) - - -def test_json_richtextcode(): - json_str = r'{"type": "code", "text": "code"}' - result = types.RichText.de_json(json_str) - assert result.text == 'code' - assert isinstance(result, types.RichTextCode) - - -def test_json_richtextanchor(): - json_str = r'{"type": "anchor", "name": "anchor"}' - result = types.RichText.de_json(json_str) - assert result.name == 'anchor' - assert isinstance(result, types.RichTextAnchor) - - -def test_json_richtextdatetime(): - json_str = r'{"type": "date_time", "text": "2024-01-01", "unix_time": 1704067200, "date_time_format": "YYYY-MM-DD"}' - result = types.RichText.de_json(json_str) - assert result.text == '2024-01-01' - assert result.unix_time == 1704067200 - assert result.date_time_format == 'YYYY-MM-DD' - assert isinstance(result, types.RichTextDateTime) - - -def test_json_richtexttextmention(): - json_str = r'{"type": "text_mention", "text": "test text", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}}' - result = types.RichText.de_json(json_str) - assert result.text == 'test text' - assert isinstance(result.user, types.User) - assert isinstance(result, types.RichTextTextMention) - - -def test_json_richtextanchorlink(): - json_str = r'{"type": "anchor_link", "text": "Link", "anchor_name": "anchor"}' - result = types.RichText.de_json(json_str) - assert result.text == 'Link' - assert result.anchor_name == 'anchor' - assert isinstance(result, types.RichTextAnchorLink) - - -def test_json_richtexturl(): - json_str = r'{"type": "url", "text": "click here", "url": "https://example.com"}' - result = types.RichText.de_json(json_str) - assert result.text == 'click here' - assert result.url == 'https://example.com' - assert isinstance(result, types.RichTextUrl) - - -def test_json_richtextemailaddress(): - json_str = r'{"type": "email_address", "text": "test@example.com", "email_address": "test@example.com"}' - result = types.RichText.de_json(json_str) - assert result.text == 'test@example.com' - assert result.email_address == 'test@example.com' - assert isinstance(result, types.RichTextEmailAddress) - - -def test_json_richtextphonenumber(): - json_str = r'{"type": "phone_number", "text": "+123****7890", "phone_number": "+123****7890"}' - result = types.RichText.de_json(json_str) - assert result.text == '+123****7890' - assert result.phone_number == '+123****7890' - assert isinstance(result, types.RichTextPhoneNumber) - - -def test_json_richtextbankcardnumber(): - json_str = r'{"type": "bank_card_number", "text": "1234 5678 9012 3456", "bank_card_number": "1234 5678 9012 3456"}' - result = types.RichText.de_json(json_str) - assert result.text == '1234 5678 9012 3456' - assert result.bank_card_number == '1234 5678 9012 3456' - assert isinstance(result, types.RichTextBankCardNumber) - - -def test_json_richblockparagraph(): - json_str = r'{"type": "paragraph", "text": "Test"}' - result = types.RichBlock.de_json(json_str) - assert result.text == 'Test' - assert isinstance(result, types.RichBlockParagraph) - - -def test_json_richblockpreformatted(): - json_str = r'{"type": "pre", "text": "Code", "language": "python"}' - result = types.RichBlock.de_json(json_str) - assert result.text == 'Code' - assert result.language == 'python' - assert isinstance(result, types.RichBlockPreformatted) - - -def test_json_richblockfooter(): - json_str = r'{"type": "footer", "text": "Footer"}' - result = types.RichBlock.de_json(json_str) - assert result.text == 'Footer' - assert isinstance(result, types.RichBlockFooter) - - -def test_json_richblockcaption(): - json_str = r'{"text": "Caption", "credit": "Author"}' - result = types.RichBlockCaption.de_json(json_str) - assert result.text == 'Caption' - assert result.credit == 'Author' - assert isinstance(result, types.RichBlockCaption) - - -def test_json_richblockanimation(): - json_str = r'{"type": "animation", "animation": {"file_id": "anim_id", "file_unique_id": "anim_uid", "width": 100, "height": 100, "duration": 10}, "caption": {"type": "bold", "text": "anim caption"}, "has_spoiler": true}' - result = types.RichBlock.de_json(json_str) - assert isinstance(result.animation, types.Animation) - assert result.has_spoiler == True - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockAnimation) - - -def test_json_richblockdetails(): - json_str = r'{"type": "details", "summary": {"text": "summary text"}, "blocks": [{"text": "detail"}], "is_open": false}' - result = types.RichBlock.de_json(json_str) - assert isinstance(result.summary, dict) or result.summary is None - assert isinstance(result.blocks, list) - assert result.is_open == False - assert isinstance(result, types.RichBlockDetails) - - -def test_json_richblocklistitem(): - json_str = r'{"label": {"text": "label text"}, "blocks": [{"text": "item block"}], "has_checkbox": true, "is_checked": true, "value": "item value", "type": null}' - result = types.RichBlockListItem.de_json(json_str) - assert isinstance(result.label, dict) - assert isinstance(result.blocks, list) - assert result.has_checkbox == True - assert result.is_checked == True - assert result.value == 'item value' - assert result.type is None - assert isinstance(result, types.RichBlockListItem) - - -def test_json_richblockvoicenote(): - json_str = r'{"type": "voice_note", "voice_note": {"file_id": "voice_id", "file_unique_id": "voice_uid", "duration": 30}, "caption": {"type": "bold", "text": "voice caption"}}' - result = types.RichBlock.de_json(json_str) - assert isinstance(result.voice_note, types.Voice) - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockVoiceNote) - - -def test_json_chatadministratorrights(): - json_str = r'{"is_anonymous": true, "can_manage_chat": true, "can_delete_messages": true, "can_manage_video_chats": true, "can_restrict_members": true, "can_promote_members": true, "can_change_info": true, "can_invite_users": true, "can_post_messages": true, "can_edit_messages": true, "can_pin_messages": true, "can_manage_topics": true, "can_post_stories": true, "can_edit_stories": true, "can_delete_stories": true, "can_manage_direct_messages": true, "can_manage_tags": true}' - result = types.ChatAdministratorRights.de_json(json_str) - assert result.is_anonymous == True - assert result.can_manage_chat == True - assert result.can_delete_messages == True - assert result.can_manage_video_chats == True - assert result.can_restrict_members == True - assert result.can_promote_members == True - assert result.can_change_info == True - assert result.can_invite_users == True - assert result.can_post_messages == True - assert result.can_edit_messages == True - assert result.can_pin_messages == True - assert result.can_manage_topics == True - assert result.can_post_stories == True - assert result.can_edit_stories == True - assert result.can_delete_stories == True - assert result.can_manage_direct_messages == True - assert result.can_manage_tags == True - assert isinstance(result, types.ChatAdministratorRights) - - -def test_json_chatpermissions(): - json_str = r'{"can_send_messages": true, "can_send_audios": true, "can_send_documents": true, "can_send_photos": true, "can_send_videos": true, "can_send_video_notes": true, "can_send_voice_notes": true, "can_send_polls": true, "can_send_other_messages": true, "can_add_web_page_previews": true, "can_change_info": true, "can_invite_users": true, "can_pin_messages": true, "can_manage_topics": true, "can_edit_tag": true, "can_react_to_messages": true}' - result = types.ChatPermissions.de_json(json_str) - assert result.can_send_messages == True - # can_send_media_messages is deprecated in this fork, not a real attribute - assert result.can_send_audios == True - assert result.can_send_documents == True - assert result.can_send_photos == True - assert result.can_send_videos == True - assert result.can_send_video_notes == True - assert result.can_send_voice_notes == True - assert result.can_send_polls == True - assert result.can_send_other_messages == True - assert result.can_add_web_page_previews == True - assert result.can_change_info == True - assert result.can_invite_users == True - assert result.can_pin_messages == True - assert result.can_manage_topics == True - assert result.can_edit_tag == True - assert result.can_react_to_messages == True - assert isinstance(result, types.ChatPermissions) - - -def test_json_chatmembermember(): - json_str = r'{"user": {"id": 1, "is_bot": false, "first_name": "Test"}, "status": "member", "until_date": 1682275907, "tag": "member_tag"}' - result = types.ChatMemberMember.de_json(json_str) - assert isinstance(result.user, types.User) - assert result.status == 'member' - assert result.until_date == 1682275907 - assert result.tag == 'member_tag' - assert isinstance(result, types.ChatMemberMember) - - -def test_json_chatmemberowner(): - json_str = r'{"status": "creator", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "is_anonymous": false, "custom_title": "Owner"}' - result = types.ChatMemberOwner.de_json(json_str) - assert isinstance(result.user, types.User) - assert result.status == 'creator' - assert result.is_anonymous == False - assert result.custom_title == 'Owner' - assert isinstance(result, types.ChatMemberOwner) - - -def test_json_chatmemberadministrator(): - json_str = r'{"status": "administrator", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "is_anonymous": true, "can_be_edited": true, "can_manage_chat": true, "can_delete_messages": true, "can_manage_video_chats": true, "can_restrict_members": true, "can_promote_members": true, "can_change_info": true, "can_invite_users": true, "can_post_stories": true, "can_edit_stories": true, "can_delete_stories": true, "can_post_messages": true, "can_edit_messages": true, "can_pin_messages": true, "can_manage_topics": true, "can_manage_direct_messages": true, "can_manage_tags": true, "custom_title": "mod"}' - result = types.ChatMemberAdministrator.de_json(json_str) - assert isinstance(result.user, types.User) - assert result.status == 'administrator' - assert result.can_be_edited == True - assert result.is_anonymous == True - assert result.can_manage_chat == True - assert result.can_delete_messages == True - assert result.can_manage_video_chats == True - assert result.can_restrict_members == True - assert result.can_promote_members == True - assert result.can_change_info == True - assert result.can_invite_users == True - assert result.can_post_stories == True - assert result.can_edit_stories == True - assert result.can_delete_stories == True - assert result.can_post_messages == True - assert result.can_edit_messages == True - assert result.can_pin_messages == True - assert result.can_manage_topics == True - assert result.custom_title == "mod" - assert result.can_manage_direct_messages == True - assert result.can_manage_tags == True - assert isinstance(result, types.ChatMemberAdministrator) - - -def test_json_chatmemberrestricted(): - json_str = r'{"status": "restricted", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "is_member": true, "can_send_messages": true, "can_send_audios": true, "can_send_documents": true, "can_send_photos": true, "can_send_videos": true, "can_send_video_notes": true, "can_send_voice_notes": true, "can_send_polls": true, "can_send_other_messages": true, "can_add_web_page_previews": true, "can_change_info": false, "can_invite_users": false, "can_pin_messages": false, "can_manage_topics": false, "until_date": 1682189507, "tag": "test_tag", "can_edit_tag": true, "can_react_to_messages": true}' - result = types.ChatMemberRestricted.de_json(json_str) - assert isinstance(result.user, types.User) - assert result.status == 'restricted' - assert result.is_member == True - assert result.can_send_messages == True - assert result.can_send_audios == True - assert result.can_send_documents == True - assert result.can_send_photos == True - assert result.can_send_videos == True - assert result.can_send_video_notes == True - assert result.can_send_voice_notes == True - assert result.can_send_polls == True - assert result.can_send_other_messages == True - assert result.can_add_web_page_previews == True - assert result.can_change_info == False - assert result.can_invite_users == False - assert result.can_pin_messages == False - assert result.can_manage_topics == False - assert result.until_date == 1682189507 - assert result.tag == 'test_tag' - assert result.can_edit_tag == True - assert result.can_react_to_messages == True - assert isinstance(result, types.ChatMemberRestricted) - - -def test_json_chatmemberleft(): - json_str = r'{"status": "left", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}}' - result = types.ChatMemberLeft.de_json(json_str) - assert isinstance(result.user, types.User) - assert result.status == 'left' - assert isinstance(result, types.ChatMemberLeft) - - -def test_json_chatmemberbanned(): - json_str = r'{"status": "kicked", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "until_date": 1682189507}' - result = types.ChatMemberBanned.de_json(json_str) - assert isinstance(result.user, types.User) - assert result.status == 'kicked' - assert result.until_date == 1682189507 - assert isinstance(result, types.ChatMemberBanned) - - -def test_json_botcommand(): - json_str = r'{"command": "/start", "description": "Start command", "is_ephemeral": true}' - result = types.BotCommand.de_json(json_str) - assert result.command == '/start' - assert result.description == 'Start command' - assert result.is_ephemeral == True - assert isinstance(result, types.BotCommand) - - -def test_json_botdescription(): - json_str = r'{"language_code": "en", "description": "Bot description"}' - result = types.BotDescription.de_json(json_str) - assert result.description == 'Bot description' - assert isinstance(result, types.BotDescription) - - -def test_json_botname(): - json_str = r'{"language_code": "en", "name": "Bot Name"}' - result = types.BotName.de_json(json_str) - assert result.name == 'Bot Name' - assert isinstance(result, types.BotName) - - -def test_json_botshortdescription(): - json_str = r'{"language_code": "en", "short_description": "Short"}' - result = types.BotShortDescription.de_json(json_str) - assert result.short_description == 'Short' - assert isinstance(result, types.BotShortDescription) - - -def test_json_inlinekeyboardbutton(): - json_str = r'{"text": "Button", "url": "https://example.com", "callback_data": "data", "web_app": {"url": "https://example.com"}, "switch_inline_query": "query", "switch_inline_query_current_chat": "query", "switch_inline_query_chosen_chat": {"query": "q", "allow_user_chats": true, "allow_bot_chats": true, "allow_group_chats": true, "allow_channel_chats": true}, "callback_game": {"type": "test"}, "pay": true, "login_url": {"url": "https://example.com", "forward_text": "Forward", "bot_username": "bot", "request_write_access": true}, "copy_text": {"text": "copy"}, "icon_custom_emoji_id": "emoji123", "style": "primary"}' - result = types.InlineKeyboardButton.de_json(json_str) - assert result.text == 'Button' - assert result.url == 'https://example.com' - assert result.callback_data == 'data' - assert isinstance(result.web_app, types.WebAppInfo) - assert result.switch_inline_query == 'query' - assert result.switch_inline_query_current_chat == 'query' - assert isinstance(result.switch_inline_query_chosen_chat, types.SwitchInlineQueryChosenChat) - assert isinstance(result.callback_game, dict) - assert result.pay == True - assert isinstance(result.login_url, types.LoginUrl) - assert isinstance(result.copy_text, types.CopyTextButton) - assert result.icon_custom_emoji_id == 'emoji123' - assert result.style == 'primary' - assert isinstance(result, types.InlineKeyboardButton) - - -def test_json_menubuttoncommands(): - json_str = r'{"type": "commands", "default_width": 100}' - result = types.MenuButtonCommands.de_json(json_str) - assert result.type == 'commands' - assert isinstance(result, types.MenuButtonCommands) - - -def test_json_menubuttondefault(): - json_str = r'{"type": "default"}' - result = types.MenuButtonDefault.de_json(json_str) - assert result.type == 'default' - assert isinstance(result, types.MenuButtonDefault) - - -def test_json_menubuttonwebapp(): - json_str = r'{"type": "web_app", "text": "Open App", "web_app": {"url": "https://example.com"}}' - result = types.MenuButtonWebApp.de_json(json_str) - assert result.type == 'web_app' - assert result.text == 'Open App' - assert isinstance(result.web_app, dict) - assert isinstance(result, types.MenuButtonWebApp) - - -def test_json_pollanswer(): - json_str = r'{"poll_id": "poll_id", "option_ids": [0], "option_persistent_ids": [0], "user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "voter_chat": {"id": 67890, "type": "channel", "title": "Channel"}}' - result = types.PollAnswer.de_json(json_str) - assert result.poll_id == 'poll_id' - assert isinstance(result.option_ids, list) - assert isinstance(result.option_persistent_ids, list) - assert isinstance(result.user, types.User) - assert isinstance(result.voter_chat, types.Chat) - assert isinstance(result, types.PollAnswer) - - -def test_json_reactiontype(): - json_str = r'{"type": "emoji", "emoji": "\u2764\uFE0F"}' - result = types.ReactionType.de_json(json_str) - assert result.type == 'emoji' - assert isinstance(result, types.ReactionType) - - -def test_linkpreviewoptionsto_dict(): - obj = types.LinkPreviewOptions(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_sentwebappmessageto_dict(): - obj = types.SentWebAppMessage(message_id=1) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_json_reactiontypepaid(): - json_str = r'{"type": "paid"}' - result = types.ReactionTypePaid.de_json(json_str) - assert isinstance(result, types.ReactionTypePaid) - - -def test_json_businessbotrights(): - result = types.BusinessBotRights.de_json({}) - assert result.can_reply is None - assert result.can_read_messages is None - assert result.can_delete_outgoing_messages is None - assert result.can_delete_all_messages is None - assert result.can_edit_name is None - assert result.can_edit_bio is None - assert result.can_edit_profile_photo is None - assert result.can_edit_username is None - assert result.can_change_gift_settings is None - assert result.can_view_gifts_and_stars is None - assert result.can_convert_gifts_to_stars is None - assert result.can_transfer_and_upgrade_gifts is None - assert result.can_transfer_stars is None - assert result.can_manage_stories is None - assert isinstance(result, types.BusinessBotRights) - - -def test_json_businessintro(): - json_str = r'{"title": "Business Title", "message": "Business message text", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}}' - result = types.BusinessIntro.de_json(json_str) - assert result.title == 'Business Title' - assert result.message == 'Business message text' - assert isinstance(result.sticker, types.Sticker) - assert isinstance(result, types.BusinessIntro) - - -def test_json_chatownerleft(): - result = types.ChatOwnerLeft.de_json({}) - assert isinstance(result, types.ChatOwnerLeft) or result is None - assert result.new_owner is None - - -def test_json_checklisttasksdone(): - json_str = r'{"checklist_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "checklist"}, "marked_as_done_task_ids": [1, 2], "marked_as_not_done_task_ids": [3]}' - result = types.ChecklistTasksDone.de_json(json_str) - assert isinstance(result.checklist_message, types.Message) - assert isinstance(result.marked_as_done_task_ids, list) - assert result.marked_as_done_task_ids == [1, 2] - assert isinstance(result.marked_as_not_done_task_ids, list) - assert result.marked_as_not_done_task_ids == [3] - assert isinstance(result, types.ChecklistTasksDone) - - -def test_json_communitychatadded(): - result = types.CommunityChatAdded.de_json({}) - assert isinstance(result, types.CommunityChatAdded) or result is None - assert result.community is None - - -def test_json_communitychatremoved(): - result = types.CommunityChatRemoved.de_json({}) - assert isinstance(result, types.CommunityChatRemoved) or result is None - - -def test_json_forumtopicclosed(): - result = types.ForumTopicClosed.de_json({}) - assert isinstance(result, types.ForumTopicClosed) or result is None - - -def test_json_forumtopicedited(): - result = types.ForumTopicEdited.de_json({'name': 'New Name', 'icon_custom_emoji_id': 'custom_emoji'}) - assert result.name == 'New Name' - assert result.icon_custom_emoji_id == 'custom_emoji' - assert isinstance(result, types.ForumTopicEdited) - - -def test_json_forumtopicreopened(): - result = types.ForumTopicReopened.de_json({}) - assert isinstance(result, types.ForumTopicReopened) or result is None - - -def test_json_generalforumtopichidden(): - result = types.GeneralForumTopicHidden.de_json({}) - assert isinstance(result, types.GeneralForumTopicHidden) or result is None - - -def test_json_generalforumtopicunhidden(): - result = types.GeneralForumTopicUnhidden.de_json({}) - assert isinstance(result, types.GeneralForumTopicUnhidden) or result is None - - -def test_json_giveawaycreated(): - result = types.GiveawayCreated.de_json({}) - assert isinstance(result, types.GiveawayCreated) or result is None - assert hasattr(result, 'prize_star_count') - - -def test_json_linkpreviewoptions(): - result = types.LinkPreviewOptions.de_json({}) - assert result.is_disabled is None - assert result.url is None - assert result.prefer_small_media is None - assert result.prefer_large_media is None - assert result.show_above_text is None - assert isinstance(result, types.LinkPreviewOptions) - - -def test_json_orderinfo(): - json_str = {'name': 'John', 'phone_number': '+1234567890', 'email': 'john@example.com', 'shipping_address': {'country_code': 'US', 'city': 'New York', 'street_line1': '123 Main St', 'street_line2': 'Apt 4B', 'postal_code': '10001', 'state': 'NY', 'post_code': '10001'}} - result = types.OrderInfo.de_json(json_str) - assert result.name == 'John' - assert result.phone_number == '+1234567890' - assert result.email == 'john@example.com' - assert isinstance(result.shipping_address, types.ShippingAddress) - assert isinstance(result, types.OrderInfo) or result is None - assert hasattr(result, 'name') - assert hasattr(result, 'phone_number') - assert hasattr(result, 'email') - - -def test_json_pollmedia(): - json_str = r'{"animation": {"file_id": "a", "file_unique_id": "au", "width": 100, "height": 100, "duration": 10}, "audio": {"file_id": "au1", "file_unique_id": "au1u", "duration": 30}, "document": {"file_id": "d", "file_unique_id": "du", "file_name": "test.pdf"}, "live_photo": {"file_id": "lp", "file_unique_id": "lpu", "width": 100, "height": 100, "duration": 5}, "location": {"latitude": 50.45, "longitude": 30.52}, "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}], "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "venue": {"location": {"latitude": 50.45, "longitude": 30.52}, "title": "Place", "address": "Addr"}, "video": {"file_id": "v", "file_unique_id": "vu", "width": 640, "height": 480, "duration": 30}, "link": {"url": "https://example.com", "shows_above_caption": true, "enhanced_smileys": true, "prefer_large_media": true}}' - result = types.PollMedia.de_json(json_str) - assert isinstance(result.animation, types.Animation) - assert isinstance(result.audio, types.Audio) - assert isinstance(result.document, types.Document) - assert isinstance(result.live_photo, types.LivePhoto) - assert isinstance(result.location, types.Location) - assert isinstance(result.photo, list) - assert isinstance(result.sticker, types.Sticker) - assert isinstance(result.venue, types.Venue) - assert isinstance(result.video, types.Video) - assert isinstance(result.link, types.Link) - assert isinstance(result, types.PollMedia) - - -def test_json_richblockdivider(): - json_str = r'{"type": "divider"}' - result = types.RichBlock.de_json(json_str) - assert isinstance(result, types.RichBlockDivider) - - -def test_json_sentwebappmessage(): - result = types.SentWebAppMessage.de_json({}) - assert isinstance(result, types.SentWebAppMessage) or result is None - assert hasattr(result, 'inline_message_id') - - -def test_json_suggestedpostdeclined(): - json_str = r'{"suggested_post_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "suggested"}, "comment": "declined reason"}' - result = types.SuggestedPostDeclined.de_json(json_str) - assert isinstance(result.suggested_post_message, types.Message) - assert result.comment == 'declined reason' - assert isinstance(result, types.SuggestedPostDeclined) - - -def test_json_switchinlinequerychosenchat(): - json_str = r'{"query": "test", "allow_user_chats": true, "allow_bot_chats": true, "allow_group_chats": true, "allow_channel_chats": true}' - result = types.SwitchInlineQueryChosenChat.de_json(json_str) - assert result.query == 'test' - assert result.allow_user_chats == True - assert result.allow_bot_chats == True - assert result.allow_group_chats == True - assert result.allow_channel_chats == True - assert isinstance(result, types.SwitchInlineQueryChosenChat) - - -def test_json_transactionpartnertelegramads(): - result = types.TransactionPartnerTelegramAds.de_json(None) - assert isinstance(result, types.TransactionPartnerTelegramAds) or result is None - - -def test_json_videochatstarted(): - result = types.VideoChatStarted.de_json({}) - assert isinstance(result, types.VideoChatStarted) or result is None - - -def test_json_voicechatstarted(): - result = types.VoiceChatStarted.de_json({}) - assert isinstance(result, types.VoiceChatStarted) or result is None - - -def test_json_writeaccessallowed(): - result = types.WriteAccessAllowed.de_json({'from_request': True, 'web_app_name': 'TestApp', 'from_attachment_menu': False}) - assert result.from_request == True - assert result.web_app_name == 'TestApp' - assert result.from_attachment_menu == False - assert isinstance(result, types.WriteAccessAllowed) - - -def test_json_acceptedgifttypes(): - json_str = r'{"unlimited_gifts": "test", "limited_gifts": "test", "unique_gifts": "test", "premium_subscription": "test", "gifts_from_channels": "test"}' - result = types.AcceptedGiftTypes.de_json(json_str) - assert result.unlimited_gifts == 'test' - assert result.limited_gifts == 'test' - assert result.unique_gifts == 'test' - assert result.premium_subscription == 'test' - assert result.gifts_from_channels == 'test' - assert isinstance(result, types.AcceptedGiftTypes) - - -def test_json_copytextbutton(): - json_str = r'{"text": "Test"}' - result = types.CopyTextButton.de_json(json_str) - assert result.text == 'Test' - assert isinstance(result, types.CopyTextButton) - - -def test_json_dice(): - json_str = r'{"value": "test", "emoji": "😀"}' - result = types.Dice.de_json(json_str) - assert result.value == 'test' - assert result.emoji == '😀' - assert isinstance(result, types.Dice) - - -def test_json_richblocktablecell(): - json_str = r'{"align": "test", "valign": "test", "text": "Test", "is_header": true, "colspan": "test", "rowspan": "test"}' - result = types.RichBlockTableCell.de_json(json_str) - assert result.align == 'test' - assert result.valign == 'test' - assert result.text == 'Test' - assert result.is_header == True - assert result.colspan == 'test' - assert result.rowspan == 'test' - assert isinstance(result, types.RichBlockTableCell) - - -def test_json_richtextbotcommand(): - json_str = r'{"type": "bot_command", "text": "Test", "bot_command": "test"}' - result = types.RichText.de_json(json_str) - assert result.text == 'Test' - assert result.bot_command == 'test' - assert isinstance(result, types.RichTextBotCommand) - - -def test_json_richtextcashtag(): - json_str = r'{"type": "cashtag", "text": "Test", "cashtag": "test"}' - result = types.RichText.de_json(json_str) - assert result.text == 'Test' - assert result.cashtag == 'test' - assert isinstance(result, types.RichTextCashtag) - - -def test_json_richtextcustomemoji(): - json_str = r'{"type": "custom_emoji", "custom_emoji_id": "test", "alternative_text": "test"}' - result = types.RichText.de_json(json_str) - assert result.custom_emoji_id == 'test' - assert result.alternative_text == 'test' - assert isinstance(result, types.RichTextCustomEmoji) - - -def test_json_richtexthashtag(): - json_str = r'{"type": "hashtag", "text": "Test", "hashtag": "test"}' - result = types.RichText.de_json(json_str) - assert result.text == 'Test' - assert result.hashtag == 'test' - assert isinstance(result, types.RichTextHashtag) - - -def test_json_richtextmathematicalexpression(): - json_str = r'{"type": "mathematical_expression", "expression": "test"}' - result = types.RichText.de_json(json_str) - assert result.expression == 'test' - assert isinstance(result, types.RichTextMathematicalExpression) - - -def test_json_richtextmention(): - json_str = r'{"type": "mention", "text": "Test", "username": "test"}' - result = types.RichText.de_json(json_str) - assert result.text == 'Test' - assert result.username == 'test' - assert isinstance(result, types.RichTextMention) - - -def test_json_richtextreference(): - json_str = r'{"type": "reference", "text": "Test", "name": "Test"}' - result = types.RichText.de_json(json_str) - assert result.text == 'Test' - assert result.name == 'Test' - assert isinstance(result, types.RichTextReference) - - -def test_json_richtextreferencelink(): - json_str = r'{"type": "reference_link", "text": "Test", "reference_name": "test"}' - result = types.RichText.de_json(json_str) - assert result.text == 'Test' - assert result.reference_name == 'test' - assert isinstance(result, types.RichTextReferenceLink) - - -def test_json_suggestedpostprice(): - json_str = r'{"currency": "en", "amount": 1}' - result = types.SuggestedPostPrice.de_json(json_str) - assert result.currency == 'en' - assert result.amount == 1 - assert isinstance(result, types.SuggestedPostPrice) - - -def test_json_affiliateinfo(): - json_str = r'{"commission_per_mille": 1000, "amount": 100, "affiliate_user": {"id": 1, "is_bot": false, "first_name": "User"}, "affiliate_chat": {"id": -1001234567890, "type": "channel", "title": "Channel"}, "nanostar_amount": 10000000}' - result = types.AffiliateInfo.de_json(json_str) - assert result.commission_per_mille == 1000 - assert result.amount == 100 - assert isinstance(result.affiliate_user, types.User) - assert isinstance(result.affiliate_chat, types.Chat) - assert result.nanostar_amount == 10000000 - assert isinstance(result, types.AffiliateInfo) - - -def test_json_backgroundfill(): - # BackgroundFill is abstract - test BackgroundFillSolid directly - json_str = r'{"type": "solid", "color": 123456}' - result = types.BackgroundFillSolid.de_json(json_str) - assert isinstance(result, types.BackgroundFillSolid) - - -def test_json_backgroundfillfreeformgradient(): - json_str = r'{"type": "freeform_gradient", "colors": [123456, 654321, 111222]}' - result = types.BackgroundFillFreeformGradient.de_json(json_str) - assert result.type == 'freeform_gradient' - assert isinstance(result.colors, list) - assert isinstance(result, types.BackgroundFillFreeformGradient) - - -def test_json_backgroundfillgradient(): - json_str = r'{"type": "gradient", "top_color": 123456, "bottom_color": 654321, "rotation_angle": 180}' - result = types.BackgroundFillGradient.de_json(json_str) - assert result.type == 'gradient' - assert result.top_color == 123456 - assert result.bottom_color == 654321 - assert result.rotation_angle == 180 - assert isinstance(result, types.BackgroundFillGradient) - - -def test_json_backgroundfillsolid(): - json_str = r'{"type": "solid", "color": 123456}' - result = types.BackgroundFillSolid.de_json(json_str) - assert result.type == 'solid' - assert result.color == 123456 - assert isinstance(result, types.BackgroundFillSolid) - - -def test_json_backgroundtype(): - # BackgroundType is abstract - test BackgroundTypeFill directly - json_str = r'{"type": "fill", "fill": {"type": "solid", "color": 123456}, "dark_theme_dimming": 0}' - result = types.BackgroundTypeFill.de_json(json_str) - assert isinstance(result, types.BackgroundTypeFill) - - -def test_json_backgroundtypechattheme(): - json_str = r'{"type": "fill", "theme_name": "test"}' - result = types.BackgroundTypeChatTheme.de_json(json_str) - assert result.type == 'fill' - assert result.theme_name == 'test' - assert isinstance(result, types.BackgroundTypeChatTheme) - - -def test_json_backgroundtypefill(): - json_str = r'{"type": "solid", "fill": {"type": "solid", "color": 123456}, "dark_theme_dimming": 0}' - result = types.BackgroundTypeFill.de_json(json_str) - assert result.type == 'solid' - assert isinstance(result.fill, types.BackgroundFill) - assert result.dark_theme_dimming == 0 - assert isinstance(result, types.BackgroundTypeFill) - - -def test_json_backgroundtypepattern(): - json_str = r'{"type": "pattern", "document": {"file_id": "doc", "file_unique_id": "docu", "mime_type": "application/pdf", "file_name": "test.pdf"}, "fill": {"type": "solid", "color": 123456}, "intensity": 0, "is_inverted": true, "is_moving": true}' - result = types.BackgroundTypePattern.de_json(json_str) - assert result.type == 'pattern' - assert isinstance(result.document, types.Document) - assert isinstance(result.fill, dict) or result.fill is None - assert result.intensity == 0 - assert result.is_inverted == True - assert result.is_moving == True - assert isinstance(result, types.BackgroundTypePattern) - - -def test_json_backgroundtypewallpaper(): - json_str = r'{"type": "wallpaper", "document": {"file_id": "doc", "file_unique_id": "docu", "mime_type": "application/pdf", "file_name": "test.pdf"}, "dark_theme_dimming": 0, "is_blurred": true, "is_moving": true}' - result = types.BackgroundTypeWallpaper.de_json(json_str) - assert result.type == 'wallpaper' - assert isinstance(result.document, types.Document) - assert result.dark_theme_dimming == 0 - assert result.is_blurred == True - assert result.is_moving == True - assert isinstance(result, types.BackgroundTypeWallpaper) - - -def test_json_birthdate(): - json_str = r'{"day": "test", "month": "test", "year": 1990}' - result = types.Birthdate.de_json(json_str) - assert result.day == 'test' - assert result.month == 'test' - assert result.year == 1990 - assert isinstance(result, types.Birthdate) - - -def test_json_botaccesssettings(): - json_str = r'{"is_access_restricted": false, "added_users": [{"id": 1, "is_bot": false, "first_name": "Test"}, {"id": 2, "is_bot": false, "first_name": "User2"}]}' - result = types.BotAccessSettings.de_json(json_str) - assert result.is_access_restricted == False - assert isinstance(result.added_users, list) - assert len(result.added_users) == 2 - assert isinstance(result.added_users[0], types.User) - assert result.added_users[0].id == 1 - assert isinstance(result, types.BotAccessSettings) - - -def test_json_botsubscriptionupdated(): - json_str = r'{"user": {"id": 1, "is_bot": false, "first_name": "Test"}, "invoice_payload": "test_payload", "state": "default"}' - result = types.BotSubscriptionUpdated.de_json(json_str) - assert isinstance(result.user, types.User) - assert result.invoice_payload == 'test_payload' - assert result.state == 'default' - assert isinstance(result, types.BotSubscriptionUpdated) - - -def test_json_businessconnection(): - json_str = r'{"id": "1", "user": {"id": 1, "is_bot": false, "first_name": "Test"}, "user_chat_id": 1, "date": 1682189507, "is_enabled": false, "rights": {"can_reply": true, "can_read_messages": true, "can_delete_outgoing_messages": false, "can_delete_all_messages": false, "can_edit_name": true, "can_edit_bio": false, "can_edit_profile_photo": true, "can_edit_username": false, "can_change_gift_settings": true, "can_view_gifts_and_stars": false, "can_convert_gifts_to_stars": true, "can_transfer_and_upgrade_gifts": false, "can_transfer_stars": true, "can_manage_stories": false}}' - result = types.BusinessConnection.de_json(json_str) - assert result.id == '1' - assert isinstance(result.user, types.User) - assert result.user_chat_id == 1 - assert result.date == 1682189507 - assert result.is_enabled == False - assert isinstance(result.rights, types.BusinessBotRights) - assert result.rights.can_reply == True - assert result.rights.can_read_messages == True - assert result.rights.can_delete_outgoing_messages == False - assert result.rights.can_delete_all_messages == False - assert result.rights.can_edit_name == True - assert result.rights.can_edit_bio == False - assert result.rights.can_edit_profile_photo == True - assert result.rights.can_edit_username == False - assert result.rights.can_change_gift_settings == True - assert result.rights.can_view_gifts_and_stars == False - assert result.rights.can_convert_gifts_to_stars == True - assert result.rights.can_transfer_and_upgrade_gifts == False - assert result.rights.can_transfer_stars == True - assert result.rights.can_manage_stories == False - assert isinstance(result, types.BusinessConnection) - - -def test_json_businesslocation(): - json_str = r'{"address": "NY", "location": {"latitude": 50.45, "longitude": 30.52, "horizontal_accuracy": 1.5}}' - result = types.BusinessLocation.de_json(json_str) - assert result.address == 'NY' - assert isinstance(result.location, types.Location) - assert result.location.latitude == 50.45 - assert result.location.longitude == 30.52 - assert result.location.horizontal_accuracy == 1.5 - assert isinstance(result, types.BusinessLocation) - - -def test_json_businessmessagesdeleted(): - json_str = r'{"business_connection_id": 1, "chat": {"id": 1, "type": "private", "title": "Test"}, "message_ids": "test"}' - result = types.BusinessMessagesDeleted.de_json(json_str) - assert result.business_connection_id == 1 - assert isinstance(result.chat, types.Chat) - assert result.message_ids == 'test' - assert isinstance(result, types.BusinessMessagesDeleted) - - -def test_json_businessopeninghours(): - json_str = r'{"time_zone_name": "test", "opening_hours": [{"opening_minute": 0, "closing_minute": 60}]}' - result = types.BusinessOpeningHours.de_json(json_str) - assert result.time_zone_name == 'test' - assert isinstance(result.opening_hours, list) - assert isinstance(result, types.BusinessOpeningHours) - - -def test_json_businessopeninghoursinterval(): - json_str = r'{"opening_minute": 0, "closing_minute": 60}' - result = types.BusinessOpeningHoursInterval.de_json(json_str) - assert result.opening_minute == 0 - assert result.closing_minute == 60 - assert isinstance(result, types.BusinessOpeningHoursInterval) - - -def test_json_callbackquery(): - # json_string is internal field, not covered (like Message.options/json_string) - json_str = r'{"id": "cq1", "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "data": "test", "chat_instance": "ci1", "message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "Hello"}, "inline_message_id": "im1", "game_short_name": "game"}' - result = types.CallbackQuery.de_json(json_str) - assert result.id == 'cq1' - assert isinstance(result.from_user, types.User) - assert result.data == 'test' - assert result.chat_instance == 'ci1' - assert isinstance(result.message, types.Message) - assert result.inline_message_id == 'im1' - assert result.game_short_name == 'game' - assert isinstance(result, types.CallbackQuery) - - -def test_json_chatbackground(): - json_str = r'{"type": {"type": "fill", "fill": {"type": "solid", "color": 123456}, "dark_theme_dimming": 0}}' - result = types.ChatBackground.de_json(json_str) - assert isinstance(result.type, types.BackgroundTypeFill) or isinstance(result.type, dict) - assert isinstance(result, types.ChatBackground) - assert hasattr(result, 'type') - - -def test_json_chatboostadded(): - json_str = r'{"boost_count": "test"}' - result = types.ChatBoostAdded.de_json(json_str) - assert result.boost_count == 'test' - assert isinstance(result, types.ChatBoostAdded) - - -def test_json_chatboostremoved(): - json_str = r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "boost_id": 1, "remove_date": 1682189507, "source": {"source": "premium", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}}' - result = types.ChatBoostRemoved.de_json(json_str) - assert isinstance(result.chat, types.Chat) - assert result.boost_id == 1 - assert result.remove_date == 1682189507 - assert isinstance(result.source, types.ChatBoostSource) - assert isinstance(result, types.ChatBoostRemoved) - - -def test_json_chatboostsource(): - # ChatBoostSource is abstract - test ChatBoostSourcePremium directly - json_str = r'{"source": "premium", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}' - result = types.ChatBoostSourcePremium.de_json(json_str) - assert isinstance(result, types.ChatBoostSourcePremium) - - -def test_json_chatboostsourcegiftcode(): - json_str = r'{"source": "gift_code", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}' - result = types.ChatBoostSourceGiftCode.de_json(json_str) - assert result.source == 'gift_code' - assert isinstance(result.user, types.User) - assert isinstance(result, types.ChatBoostSourceGiftCode) - - -def test_json_chatboostsourcegiveaway(): - json_str = r'{"source": "giveaway", "giveaway_message_id": 1, "user": {"id": 1, "is_bot": false, "first_name": "Test"}, "is_unclaimed": false, "prize_star_count": 100}' - result = types.ChatBoostSourceGiveaway.de_json(json_str) - assert result.source == 'giveaway' - assert result.giveaway_message_id == 1 - assert isinstance(result.user, types.User) - assert result.is_unclaimed == False - assert result.prize_star_count == 100 - assert isinstance(result, types.ChatBoostSourceGiveaway) - - -def test_json_chatboostsourcepremium(): - json_str = r'{"source": "premium", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}' - result = types.ChatBoostSourcePremium.de_json(json_str) - assert result.source == 'premium' - assert isinstance(result.user, types.User) - assert isinstance(result, types.ChatBoostSourcePremium) - - -def test_json_chatboostupdated(): - json_str = r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "boost": {"boost_item_id": "b1", "add_date": 1682189507, "expiration_date": 1682275907}}' - result = types.ChatBoostUpdated.de_json(json_str) - assert isinstance(result.chat, types.Chat) - assert isinstance(result.boost, types.ChatBoost) - assert isinstance(result.boost.boost_id, str) or result.boost.boost_id is None - assert isinstance(result.boost.add_date, int) - assert isinstance(result.boost.expiration_date, int) - assert isinstance(result, types.ChatBoostUpdated) - - -def test_json_chatjoinrequest(): - json_str = r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "user_chat_id": 1, "date": 1682189507, "bio": "Hello", "invite_link": {"invite_link": "https://t.me/joinchat/ABC", "creator": {"id": 1, "is_bot": false, "first_name": "Test"}, "is_primary": true, "is_revoked": false, "creates_join_request": false}, "query_id": "query123"}' - result = types.ChatJoinRequest.de_json(json_str) - assert isinstance(result.chat, types.Chat) - assert isinstance(result.from_user, types.User) - assert result.from_user.id == 1 - assert result.from_user.first_name == 'Test' - assert result.user_chat_id == 1 - assert result.date == 1682189507 - assert result.bio == 'Hello' - assert isinstance(result.invite_link, types.ChatInviteLink) - assert result.query_id == 'query123' - assert isinstance(result, types.ChatJoinRequest) - - -def test_json_chatfullinfo(): - json_str = r'{"id": 1, "type": "private", "title": "Test Chat", "username": "testchat", "first_name": "John", "last_name": "Doe", "photo": {"small_file_id": "s", "small_file_unique_id": "su", "big_file_id": "b", "big_file_unique_id": "bu"}, "bio": "bio text", "has_private_forwards": true, "description": "desc", "pinned_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}}, "permissions": {"can_send_messages": true, "can_send_audios": true, "can_send_documents": true, "can_send_photos": true, "can_send_videos": true, "can_send_video_notes": true, "can_send_voice_notes": true, "can_send_polls": true, "can_send_other_messages": true, "can_add_web_page_previews": true, "can_change_info": true, "can_invite_users": true, "can_pin_messages": true, "can_manage_topics": true}, "slow_mode_delay": 30, "message_auto_delete_time": 86400, "has_protected_content": true, "sticker_set_name": "sticker_set", "can_set_sticker_set": false, "linked_chat_id": 2, "location": {"chat": {"id": 1, "type": "supergroup", "title": "Loc"}, "location": {"latitude": 50.45, "longitude": 30.52}, "address": "Main St"}, "join_to_send_messages": false, "join_by_request": true, "has_restricted_voice_and_video_messages": false, "is_forum": true, "max_reaction_count": 10, "active_usernames": ["test"], "emoji_status_custom_emoji_id": "custom_emoji", "has_hidden_members": false, "has_aggressive_anti_spam_enabled": false, "emoji_status_expiration_date": 1682275907, "available_reactions": ["emoji", "custom_emoji"], "accent_color_id": 1, "background_custom_emoji_id": "bg_emoji", "profile_accent_color_id": 2, "profile_background_custom_emoji_id": "profile_bg", "has_visible_history": true, "unrestrict_boost_count": 5, "custom_emoji_sticker_set_name": "custom_stickers", "personal_chat": {"id": 3, "type": "private", "title": "Personal"}, "birthdate": {"day": "15", "month": "6"}, "can_send_paid_media": true, "is_direct_messages": true, "parent_chat": {"id": 4, "type": "supergroup", "title": "Parent"}, "rating": {"level": "test", "rating": "test", "current_level_rating": "test"}, "paid_message_star_count": 5, "invite_link": "https://t.me/joinchat/ABC", "business_intro": {"title": "B", "description": "D"}, "business_location": {"address": "NY", "has_active_address": true}, "business_opening_hours": {"time_zone_name": "UTC", "opening_hours": [{"opening_minute": 540, "closing_minute": 1020, "day_of_week": 1, "is_recurring": true}]}, "accepted_gift_types": {"unlimited_gifts": false, "limited_gifts": false, "unique_gifts": true, "premium_subscription": false, "gifts_from_channels": false}, "first_profile_audio": {"file_id": "fa1", "file_unique_id": "fa1u", "duration": 30, "mime_type": "audio/ogg"}, "unique_gift_colors": {"model_custom_emoji_id": 1, "symbol_custom_emoji_id": 1, "light_theme_main_color": 333333, "light_theme_other_colors": [444444], "dark_theme_main_color": 555555, "dark_theme_other_colors": [666666]}, "guard_bot": {"id": 2, "is_bot": true, "first_name": "GuardBot"}, "community": {"id": 5, "name": "Community"}}' - result = types.ChatFullInfo.de_json(json_str) - assert result.id == 1 - assert result.type == 'private' - assert result.title == 'Test Chat' - assert result.username == 'testchat' - assert result.first_name == 'John' - assert result.last_name == 'Doe' - assert isinstance(result.photo, types.ChatPhoto) - assert result.bio == 'bio text' - assert result.has_private_forwards == True - assert result.description == 'desc' - assert result.invite_link == "https://t.me/joinchat/ABC" - assert isinstance(result.pinned_message, types.Message) - assert isinstance(result.permissions, types.ChatPermissions) - assert result.slow_mode_delay == 30 - assert result.message_auto_delete_time == 86400 - assert result.has_protected_content == True - assert result.sticker_set_name == 'sticker_set' - assert result.can_set_sticker_set == False - assert result.linked_chat_id == 2 - assert isinstance(result.location, types.ChatLocation) - assert result.join_to_send_messages == False - assert result.join_by_request == True - assert result.has_restricted_voice_and_video_messages == False - assert result.is_forum == True - assert result.max_reaction_count == 10 - assert result.active_usernames == ['test'] - assert result.emoji_status_custom_emoji_id == 'custom_emoji' - assert result.has_hidden_members == False - assert result.has_aggressive_anti_spam_enabled == False - assert result.emoji_status_expiration_date == 1682275907 - assert isinstance(result.available_reactions, list) - assert result.accent_color_id == 1 - assert result.background_custom_emoji_id == 'bg_emoji' - assert result.profile_accent_color_id == 2 - assert result.profile_background_custom_emoji_id == 'profile_bg' - assert result.has_visible_history == True - assert result.unrestrict_boost_count == 5 - assert result.custom_emoji_sticker_set_name == 'custom_stickers' - assert isinstance(result.business_intro, types.BusinessIntro) - assert isinstance(result.business_location, types.BusinessLocation) - assert isinstance(result.business_opening_hours, types.BusinessOpeningHours) - assert isinstance(result.personal_chat, types.Chat) - assert isinstance(result.birthdate, types.Birthdate) - assert result.can_send_paid_media == True - assert isinstance(result.accepted_gift_types, types.AcceptedGiftTypes) - assert result.is_direct_messages == True - assert isinstance(result.parent_chat, types.Chat) - assert isinstance(result.rating, types.UserRating) - assert result.paid_message_star_count == 5 - assert isinstance(result.unique_gift_colors, types.UniqueGiftColors) - assert isinstance(result.first_profile_audio, types.Audio) - assert isinstance(result.guard_bot, types.User) - assert isinstance(result.community, types.Community) - assert isinstance(result, types.ChatFullInfo) - - -def test_json_chatmember(): - # ChatMember is abstract - test ChatMemberMember directly - json_str = r'{"status": "member", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}' - result = types.ChatMemberMember.de_json(json_str) - assert isinstance(result.user, types.User) - assert result.status == 'member' - assert isinstance(result, types.ChatMemberMember) - - -def test_json_chatmemberupdated(): - json_str = r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "date": 1682189507, "old_chat_member": {"user": {"id": 1, "is_bot": false, "first_name": "Test"}, "status": "member"}, "new_chat_member": {"user": {"id": 1, "is_bot": false, "first_name": "Test"}, "status": "member"}, "via_join_request": true, "via_chat_folder_invite_link": true, "invite_link": {"invite_link": "https://t.me/joinchat/ABC", "creator": {"id": 1, "is_bot": false, "first_name": "Test"}, "creates_join_request": false, "is_primary": true, "is_revoked": false}}' - result = types.ChatMemberUpdated.de_json(json_str) - assert isinstance(result.chat, types.Chat) - assert isinstance(result.from_user, types.User) - assert result.date == 1682189507 - assert isinstance(result.old_chat_member, types.ChatMember) - assert isinstance(result.new_chat_member, types.ChatMember) - assert isinstance(result.invite_link, types.ChatInviteLink) - assert result.invite_link.invite_link == 'https://t.me/joinchat/ABC' - assert isinstance(result.invite_link.creator, types.User) - assert result.invite_link.creates_join_request == False - assert result.invite_link.is_primary == True - assert result.invite_link.is_revoked == False - assert result.via_join_request == True - assert result.via_chat_folder_invite_link == True - assert isinstance(result, types.ChatMemberUpdated) - - -def test_json_chatownerchanged(): - json_str = r'{"new_owner": {"id": 1, "is_bot": false, "first_name": "Test"}}' - result = types.ChatOwnerChanged.de_json(json_str) - assert isinstance(result.new_owner, types.User) - assert isinstance(result, types.ChatOwnerChanged) - - -def test_json_chatphoto(): - json_str = r'{"small_file_id": 1, "small_file_unique_id": 1, "big_file_id": 1, "big_file_unique_id": 1}' - result = types.ChatPhoto.de_json(json_str) - assert result.small_file_id == 1 - assert result.small_file_unique_id == 1 - assert result.big_file_id == 1 - assert result.big_file_unique_id == 1 - assert isinstance(result, types.ChatPhoto) - - -def test_json_checklist(): - json_str = r'{"title": "test", "tasks": [{"id": 1, "text": "test", "is_checked": false}], "others_can_add_tasks": true, "others_can_mark_tasks_as_done": true, "title_entities": [{"type": "bold", "offset": 0, "length": 4}]}' - result = types.Checklist.de_json(json_str) - assert result.title == 'test' - assert isinstance(result.tasks, list) - assert isinstance(result.title_entities, list) - assert result.others_can_add_tasks == True - assert result.others_can_mark_tasks_as_done == True - assert isinstance(result, types.Checklist) - - -def test_json_checklisttask(): - json_str = r'{"id": 1, "text": {"type": "bold", "text": "Task text"}, "text_entities": [{"type": "bold", "offset": 0, "length": 9}], "completed_by_user": {"id": 1, "is_bot": false, "first_name": "User"}, "completed_by_chat": {"id": 1, "type": "private"}, "completion_date": 1682189507}' - result = types.ChecklistTask.de_json(json_str) - assert result.id == 1 - assert result.text == {"type": "bold", "text": "Task text"} - assert isinstance(result.text_entities, list) - assert isinstance(result.completed_by_user, types.User) - assert isinstance(result.completed_by_chat, types.Chat) - assert result.completion_date == 1682189507 - assert isinstance(result, types.ChecklistTask) - - -def test_json_checklisttasksadded(): - json_str = r'{"tasks": [{"id": "t1", "text": "task"}], "checklist_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "checklist"}}' - result = types.ChecklistTasksAdded.de_json(json_str) - assert isinstance(result.tasks, list) - assert isinstance(result.checklist_message, types.Message) - assert isinstance(result, types.ChecklistTasksAdded) - - -def test_json_choseninlineresult(): - json_str = r'{"result_id": "res1", "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "query": "test", "location": {"latitude": 50.45, "longitude": 30.52, "horizontal_accuracy": 1.5, "live_period": 3600}, "inline_message_id": "im1"}' - result = types.ChosenInlineResult.de_json(json_str) - assert result.result_id == 'res1' - assert isinstance(result.from_user, types.User) - assert result.query == 'test' - assert isinstance(result.location, types.Location) - assert result.inline_message_id == 'im1' - assert isinstance(result, types.ChosenInlineResult) - - -def test_json_community(): - json_str = r'{"id": 1, "name": "test"}' - result = types.Community.de_json(json_str) - assert result.id == 1 - assert result.name == 'test' - assert isinstance(result, types.Community) - - -def test_json_directmessagepricechanged(): - json_str = r'{"are_direct_messages_enabled": true, "direct_message_star_count": 5}' - result = types.DirectMessagePriceChanged.de_json(json_str) - assert result.are_direct_messages_enabled == True - assert result.direct_message_star_count == 5 - assert isinstance(result, types.DirectMessagePriceChanged) - - -def test_json_directmessagestopic(): - json_str = r'{"topic_id": 1, "user": {"id": 1, "is_bot": false, "first_name": "Test"}}' - result = types.DirectMessagesTopic.de_json(json_str) - assert result.topic_id == 1 - assert isinstance(result.user, types.User) - assert result.user.id == 1 - assert result.user.first_name == 'Test' - assert isinstance(result, types.DirectMessagesTopic) - - -def test_json_externalreplyinfo(): - json_str = r'{"origin": {"type": "user", "date": 1682189507, "sender_user": {"id": 1, "is_bot": false, "first_name": "Test"}}, "chat": {"id": 1, "type": "private"}, "message_id": 42, "link_preview_options": {"url": "https://example.com", "shows_above_caption": true, "enhanced_smileys": true, "prefer_large_media": true}, "animation": {"file_id": "anim", "file_unique_id": "aniu", "width": 100, "height": 100, "duration": 10}, "audio": {"file_id": "au1", "file_unique_id": "au1u", "duration": 30}, "document": {"file_id": "doc1", "file_unique_id": "doc1u", "file_name": "test.pdf"}, "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}], "sticker": {"file_id": "st1", "file_unique_id": "st1u", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "story": {"chat": {"id": 1, "type": "private"}, "id": 1}, "video": {"file_id": "v1", "file_unique_id": "v1u", "width": 640, "height": 480, "duration": 30}, "video_note": {"file_id": "vn1", "file_unique_id": "vn1u", "duration": 10, "length": 512}, "voice": {"file_id": "vo1", "file_unique_id": "vo1u", "duration": 10}, "has_media_spoiler": true, "contact": {"phone_number": "+123", "first_name": "John"}, "dice": {"emoji": "🎲", "value": 5}, "game": {"id": "g1", "title": "Game", "description": "Test", "text": "Play", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}, "giveaway": {"chats": [{"id": 1, "type": "private"}], "winners_selection_date": 1682189507, "winner_count": 1, "only_new_members": false, "has_public_winners": false, "prize_description": "Prize", "premium_subscription_month_count": 0, "prize_star_count": 0}, "giveaway_winners": {"chat": {"id": 1, "type": "private"}, "giveaway_message_id": 1, "winners_selection_date": 1682189507, "winner_count": 1, "winners": [{"id": 1, "is_bot": false, "first_name": "Test"}], "additional_chat_count": 0, "premium_subscription_month_count": 0, "unclaimed_prize_count": 0, "only_new_members": false, "was_refunded": false, "prize_description": "", "prize_star_count": 0}, "invoice": {"title": "Test", "description": "Desc", "start_parameter": "sp", "currency": "USD", "total_amount": 100, "invoice_payload": "payload", "shipping_option_id": "opt", "order_info": {"user_name": "User", "user_phone": "+123", "shipping_address": {"country_code": "US", "state": "CA", "city": "SJ", "street_line1": "123", "street_line2": "", "post_code": "95113"}}, "telegram_payment_charge_id": "chg1", "provider_payment_charge_id": "chg2"}, "location": {"latitude": 50.45, "longitude": 30.52}, "poll": {"id": "p1", "question": "test question", "options": [{"text": "Opt1", "persistent_id": "opt1"}], "type": "quiz"}, "venue": {"location": {"latitude": 50.45, "longitude": 30.52}, "title": "Place", "address": "Addr"}, "paid_media": {"star_count": 10, "paid_media": [{"type": "photo", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}]}, "live_photo": {"file_id": "lp1", "file_unique_id": "lp1u", "width": 100, "height": 100, "duration": 5}, "checklist": {"title": "Check", "tasks": [{"id": "t1", "text": "Task1", "status": "pending"}]}}' - result = types.ExternalReplyInfo.de_json(json_str) - assert isinstance(result.origin, types.MessageOrigin) - assert isinstance(result.chat, types.Chat) - assert result.message_id == 42 - assert isinstance(result.link_preview_options, types.LinkPreviewOptions) - assert isinstance(result.animation, types.Animation) - assert isinstance(result.audio, types.Audio) - assert isinstance(result.document, types.Document) - assert isinstance(result.photo, list) - assert isinstance(result.sticker, types.Sticker) - assert isinstance(result.story, types.Story) - assert isinstance(result.video, types.Video) - assert isinstance(result.video_note, types.VideoNote) - assert isinstance(result.voice, types.Voice) - assert result.has_media_spoiler == True - assert isinstance(result.contact, types.Contact) - assert isinstance(result.dice, types.Dice) - assert isinstance(result.game, types.Game) - assert isinstance(result.giveaway, types.Giveaway) - assert isinstance(result.giveaway.chats, list) - assert result.giveaway.winner_count == 1 - assert isinstance(result.giveaway_winners, types.GiveawayWinners) - assert isinstance(result.invoice, types.Invoice) - assert isinstance(result.location, types.Location) - assert isinstance(result.poll, types.Poll) - assert result.poll.id == 'p1' - assert result.poll.question == 'test question' - assert isinstance(result.poll.options, list) - assert result.poll.type == 'quiz' - assert isinstance(result.venue, types.Venue) - assert isinstance(result.paid_media, types.PaidMediaInfo) - assert isinstance(result.live_photo, types.LivePhoto) - assert isinstance(result.checklist, types.Checklist) - assert isinstance(result, types.ExternalReplyInfo) - - -def test_json_file(): - json_str = r'{"file_id": "test_file_id", "file_unique_id": "test_unique_id", "file_size": 1024, "file_path": "docs/test.pdf"}' - result = types.File.de_json(json_str) - assert result.file_id == 'test_file_id' - assert result.file_unique_id == 'test_unique_id' - assert result.file_size == 1024 - assert result.file_path == 'docs/test.pdf' - assert isinstance(result, types.File) - - -def test_json_forumtopiccreated(): - json_str = r'{"name": "test", "icon_color": 4294967295, "icon_custom_emoji_id": "custom_emoji", "is_name_implicit": true}' - result = types.ForumTopicCreated.de_json(json_str) - assert result.name == 'test' - assert result.icon_color == 4294967295 - assert result.icon_custom_emoji_id == 'custom_emoji' - assert result.is_name_implicit == True - assert isinstance(result, types.ForumTopicCreated) - - -def test_json_game(): - json_str = r'{"id": "1", "title": "test", "description": "test", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}], "text": "game text", "animation": {"file_id": "anim", "file_unique_id": "aniu", "width": 100, "height": 100, "duration": 10}, "text_entities": [{"type": "bold", "offset": 0, "length": 4}]}' - result = types.Game.de_json(json_str) - assert result.title == 'test' - assert result.description == 'test' - assert isinstance(result.photo, list) - assert result.text == 'game text' - assert isinstance(result.text_entities, list) - assert isinstance(result.animation, types.Animation) - assert isinstance(result, types.Game) - - -def test_json_gamehighscore(): - json_str = r'{"position": 0, "user": {"id": 1, "is_bot": false, "first_name": "Test"}, "score": 1}' - result = types.GameHighScore.de_json(json_str) - assert result.position == 0 - assert isinstance(result.user, types.User) - assert result.score == 1 - assert isinstance(result, types.GameHighScore) - - -def test_json_giveaway(): - json_str = r'{"chats": [{"id": 1, "type": "private", "title": "Test"}], "winners_selection_date": 1682189507, "winner_count": 1, "only_new_members": true, "has_public_winners": false, "prize_description": "Prize", "country_codes": ["US", "GB"], "premium_subscription_month_count": 3, "prize_star_count": 100}' - result = types.Giveaway.de_json(json_str) - assert isinstance(result.chats, list) - assert result.winners_selection_date == 1682189507 - assert result.winner_count == 1 - assert result.only_new_members == True - assert result.has_public_winners == False - assert result.prize_description == 'Prize' - assert isinstance(result.country_codes, list) - assert result.premium_subscription_month_count == 3 - assert result.prize_star_count == 100 - assert isinstance(result, types.Giveaway) - - -def test_json_giveawaycompleted(): - json_str = r'{"winner_count": 1, "unclaimed_prize_count": 5, "giveaway_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "giveaway"}, "is_star_giveaway": true}' - result = types.GiveawayCompleted.de_json(json_str) - assert result.winner_count == 1 - assert result.unclaimed_prize_count == 5 - assert isinstance(result.giveaway_message, types.Message) - assert result.is_star_giveaway == True - assert isinstance(result, types.GiveawayCompleted) - - -def test_json_giveawaywinners(): - json_str = r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "giveaway_message_id": 1, "winners_selection_date": 1682189507, "winner_count": 1, "winners": [{"id": 1, "is_bot": false, "first_name": "Test"}], "additional_chat_count": 5, "premium_subscription_month_count": 3, "unclaimed_prize_count": 10, "only_new_members": true, "was_refunded": false, "prize_description": "Prize desc", "prize_star_count": 100}' - result = types.GiveawayWinners.de_json(json_str) - assert isinstance(result.chat, types.Chat) - assert result.giveaway_message_id == 1 - assert result.winners_selection_date == 1682189507 - assert result.winner_count == 1 - assert isinstance(result.winners, list) - assert result.additional_chat_count == 5 - assert result.premium_subscription_month_count == 3 - assert result.unclaimed_prize_count == 10 - assert result.only_new_members == True - assert result.was_refunded == False - assert result.prize_description == 'Prize desc' - assert result.prize_star_count == 100 - assert isinstance(result, types.GiveawayWinners) - - -def test_json_groupchat(): - json_str = r'{"id": 1, "title": "test"}' - result = types.GroupChat.de_json(json_str) - assert result.id == 1 - assert result.title == 'test' - assert isinstance(result, types.GroupChat) - - -def test_json_inaccessiblemessage(): - json_str = r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "message_id": 1, "date": 1682189507}' - result = types.InaccessibleMessage.de_json(json_str) - assert isinstance(result.chat, types.Chat) - assert result.message_id == 1 - assert result.date == 1682189507 - assert isinstance(result, types.InaccessibleMessage) - - -def test_json_inlinequery(): - json_str = r'{"id": "iq1", "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "query": "test", "offset": "off1", "chat_type": "private", "location": {"latitude": 50.45, "longitude": 30.52, "horizontal_accuracy": 1.5, "live_period": 3600}}' - result = types.InlineQuery.de_json(json_str) - assert result.id == 'iq1' - assert isinstance(result.from_user, types.User) - assert result.query == 'test' - assert result.offset == 'off1' - assert result.chat_type == 'private' - assert isinstance(result.location, types.Location) - assert isinstance(result, types.InlineQuery) - - -def test_json_invoice(): - json_str = r'{"title": "test", "description": "test", "start_parameter": "test_sp", "currency": "test", "total_amount": 1}' - result = types.Invoice.de_json(json_str) - assert result.title == 'test' - assert result.description == 'test' - assert result.start_parameter == 'test_sp' - assert result.currency == 'test' - assert result.total_amount == 1 - assert isinstance(result, types.Invoice) - - -def test_json_jsondeserializable(): - # JsonDeserializable is abstract base class, skip - pass - - -def test_json_link(): - json_str = r'{"url": "https://example.com"}' - result = types.Link.de_json(json_str) - assert result.url == 'https://example.com' - assert isinstance(result, types.Link) - - -def test_json_livephoto(): - json_str = r'{"file_id": "test_file_id", "file_unique_id": "test_unique_id", "width": 100, "height": 100, "duration": 30, "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}], "mime_type": "image/jpeg", "file_size": 20480}' - result = types.LivePhoto.de_json(json_str) - assert result.file_id == 'test_file_id' - assert result.file_unique_id == 'test_unique_id' - assert result.width == 100 - assert result.height == 100 - assert result.duration == 30 - assert isinstance(result.photo, list) - assert result.mime_type == 'image/jpeg' - assert result.file_size == 20480 - assert isinstance(result, types.LivePhoto) - - -def test_json_managedbotcreated(): - json_str = r'{"bot": {"id": 1, "is_bot": true, "first_name": "Bot"}}' - result = types.ManagedBotCreated.de_json(json_str) - assert isinstance(result, types.ManagedBotCreated) - assert hasattr(result, 'bot') - - -def test_json_managedbotupdated(): - json_str = r'{"user": {"id": 1, "is_bot": false, "first_name": "Test"}, "bot": {"id": 2, "is_bot": true, "first_name": "Bot"}}' - result = types.ManagedBotUpdated.de_json(json_str) - assert isinstance(result.user, types.User) - assert result.user.id == 1 - assert isinstance(result.bot, types.User) - assert result.bot.id == 2 - assert isinstance(result, types.ManagedBotUpdated) - - -def test_json_menubutton(): - # MenuButton dispatches on type - test concrete subclass - json_str = r'{"type": "default"}' - result = types.MenuButtonDefault.de_json(json_str) - assert isinstance(result, types.MenuButtonDefault) - - -def test_json_messageautodeletetimerchanged(): - json_str = r'{"message_auto_delete_time": 60}' - result = types.MessageAutoDeleteTimerChanged.de_json(json_str) - assert result.message_auto_delete_time == 60 - assert isinstance(result, types.MessageAutoDeleteTimerChanged) - - -def test_json_messageid(): - json_str = r'{"message_id": 1}' - result = types.MessageID.de_json(json_str) - assert isinstance(result, types.MessageID) - - -def test_json_messageorigin(): - # MessageOrigin is abstract - test MessageOriginUser directly - json_str = r'{"type": "user", "date": 1682189507, "sender_user": {"id": 1, "is_bot": false, "first_name": "Test"}}' - result = types.MessageOriginUser.de_json(json_str) - assert result.type == 'user' - assert result.date == 1682189507 - assert isinstance(result.sender_user, types.User) - assert result.sender_user.id == 1 - assert result.sender_user.first_name == 'Test' - assert isinstance(result, types.MessageOriginUser) - - -def test_json_messagereactioncountupdated(): - json_str = r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "message_id": 1, "date": 1682189507, "reactions": [{"type": {"type": "emoji", "emoji": "\u2764\ufe0f"}, "total_count": 5}]}' - result = types.MessageReactionCountUpdated.de_json(json_str) - assert isinstance(result.chat, types.Chat) - assert result.message_id == 1 - assert result.date == 1682189507 - assert isinstance(result.reactions, list) - assert isinstance(result, types.MessageReactionCountUpdated) - - -def test_json_messagereactionupdated(): - json_str = r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "message_id": 1, "date": 1682189507, "old_reaction": [{"type": "emoji", "emoji": "\u0001f600"}], "new_reaction": [{"type": "emoji", "emoji": "\u0001f600"}], "user": {"id": 1, "is_bot": false, "first_name": "Test"}, "actor_chat": {"id": -1, "type": "channel", "title": "Channel"}}' - result = types.MessageReactionUpdated.de_json(json_str) - assert isinstance(result.chat, types.Chat) - assert result.message_id == 1 - assert result.date == 1682189507 - assert isinstance(result.old_reaction, list) - assert isinstance(result.new_reaction, list) - assert isinstance(result.user, types.User) - assert isinstance(result.actor_chat, types.Chat) - assert isinstance(result, types.MessageReactionUpdated) - - -def test_json_ownedgift(): - # OwnedGift is abstract - test OwnedGiftRegular directly - json_str = r'{"type": "regular", "gift": {"id": 1, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100}}' - result = types.OwnedGiftRegular.de_json(json_str) - assert result.type == 'regular' - assert isinstance(result, types.OwnedGiftRegular) - - -def test_json_ownedgiftregular(): - json_str = r'{"type": "regular", "gift": {"id": 1, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100}, "owned_gift_id": "og_123", "sender_user": {"id": 1, "is_bot": false, "first_name": "Sender"}, "send_date": 1682189507, "text": {"type": "bold", "text": "Gift text"}, "entities": [{"type": "bold", "offset": 0, "length": 4}], "is_private": false, "is_saved": false, "can_be_upgraded": true, "was_refunded": false, "convert_star_count": 50, "prepaid_upgrade_star_count": 100, "is_upgrade_separate": false, "unique_gift_number": 42}' - result = types.OwnedGiftRegular.de_json(json_str) - assert result.type == 'regular' - assert isinstance(result.gift, types.Gift) - assert result.owned_gift_id == 'og_123' - assert isinstance(result.sender_user, types.User) - assert result.send_date == 1682189507 - assert isinstance(result.text, dict) - assert isinstance(result.entities, list) - assert result.is_private == False - assert result.is_saved == False - assert result.can_be_upgraded == True - assert result.was_refunded == False - assert result.convert_star_count == 50 - assert result.prepaid_upgrade_star_count == 100 - assert result.is_upgrade_separate == False - assert result.unique_gift_number == 42 - assert isinstance(result, types.OwnedGiftRegular) - - -def test_json_ownedgiftunique(): - json_str = r'{"type": "unique", "gift": {"base_name": "test", "name": "test", "number": 1, "model": {"name": "m", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "symbol": {"name": "s", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "backdrop": {"name": "b", "colors": {"center_color": 123456, "edge_color": 654321, "symbol_color": 111111, "text_color": 222222}, "rarity_per_mille": 1000}, "gift_id": 1}, "gift_id": 1, "owned_gift_id": "og_456", "sender_user": {"id": 2, "is_bot": false, "first_name": "Sender"}, "send_date": 1682189507, "is_saved": false, "can_be_transferred": true, "transfer_star_count": 50, "next_transfer_date": 1704067200}' - result = types.OwnedGiftUnique.de_json(json_str) - assert result.type == 'unique' - assert isinstance(result.gift, types.UniqueGift) - assert result.owned_gift_id == 'og_456' - assert isinstance(result.sender_user, types.User) - assert result.send_date == 1682189507 - assert result.is_saved == False - assert result.can_be_transferred == True - assert result.transfer_star_count == 50 - assert result.next_transfer_date == 1704067200 - assert isinstance(result, types.OwnedGiftUnique) - - -def test_json_ownedgifts(): - json_str = r'{"total_count": 1, "gifts": [{"type": "regular", "gift": {"id": 1, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100}}], "next_offset": "offset123"}' - result = types.OwnedGifts.de_json(json_str) - assert result.total_count == 1 - assert isinstance(result.gifts, list) - assert result.next_offset == 'offset123' - assert isinstance(result, types.OwnedGifts) - - -def test_json_paidmedia(): - # PaidMedia is abstract - test PaidMediaPhoto directly - json_str = r'{"type": "photo", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}' - result = types.PaidMediaPhoto.de_json(json_str) - assert isinstance(result, types.PaidMediaPhoto) - - -def test_json_paidmediainfo(): - json_str = r'{"star_count": 100, "paid_media": [{"type": "photo", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}]}' - result = types.PaidMediaInfo.de_json(json_str) - assert result.star_count == 100 - assert isinstance(result.paid_media, list) - assert isinstance(result, types.PaidMediaInfo) - - -def test_json_paidmedialivephoto(): - json_str = r'{"type": "live_photo", "live_photo": {"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100, "duration": 10}}' - result = types.PaidMediaLivePhoto.de_json(json_str) - assert result.type == 'live_photo' - assert isinstance(result.live_photo, types.LivePhoto) - assert isinstance(result, types.PaidMediaLivePhoto) - - -def test_json_paidmediaphoto(): - json_str = r'{"type": "photo", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}' - result = types.PaidMediaPhoto.de_json(json_str) - assert result.type == 'photo' - assert isinstance(result.photo, list) - assert isinstance(result, types.PaidMediaPhoto) - - -def test_json_paidmediapreview(): - json_str = r'{"type": "default", "width": 640, "height": 480, "duration": 30}' - result = types.PaidMediaPreview.de_json(json_str) - assert result.type == 'default' - assert result.width == 640 - assert result.height == 480 - assert result.duration == 30 - assert isinstance(result, types.PaidMediaPreview) - - -def test_json_paidmediapurchased(): - json_str = r'{"from_user": {"id": 1, "is_bot": false, "first_name": "Test"}, "paid_media_payload": "test"}' - result = types.PaidMediaPurchased.de_json(json_str) - assert isinstance(result.from_user, types.User) - assert result.paid_media_payload == 'test' - assert isinstance(result, types.PaidMediaPurchased) - - -def test_json_paidmediavideo(): - json_str = r'{"type": "video", "video": {"file_id": "v", "file_unique_id": "vu", "width": 640, "height": 480, "duration": 30}}' - result = types.PaidMediaVideo.de_json(json_str) - assert result.type == 'video' - assert isinstance(result.video, types.Video) - assert isinstance(result, types.PaidMediaVideo) - - -def test_json_paidmessagepricechanged(): - json_str = r'{"paid_message_star_count": 1}' - result = types.PaidMessagePriceChanged.de_json(json_str) - assert isinstance(result, types.PaidMessagePriceChanged) - assert hasattr(result, 'paid_message_star_count') - - -def test_json_poll(): - # Poll.poll_type is deprecated in Telegram API, not covered - json_str = r'{"id": "poll1", "question": "test question", "options": [{"text": "Opt1", "persistent_id": "opt1"}], "total_voter_count": 10, "is_closed": false, "is_anonymous": true, "type": "quiz", "allows_multiple_answers": false, "explanation": "explanation text", "explanation_entities": [{"type": "bold", "offset": 0, "length": 4}], "open_period": 3600, "close_date": 1682193107, "question_entities": [{"type": "bold", "offset": 0, "length": 5}], "correct_option_ids": [0], "allows_revoting": true, "description": "poll desc", "description_entities": [{"type": "italic", "offset": 0, "length": 9}], "members_only": true, "country_codes": ["US", "GB"], "explanation_media": {"file_id": "em1", "file_unique_id": "emu1", "mime_type": "image/jpeg", "file_name": "media.jpg"}}' - result = types.Poll.de_json(json_str) - # __init__ param is "poll_id" but de_json sets "id" attribute (from JSON "id" key) - # Use Poll.id, NOT Poll.poll_id - assert result.id == "poll1" - assert result.question == "test question" - assert isinstance(result.options, list) - assert result.total_voter_count == 10 - assert result.is_closed == False - assert result.is_anonymous == True - assert result.type == "quiz" - assert result.allows_multiple_answers == False - assert result.explanation == "explanation text" - assert isinstance(result.explanation_entities, list) - assert result.open_period == 3600 - assert result.close_date == 1682193107 - assert isinstance(result.question_entities, list) - assert isinstance(result.correct_option_ids, list) - assert result.allows_revoting == True - assert result.description == "poll desc" - assert isinstance(result.description_entities, list) - assert result.media is None - assert result.members_only == True - assert isinstance(result.country_codes, list) - assert isinstance(result.explanation_media, types.PollMedia) - assert isinstance(result, types.Poll) - - -def test_json_polloption(): - json_str = r'{"text": "test", "persistent_id": 1, "voter_count": 5, "text_entities": [{"type": "bold", "offset": 0, "length": 4}], "added_by_user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "added_by_chat": {"id": -1, "type": "channel", "title": "Channel"}, "addition_date": 1682189507}' - result = types.PollOption.de_json(json_str) - assert result.text == 'test' - assert result.persistent_id == 1 - assert result.voter_count == 5 - assert isinstance(result.text_entities, list) - assert isinstance(result.added_by_user, types.User) - assert result.added_by_user.id == 12345 - assert isinstance(result.added_by_chat, types.Chat) - assert result.addition_date == 1682189507 - assert result.media is None - assert isinstance(result, types.PollOption) - - -def test_json_polloptionadded(): - json_str = r'{"option_persistent_id": 1, "option_text": "test", "poll_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "poll"}, "option_text_entities": [{"type": "bold", "offset": 0, "length": 4}]}' - result = types.PollOptionAdded.de_json(json_str) - assert result.option_persistent_id == 1 - assert result.option_text == 'test' - assert isinstance(result.poll_message, types.Message) - assert isinstance(result.option_text_entities, list) - assert isinstance(result, types.PollOptionAdded) - - -def test_json_polloptiondeleted(): - json_str = r'{"option_persistent_id": 1, "option_text": "test", "poll_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "poll"}, "option_text_entities": [{"type": "bold", "offset": 0, "length": 4}]}' - result = types.PollOptionDeleted.de_json(json_str) - assert result.option_persistent_id == 1 - assert result.option_text == 'test' - assert isinstance(result.poll_message, types.Message) - assert isinstance(result.option_text_entities, list) - assert isinstance(result, types.PollOptionDeleted) - - -def test_json_precheckoutquery(): - json_str = r'{"id": 1, "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "currency": "USD", "total_amount": 1234, "invoice_payload": "test_payload", "shipping_option_id": "opt1", "order_info": {"user_name": "Buyer", "user_phone": "+123", "shipping_address": {"country_code": "US", "state": "CA", "city": "San Jose", "street_line1": "123 Main St", "street_line2": "", "post_code": "95113"}}}' - result = types.PreCheckoutQuery.de_json(json_str) - assert result.id == 1 - assert isinstance(result.from_user, types.User) - assert result.currency == 'USD' - assert result.total_amount == 1234 - assert result.invoice_payload == 'test_payload' - assert result.shipping_option_id == 'opt1' - assert isinstance(result.order_info, types.OrderInfo) - assert isinstance(result, types.PreCheckoutQuery) - - -def test_json_preparedinlinemessage(): - json_str = r'{"id": "prep1", "expiration_date": 1682189507}' - result = types.PreparedInlineMessage.de_json(json_str) - assert result.id == 'prep1' - assert result.expiration_date == 1682189507 - assert isinstance(result, types.PreparedInlineMessage) - - -def test_json_preparedkeyboardbutton(): - json_str = r'{"id": 1}' - result = types.PreparedKeyboardButton.de_json(json_str) - assert result.id == 1 - assert isinstance(result, types.PreparedKeyboardButton) - - -def test_json_proximityalerttriggered(): - json_str = r'{"traveler": {"id": 1, "is_bot": false, "first_name": "Test"}, "watcher": {"id": 1, "is_bot": false, "first_name": "Test"}, "distance": "test"}' - result = types.ProximityAlertTriggered.de_json(json_str) - assert isinstance(result.traveler, dict) - assert isinstance(result.watcher, dict) - assert result.distance == 'test' - assert isinstance(result, types.ProximityAlertTriggered) - - -def test_json_refundedpayment(): - json_str = r'{"currency": "USD", "total_amount": 100, "invoice_payload": "test_payload", "telegram_payment_charge_id": "chg1", "provider_payment_charge_id": "chg2"}' - result = types.RefundedPayment.de_json(json_str) - assert result.currency == 'USD' - assert result.total_amount == 100 - assert result.invoice_payload == 'test_payload' - assert result.telegram_payment_charge_id == 'chg1' - assert result.provider_payment_charge_id == 'chg2' - assert isinstance(result, types.RefundedPayment) - - -def test_json_revenuewithdrawalstate(): - # RevenueWithdrawalState is abstract - test RevenueWithdrawalStatePending directly - json_str = r'{"type": "pending"}' - result = types.RevenueWithdrawalStatePending.de_json(json_str) - assert isinstance(result, types.RevenueWithdrawalStatePending) - - -def test_json_revenuewithdrawalstatefailed(): - json_str = r'{"type": "failed"}' - result = types.RevenueWithdrawalStateFailed.de_json(json_str) - assert result.type == 'failed' - assert isinstance(result, types.RevenueWithdrawalStateFailed) - - -def test_json_revenuewithdrawalstatepending(): - json_str = r'{"type": "pending"}' - result = types.RevenueWithdrawalStatePending.de_json(json_str) - assert result.type == 'pending' - assert isinstance(result, types.RevenueWithdrawalStatePending) - - -def test_json_revenuewithdrawalstatesucceeded(): - json_str = r'{"type": "succeeded", "date": 1682189507, "url": "https://example.com"}' - result = types.RevenueWithdrawalStateSucceeded.de_json(json_str) - assert result.type == 'succeeded' - assert result.date == 1682189507 - assert result.url == 'https://example.com' - assert isinstance(result, types.RevenueWithdrawalStateSucceeded) - - -def test_json_richblockanchor(): - json_str = r'{"type": "anchor", "name": "test"}' - result = types.RichBlock.de_json(json_str) - assert result.name == 'test' - assert isinstance(result, types.RichBlockAnchor) - - -def test_json_richblockaudio(): - json_str = r'{"type": "audio", "audio": {"file_id": "a", "file_unique_id": "au", "duration": 30}, "caption": {"type": "bold", "text": "audio caption"}}' - result = types.RichBlock.de_json(json_str) - assert isinstance(result.audio, types.Audio) - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockAudio) - - -def test_json_richblockblockquotation(): - json_str = r'{"type": "blockquote", "blocks": [{"text": "Test"}], "credit": "Credit text"}' - result = types.RichBlock.de_json(json_str) - assert isinstance(result.blocks, list) - assert result.credit == 'Credit text' - assert isinstance(result, types.RichBlockBlockQuotation) - - -def test_json_richblockcollage(): - json_str = r'{"type": "collage", "blocks": [{"text": "Test"}], "caption": {"type": "bold", "text": "Caption"}}' - result = types.RichBlock.de_json(json_str) - assert isinstance(result.blocks, list) - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockCollage) - - -def test_json_richblocklist(): - json_str = r'{"type": "list", "items": [{"type": "list_item", "label": {"text": "label"}, "blocks": [{"text": "Test"}]}]}' - result = types.RichBlock.de_json(json_str) - assert isinstance(result.items, list) - assert isinstance(result, types.RichBlockList) - assert hasattr(result, 'items') - - -def test_json_richblockmap(): - json_str = r'{"type": "map", "location": {"latitude": 50.0, "longitude": 30.0}, "zoom": 1.0, "width": 100, "height": 100, "caption": {"type": "bold", "text": "Map caption"}}' - result = types.RichBlock.de_json(json_str) - assert isinstance(result.location, types.Location) - assert result.zoom == 1.0 - assert result.width == 100 - assert result.height == 100 - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockMap) - - -def test_json_richblockmathematicalexpression(): - json_str = r'{"type": "mathematical_expression", "expression": "test"}' - result = types.RichBlock.de_json(json_str) - assert result.expression == 'test' - assert isinstance(result, types.RichBlockMathematicalExpression) - - -def test_json_richblockphoto(): - json_str = r'{"type": "photo", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}], "has_spoiler": true, "caption": {"type": "bold", "text": "Photo caption"}}' - result = types.RichBlock.de_json(json_str) - assert isinstance(result.photo, list) - assert result.has_spoiler == True - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockPhoto) - - -def test_json_richblockpullquotation(): - json_str = r'{"type": "pullquote", "text": "test quote", "credit": "Author Name"}' - result = types.RichBlock.de_json(json_str) - assert result.text == 'test quote' - assert result.credit == 'Author Name' - assert isinstance(result, types.RichBlockPullQuotation) - - -def test_json_richblocksectionheading(): - json_str = r'{"type": "heading", "text": "test", "size": "test"}' - result = types.RichBlock.de_json(json_str) - assert result.text == 'test' - assert result.size == 'test' - assert isinstance(result, types.RichBlockSectionHeading) - - -def test_json_richblockslideshow(): - json_str = r'{"type": "slideshow", "blocks": [{"text": "Test"}], "caption": {"type": "bold", "text": "slide caption"}}' - result = types.RichBlock.de_json(json_str) - assert isinstance(result.blocks, list) - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockSlideshow) - assert hasattr(result, 'caption') - assert hasattr(result, 'blocks') - - -def test_json_richblocktable(): - json_str = r'{"type": "table", "cells": [[{"align": "left", "valign": "top", "text": "cell", "is_header": false, "colspan": 1, "rowspan": 1}]], "is_bordered": true, "is_striped": true, "caption": {"type": "bold", "text": "table caption"}}' - result = types.RichBlock.de_json(json_str) - assert isinstance(result.cells, list) - assert result.is_bordered == True - assert result.is_striped == True - assert isinstance(result.caption, types.RichText) - assert isinstance(result, types.RichBlockTable) - assert hasattr(result, 'is_striped') - assert hasattr(result, 'is_bordered') - assert hasattr(result, 'cells') - - -def test_json_richblockthinking(): - json_str = r'{"type": "thinking", "text": "test"}' - result = types.RichBlock.de_json(json_str) - assert result.text == 'test' - assert isinstance(result, types.RichBlockThinking) - - -def test_json_richblockvideo(): - json_str = r'{"type": "video", "video": {"file_id": "v", "file_unique_id": "vu", "width": 640, "height": 480, "duration": 30}, "has_spoiler": true, "caption": {"type": "bold", "text": "video caption"}}' - result = types.RichBlock.de_json(json_str) - assert isinstance(result.video, types.Video) - assert result.has_spoiler == True - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockVideo) - assert hasattr(result, 'has_spoiler') - - -def test_json_richmessage(): - json_str = r'{"blocks": [{"type": "text", "text": "Test"}], "is_rtl": true}' - result = types.RichMessage.de_json(json_str) - assert isinstance(result.blocks, list) - assert result.is_rtl == True - assert isinstance(result, types.RichMessage) - - -def test_json_sentguestmessage(): - json_str = r'{"inline_message_id": 1}' - result = types.SentGuestMessage.de_json(json_str) - assert result.inline_message_id == 1 - assert isinstance(result, types.SentGuestMessage) - - -def test_json_shippingaddress(): - json_str = r'{"country_code": "US", "state": "CA", "city": "San Jose", "street_line1": "123 Main St", "street_line2": "Apt 4", "post_code": "95113"}' - result = types.ShippingAddress.de_json(json_str) - assert result.country_code == 'US' - assert result.state == 'CA' - assert result.city == 'San Jose' - assert result.street_line1 == '123 Main St' - assert result.street_line2 == 'Apt 4' - assert result.post_code == '95113' - assert isinstance(result, types.ShippingAddress) - - -def test_json_shippingquery(): - json_str = r'{"id": "1", "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "invoice_payload": "test_payload", "shipping_address": {"country_code": "US", "state": "CA", "city": "Test", "street_line1": "Test St", "street_line2": "", "post_code": "12345"}}' - result = types.ShippingQuery.de_json(json_str) - assert result.id == '1' - assert isinstance(result.from_user, types.User) - assert result.invoice_payload == 'test_payload' - assert result.shipping_address.country_code == 'US' - assert result.shipping_address.state == 'CA' - assert result.shipping_address.city == 'Test' - assert result.shipping_address.street_line1 == 'Test St' - assert result.shipping_address.street_line2 == '' - assert result.shipping_address.post_code == '12345' - assert isinstance(result, types.ShippingQuery) - - -def test_json_staramount(): - json_str = r'{"amount": "100", "nanostar_amount": 1000000000}' - result = types.StarAmount.de_json(json_str) - assert result.amount == '100' - assert result.nanostar_amount == 1000000000 - assert isinstance(result, types.StarAmount) - - -def test_json_startransaction(): - json_str = r'{"id": 1, "amount": 100, "date": 1682189507, "source": {"type": "fragment"}, "receiver": {"type": "telegram_ads"}, "nanostar_amount": 10000000}' - result = types.StarTransaction.de_json(json_str) - assert result.id == 1 - assert result.amount == 100 - assert result.date == 1682189507 - assert isinstance(result.source, types.TransactionPartnerFragment) - assert isinstance(result.receiver, dict) - assert result.receiver['type'] == 'telegram_ads' - assert result.nanostar_amount == 10000000 - assert isinstance(result, types.StarTransaction) - - -def test_json_startransactions(): - json_str = r'{"transactions": [{"id": "tx1", "amount": 100, "date": 1682189507}]}' - result = types.StarTransactions.de_json(json_str) - assert isinstance(result, types.StarTransactions) - assert hasattr(result, 'transactions') - - -def test_json_story(): - json_str = r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "id": 1}' - result = types.Story.de_json(json_str) - assert isinstance(result.chat, types.Chat) - assert result.id == 1 - assert isinstance(result, types.Story) - - -def test_json_successfulpayment(): - json_str = r'{"currency": "USD", "total_amount": 1234, "invoice_payload": "test_payload", "shipping_option_id": "opt1", "order_info": {"user_name": "Buyer", "user_phone": "+123", "shipping_address": {"country_code": "US", "state": "CA", "city": "San Jose", "street_line1": "123 Main St", "street_line2": "", "post_code": "95113"}}, "telegram_payment_charge_id": "chg1", "provider_payment_charge_id": "chg2", "subscription_expiration_date": 1704067200, "is_recurring": true, "is_first_recurring": true}' - result = types.SuccessfulPayment.de_json(json_str) - assert result.currency == 'USD' - assert result.total_amount == 1234 - assert result.invoice_payload == 'test_payload' - assert result.shipping_option_id == 'opt1' - assert isinstance(result.order_info, types.OrderInfo) - assert result.telegram_payment_charge_id == 'chg1' - assert result.provider_payment_charge_id == 'chg2' - assert result.subscription_expiration_date == 1704067200 - assert result.is_recurring == True - assert result.is_first_recurring == True - assert isinstance(result, types.SuccessfulPayment) - - -def test_json_suggestedpostapprovalfailed(): - json_str = r'{"price": {"currency": "USD", "amount": 100}, "suggested_post_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "suggested"}}' - result = types.SuggestedPostApprovalFailed.de_json(json_str) - assert isinstance(result.price, types.SuggestedPostPrice) - assert isinstance(result.suggested_post_message, types.Message) - assert result.suggested_post_message.message_id == 1 - assert isinstance(result, types.SuggestedPostApprovalFailed) - - -def test_json_suggestedpostapproved(): - json_str = r'{"send_date": 1682189507, "suggested_post_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "suggested"}, "price": {"amount": "100", "currency": "XTR"}}' - result = types.SuggestedPostApproved.de_json(json_str) - assert result.send_date == 1682189507 - assert isinstance(result.suggested_post_message, types.Message) - assert isinstance(result.price, types.SuggestedPostPrice) - assert isinstance(result, types.SuggestedPostApproved) - - -def test_json_suggestedpostinfo(): - json_str = r'{"state": "default", "price": {"amount": "100", "currency": "XTR"}, "send_date": 1682189507}' - result = types.SuggestedPostInfo.de_json(json_str) - assert result.state == 'default' - assert isinstance(result.price, types.SuggestedPostPrice) - assert result.send_date == 1682189507 - assert isinstance(result, types.SuggestedPostInfo) - - -def test_json_suggestedpostpaid(): - json_str = r'{"currency": "test", "suggested_post_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "suggested"}, "amount": 100, "star_amount": {"amount": 50}}' - result = types.SuggestedPostPaid.de_json(json_str) - assert result.currency == 'test' - assert isinstance(result.suggested_post_message, types.Message) - assert result.amount == 100 - assert isinstance(result.star_amount, types.StarAmount) - assert result.star_amount.amount == 50 - assert isinstance(result, types.SuggestedPostPaid) - - -def test_json_suggestedpostrefunded(): - json_str = r'{"reason": "test", "suggested_post_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "suggested"}}' - result = types.SuggestedPostRefunded.de_json(json_str) - assert result.reason == 'test' - assert isinstance(result.suggested_post_message, types.Message) - assert result.suggested_post_message.message_id == 1 - assert isinstance(result, types.SuggestedPostRefunded) - - -def test_json_textquote(): - json_str = r'{"text": "test", "position": 0, "entities": [{"type": "bold", "offset": 0, "length": 4}], "is_manual": true}' - result = types.TextQuote.de_json(json_str) - assert result.text == 'test' - assert result.position == 0 - assert isinstance(result.entities, list) - assert result.is_manual == True - assert isinstance(result, types.TextQuote) - - -def test_json_transactionpartner(): - # TransactionPartner is abstract - test TransactionPartnerUser directly - json_str = r'{"type": "user", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}' - result = types.TransactionPartnerUser.de_json(json_str) - assert isinstance(result, types.TransactionPartnerUser) - - -def test_json_transactionpartneraffiliateprogram(): - json_str = r'{"type": "affiliate_program", "commission_per_mille": 1000, "sponsor_user": {"id": 1, "is_bot": false, "first_name": "Sponsor"}}' - result = types.TransactionPartnerAffiliateProgram.de_json(json_str) - assert result.type == 'affiliate_program' - assert result.commission_per_mille == 1000 - assert isinstance(result.sponsor_user, types.User) - assert result.sponsor_user.id == 1 - assert isinstance(result, types.TransactionPartnerAffiliateProgram) - - -def test_json_transactionpartnerchat(): - json_str = r'{"type": "chat", "chat": {"id": 1, "type": "private", "title": "Test"}, "gift": {"id": 123456789, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100, "total_count": 5, "remaining_count": 3, "upgrade_star_count": 50, "personal_total_count": 10, "personal_remaining_count": 2, "is_premium": true, "has_colors": true, "publisher_chat": {"id": 1, "type": "channel", "title": "Publisher"}, "unique_gift_variant_count": 3}}' - result = types.TransactionPartnerChat.de_json(json_str) - assert result.type == 'chat' - assert isinstance(result.chat, types.Chat) - assert isinstance(result.gift, types.Gift) - assert result.gift.id == 123456789 - assert isinstance(result, types.TransactionPartnerChat) - - -def test_json_transactionpartnerfragment(): - json_str = r'{"type": "fragment", "withdrawal_state": {"type": "pending"}}' - result = types.TransactionPartnerFragment.de_json(json_str) - assert result.type == 'fragment' - assert isinstance(result.withdrawal_state, types.RevenueWithdrawalState) - assert isinstance(result, types.TransactionPartnerFragment) - - -def test_json_transactionpartnerother(): - json_str = r'{"type": "other"}' - result = types.TransactionPartnerOther.de_json(json_str) - assert result.type == 'other' - assert isinstance(result, types.TransactionPartnerOther) - - -def test_json_transactionpartnertelegramapi(): - json_str = r'{"type": "default", "request_count": 10}' - result = types.TransactionPartnerTelegramApi.de_json(json_str) - assert result.type == 'default' - assert result.request_count == 10 - assert isinstance(result, types.TransactionPartnerTelegramApi) - - -def test_json_transactionpartneruser(): - json_str = r'{"type": "default", "user": {"id": 1, "is_bot": false, "first_name": "Test"}, "affiliate": {"commission_per_mille": 5500, "amount": 100, "affiliate_user": {"id": 1, "is_bot": false, "first_name": "User"}, "affiliate_chat": {"id": 1, "type": "private"}, "nanostar_amount": 1000000}, "invoice_payload": "payload", "paid_media": [{"type": "photo", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}], "subscription_period": 30, "gift": {"id": 1, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100, "total_count": 1000, "remaining_count": 999, "upgrade_star_count": 50, "personal_total_count": 5, "personal_remaining_count": 3, "is_premium": true, "has_colors": false, "publisher_chat": {"id": 1, "type": "channel", "title": "Pub"}, "unique_gift_variant_count": 10}, "premium_subscription_duration": 12, "transaction_type": "purchase"}' - result = types.TransactionPartnerUser.de_json(json_str) - assert result.type == 'default' - assert isinstance(result.user, types.User) - assert isinstance(result.affiliate, types.AffiliateInfo) - assert result.invoice_payload == 'payload' - assert isinstance(result.paid_media, list) - assert result.subscription_period == 30 - assert isinstance(result.gift, types.Gift) - assert result.premium_subscription_duration == 12 - assert result.transaction_type == 'purchase' - assert isinstance(result, types.TransactionPartnerUser) - - -def test_json_uniquegift(): - json_str = r'{"base_name": "test", "name": "test", "number": 1, "model": {"name": "model_name", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "symbol": {"name": "symbol_name", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "backdrop": {"name": "backdrop_name", "colors": {"center_color": 123456, "edge_color": 654321, "symbol_color": 111111, "text_color": 222222}, "rarity_per_mille": 1000}, "gift_id": 1, "publisher_chat": {"id": -1001234567890, "type": "channel", "title": "Channel"}, "is_from_blockchain": true, "is_premium": false, "colors": {"model_custom_emoji_id": 1, "symbol_custom_emoji_id": 1, "light_theme_main_color": 333333, "light_theme_other_colors": [444444], "dark_theme_main_color": 555555, "dark_theme_other_colors": [666666]}, "is_burned": false}' - result = types.UniqueGift.de_json(json_str) - assert result.base_name == 'test' - assert result.name == 'test' - assert result.number == 1 - assert isinstance(result.model, types.UniqueGiftModel) - assert isinstance(result.symbol, types.UniqueGiftSymbol) - assert isinstance(result.backdrop, types.UniqueGiftBackdrop) - assert result.gift_id == 1 - assert isinstance(result.publisher_chat, types.Chat) - assert result.is_from_blockchain == True - assert result.is_premium == False - assert isinstance(result.colors, types.UniqueGiftColors) - assert result.is_burned == False - assert isinstance(result, types.UniqueGift) - - -def test_json_uniquegiftbackdrop(): - json_str = r'{"name": "test", "colors": {"center_color": 123456, "edge_color": 654321, "symbol_color": 111111, "text_color": 222222}, "rarity_per_mille": 1000}' - result = types.UniqueGiftBackdrop.de_json(json_str) - assert result.name == 'test' - assert isinstance(result.colors, types.UniqueGiftBackdropColors) - assert result.rarity_per_mille == 1000 - assert isinstance(result, types.UniqueGiftBackdrop) - - -def test_json_uniquegiftbackdropcolors(): - json_str = r'{"center_color": 123456, "edge_color": 654321, "symbol_color": 111111, "text_color": 222222}' - result = types.UniqueGiftBackdropColors.de_json(json_str) - assert result.center_color == 123456 - assert result.edge_color == 654321 - assert result.symbol_color == 111111 - assert result.text_color == 222222 - assert isinstance(result, types.UniqueGiftBackdropColors) - - -def test_json_uniquegiftcolors(): - json_str = r'{"model_custom_emoji_id": 1, "symbol_custom_emoji_id": 1, "light_theme_main_color": 333333, "light_theme_other_colors": [444444], "dark_theme_main_color": 555555, "dark_theme_other_colors": [666666]}' - result = types.UniqueGiftColors.de_json(json_str) - assert result.model_custom_emoji_id == 1 - assert result.symbol_custom_emoji_id == 1 - assert result.light_theme_main_color == 333333 - assert isinstance(result.light_theme_other_colors, list) - assert result.dark_theme_main_color == 555555 - assert isinstance(result.dark_theme_other_colors, list) - assert isinstance(result, types.UniqueGiftColors) - - -def test_json_uniquegiftinfo(): - json_str = r'{"gift": {"base_name": "b", "name": "n", "number": 1, "model": {"name": "m", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "symbol": {"name": "s", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "backdrop": {"name": "b", "colors": {"center_color": 123456, "edge_color": 654321, "symbol_color": 111111, "text_color": 222222}, "rarity_per_mille": 1000}, "gift_id": 1}, "origin": "test", "owned_gift_id": "og123", "transfer_star_count": 100, "next_transfer_date": 1682189507, "last_resale_currency": "USD", "last_resale_amount": 500}' - result = types.UniqueGiftInfo.de_json(json_str) - assert isinstance(result.gift, types.UniqueGift) - assert result.origin == 'test' - assert result.owned_gift_id == 'og123' - assert result.transfer_star_count == 100 - assert result.next_transfer_date == 1682189507 - assert result.last_resale_currency == 'USD' - assert result.last_resale_amount == 500 - assert isinstance(result, types.UniqueGiftInfo) - - -def test_json_uniquegiftmodel(): - json_str = r'{"name": "test", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000, "rarity": "common"}' - result = types.UniqueGiftModel.de_json(json_str) - assert result.name == 'test' - assert isinstance(result.sticker, types.Sticker) - assert result.rarity_per_mille == 1000 - assert result.rarity == 'common' - assert isinstance(result, types.UniqueGiftModel) - - -def test_json_uniquegiftsymbol(): - json_str = r'{"name": "test", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}' - result = types.UniqueGiftSymbol.de_json(json_str) - assert result.name == 'test' - assert isinstance(result.sticker, types.Sticker) - assert result.rarity_per_mille == 1000 - assert isinstance(result, types.UniqueGiftSymbol) - - -# NOTE: Update is an abstract/registry class that dispatches to specific -# update types (message_update, callback_query_update, etc.). Its __init__ -# only contains 'update_id' in practice; other 'update_type' fields are -# handled by subclasses. Full field coverage is intentionally not required. -def test_json_update(): - json_str = r'{"update_id": 1}' - result = types.Update.de_json(json_str) - assert result.update_id == 1 - assert isinstance(result, types.Update) - - -def test_json_userchatboosts(): - json_str = r'{"boosts": [{"boost_item_id": "b1", "add_date": 1682189507, "expiration_date": 1682275907}]}' - result = types.UserChatBoosts.de_json(json_str) - assert isinstance(result.boosts, list) - assert isinstance(result, types.UserChatBoosts) - assert hasattr(result, 'boosts') - - -def test_json_userprofileaudios(): - json_str = r'{"total_count": 1, "audios": [{"file_id": "a1", "file_unique_id": "au1", "duration": 180, "title": "Test", "performer": "Perf", "type": "song"}]}' - result = types.UserProfileAudios.de_json(json_str) - assert result.total_count == 1 - assert isinstance(result.audios, list) - assert isinstance(result, types.UserProfileAudios) - - -def test_json_userprofilephotos(): - json_str = r'{"total_count": 1, "photos": [[{"file_id": "p1", "file_unique_id": "pu1", "width": 100, "height": 100}]]}' - result = types.UserProfilePhotos.de_json(json_str) - assert result.total_count == 1 - assert isinstance(result.photos, list) - assert isinstance(result.photos[0], list) - assert isinstance(result.photos[0][0], types.PhotoSize) - assert isinstance(result, types.UserProfilePhotos) - - -def test_json_userrating(): - json_str = r'{"level": "test", "rating": "test", "current_level_rating": "test", "next_level_rating": "next_test"}' - result = types.UserRating.de_json(json_str) - assert result.level == 'test' - assert result.rating == 'test' - assert result.current_level_rating == 'test' - assert result.next_level_rating == 'next_test' - assert isinstance(result, types.UserRating) - - -def test_json_videochatended(): - json_str = r'{"duration": 30}' - result = types.VideoChatEnded.de_json(json_str) - assert result.duration == 30 - assert isinstance(result, types.VideoChatEnded) - - -def test_json_videochatscheduled(): - json_str = r'{"start_date": 1682189507}' - result = types.VideoChatScheduled.de_json(json_str) - assert result.start_date == 1682189507 - assert isinstance(result, types.VideoChatScheduled) - - -def test_json_videonote(): - json_str = r'{"file_id": "test_file_id", "file_unique_id": "test_unique_id", "length": 100, "duration": 30, "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 50, "height": 50}, "file_size": 1024}' - result = types.VideoNote.de_json(json_str) - assert result.file_id == 'test_file_id' - assert result.file_unique_id == 'test_unique_id' - assert result.length == 100 - assert result.duration == 30 - assert isinstance(result.thumbnail, types.PhotoSize) - assert result.file_size == 1024 - assert isinstance(result, types.VideoNote) - - -def test_json_videoquality(): - json_str = r'{"file_id": "test_file_id", "file_unique_id": "test_unique_id", "width": 100, "height": 100, "codec": "h264", "file_size": 1024}' - result = types.VideoQuality.de_json(json_str) - assert result.file_id == 'test_file_id' - assert result.file_unique_id == 'test_unique_id' - assert result.width == 100 - assert result.height == 100 - assert result.codec == 'h264' - assert result.file_size == 1024 - assert isinstance(result, types.VideoQuality) - - -def test_json_webhookinfo(): - json_str = r'{"url": "https://example.com", "has_custom_certificate": false, "pending_update_count": 1}' - result = types.WebhookInfo.de_json(json_str) - assert result.url == 'https://example.com' - assert result.has_custom_certificate == False - assert result.pending_update_count == 1 - assert isinstance(result, types.WebhookInfo) \ No newline at end of file diff --git a/tests/test_types.py b/tests/test_types.py index d4e325e71..ba6211af7 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -6,2674 +6,384 @@ def test_json_user(): - json_str = r'{"id": 123456789, "is_bot": false, "first_name": "John", "last_name": "Doe", "username": "@johndoe", "language_code": "en", "can_join_groups": true, "can_read_all_group_messages": false, "supports_inline_queries": true, "is_premium": true, "added_to_attachment_menu": false, "can_connect_to_business": true, "has_main_web_app": false, "has_topics_enabled": true, "allows_users_to_create_topics": true, "can_manage_bots": true, "supports_guest_queries": true, "supports_join_request_queries": true}' - result = types.User.de_json(json_str) - assert result.id == 123456789 - assert result.is_bot == False - assert result.first_name == 'John' - assert result.last_name == 'Doe' - assert result.username == '@johndoe' - assert result.language_code == 'en' - assert result.can_join_groups == True - assert result.can_read_all_group_messages == False - assert result.supports_inline_queries == True - assert result.is_premium == True - assert result.added_to_attachment_menu == False - assert result.can_connect_to_business == True - assert result.has_main_web_app == False - assert result.has_topics_enabled == True - assert result.allows_users_to_create_topics == True - assert result.can_manage_bots == True - assert result.supports_guest_queries == True - assert result.supports_join_request_queries == True - assert isinstance(result, types.User) + jsonstring = r'{"id":101176298,"first_name":"RDSSBOT","last_name":")))","username":"rdss_bot","is_bot":true, "is_premium":true, "added_to_attachment_menu": true}' + u = types.User.de_json(jsonstring) + assert u.id == 101176298 + assert u.full_name == 'RDSSBOT )))' + assert u.is_premium is True + assert u.added_to_attachment_menu is True -def test_json_chat(): - json_str = r'{"id": 12345, "type": "private", "title": "Test Chat", "username": "@testchat", "first_name": "John", "last_name": "Doe", "photo": {"small_file_id": "s", "small_file_unique_id": "su", "big_file_id": "b", "big_file_unique_id": "bu"}, "bio": "bio text", "has_private_forwards": true, "description": "chat description", "invite_link": "https://t.me/joinchat/ABC", "pinned_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "pinned"}, "permissions": {"can_send_messages": true, "can_send_audios": true, "can_send_documents": true, "can_send_photos": true, "can_send_videos": true, "can_send_video_notes": true, "can_send_voice_notes": true, "can_send_polls": true, "can_send_other_messages": true, "can_add_web_page_previews": true, "can_change_info": true, "can_invite_users": true, "can_pin_messages": true, "can_manage_topics": true}, "slow_mode_delay": 30, "message_auto_delete_time": 86400, "has_protected_content": true, "sticker_set_name": "TestStickerSet", "can_set_sticker_set": false, "linked_chat_id": 2, "location": {"chat": {"id": 1, "type": "supergroup", "title": "Loc"}, "location": {"latitude": 50.45, "longitude": 30.52}, "address": "Main St"}, "join_to_send_messages": false, "join_by_request": true, "has_restricted_voice_and_video_messages": false, "is_forum": true, "max_reaction_count": 10, "active_usernames": ["test"], "emoji_status_custom_emoji_id": "custom_emoji", "has_hidden_members": false, "has_aggressive_anti_spam_enabled": false, "emoji_status_expiration_date": 1682275907, "available_reactions": ["emoji", "custom_emoji"], "accent_color_id": 1, "background_custom_emoji_id": "bg_emoji", "profile_accent_color_id": 2, "profile_background_custom_emoji_id": "profile_bg", "has_visible_history": true, "unrestrict_boost_count": 5, "custom_emoji_sticker_set_name": "custom_stickers", "business_intro": {"title": "Business", "description": "Business desc", "has_visible_history": true}, "business_location": {"address": "New York, NY", "has_active_address": true}, "business_opening_hours": {"time_zone_name": "America/New_York", "opening_hours": [{"opening_minute": 540, "closing_minute": 1020, "day_of_week": 1, "is_recurring": true}]}, "personal_chat": {"id": 3, "type": "private", "title": "Personal"}, "birthdate": {"day": "15", "month": "6"}, "can_send_paid_media": true, "accepted_gift_types": {"unlimited_gifts": false, "limited_gifts": false, "unique_gifts": true, "premium_subscription": false, "gifts_from_channels": false}, "is_direct_messages": true, "parent_chat": {"id": 4, "type": "supergroup", "title": "Parent"}, "rating": {"level": "test", "rating": "test", "current_level_rating": "test"}, "paid_message_star_count": 5, "first_profile_audio": {"file_id": "fa1", "file_unique_id": "fa1u", "duration": 30, "mime_type": "audio/ogg"}, "unique_gift_colors": {"model_custom_emoji_id": 1, "symbol_custom_emoji_id": 1, "light_theme_main_color": 333333, "light_theme_other_colors": [444444], "dark_theme_main_color": 555555, "dark_theme_other_colors": [666666]}, "guard_bot": {"id": 2, "is_bot": true, "first_name": "GuardBot"}, "community": {"id": 5, "name": "Community"}}' - result = types.Chat.de_json(json_str) - assert result.id == 12345 - assert result.type == 'private' - assert result.title == 'Test Chat' - assert result.username == "@testchat" - assert result.first_name == "John" - assert result.last_name == "Doe" - assert isinstance(result.photo, types.ChatPhoto) - assert result.bio == "bio text" - assert result.has_private_forwards == True - assert result.description == "chat description" - assert result.invite_link == "https://t.me/joinchat/ABC" - assert isinstance(result.pinned_message, types.Message) - assert isinstance(result.permissions, types.ChatPermissions) - assert result.slow_mode_delay == 30 - assert result.message_auto_delete_time == 86400 - assert result.has_protected_content == True - assert result.sticker_set_name == "TestStickerSet" - assert result.can_set_sticker_set == False - assert result.linked_chat_id == 2 - assert isinstance(result.location, types.ChatLocation) - assert result.join_to_send_messages == False - assert result.join_by_request == True - assert result.has_restricted_voice_and_video_messages == False - assert result.is_forum == True - assert result.max_reaction_count == 10 - assert isinstance(result.active_usernames, list) - assert result.emoji_status_custom_emoji_id == "custom_emoji" - assert result.has_hidden_members == False - assert result.has_aggressive_anti_spam_enabled == False - assert result.emoji_status_expiration_date == 1682275907 - assert isinstance(result.available_reactions, list) - assert result.accent_color_id == 1 - assert result.background_custom_emoji_id == "bg_emoji" - assert result.profile_accent_color_id == 2 - assert result.profile_background_custom_emoji_id == "profile_bg" - assert result.has_visible_history == True - assert result.unrestrict_boost_count == 5 - assert result.custom_emoji_sticker_set_name == "custom_stickers" - assert isinstance(result.business_intro, types.BusinessIntro) - assert isinstance(result.business_location, types.BusinessLocation) - assert isinstance(result.business_opening_hours, types.BusinessOpeningHours) - assert isinstance(result.personal_chat, types.Chat) - assert isinstance(result.birthdate, types.Birthdate) - assert result.can_send_paid_media == True - assert isinstance(result.accepted_gift_types, types.AcceptedGiftTypes) - assert result.is_direct_messages == True - assert isinstance(result.parent_chat, types.Chat) - assert isinstance(result.rating, types.UserRating) - assert result.paid_message_star_count == 5 - assert isinstance(result.unique_gift_colors, types.UniqueGiftColors) - assert isinstance(result.first_profile_audio, types.Audio) - assert isinstance(result.guard_bot, types.User) - assert isinstance(result.community, types.Community) - assert isinstance(result, types.Chat) - - -# NOTE: Message has internal fields that are not covered by de_json tests: -# - options: internal field, not from JSON -# - json_string: internal field, not from JSON -def test_json_message(): - json_str = r'{"message_id": 1, "date": 1682189507, "chat": {"id": 12345, "type": "private", "title": "Chat"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "Hello", "content_type": "text"}' - result = types.Message.de_json(json_str) - assert result.message_id == 1 - assert isinstance(result.from_user, types.User) - assert result.date == 1682189507 - assert isinstance(result.chat, types.Chat) - assert result.content_type == 'text' - assert isinstance(result, types.Message) - - -def test_json_location(): - json_str = r'{"latitude": 50.4501, "longitude": 30.5234, "horizontal_accuracy": 1.5, "live_period": 3600, "heading": 45, "proximity_alert_radius": 100}' - result = types.Location.de_json(json_str) - assert result.longitude == 30.5234 - assert result.latitude == 50.4501 - assert result.horizontal_accuracy == 1.5 - assert result.live_period == 3600 - assert result.heading == 45 - assert result.proximity_alert_radius == 100 - assert isinstance(result, types.Location) - - -def test_json_venue(): - json_str = r'{"location": {"latitude": 50.45, "longitude": 30.52}, "title": "Kyiv", "address": "Khreshchatyk St", "foursquare_id": "12345", "foursquare_type": "restaurant", "google_place_id": "ChI123456", "google_place_type": "locality"}' - result = types.Venue.de_json(json_str) - assert isinstance(result.location, types.Location) - assert result.title == 'Kyiv' - assert result.address == 'Khreshchatyk St' - assert result.foursquare_id == '12345' - assert result.foursquare_type == 'restaurant' - assert result.google_place_id == 'ChI123456' - assert result.google_place_type == 'locality' - assert isinstance(result, types.Venue) - - -def test_json_contact(): - json_str = r'{"phone_number": "+123****7890", "first_name": "John", "user_id": 12345, "last_name": "Doe", "vcard": "some vcard data"}' - result = types.Contact.de_json(json_str) - assert result.phone_number == '+123****7890' - assert result.first_name == 'John' - assert result.last_name == 'Doe' - assert result.user_id == 12345 - assert result.vcard == 'some vcard data' - assert isinstance(result, types.Contact) - - -def test_json_document(): - json_str = r'{"file_id": "doc1", "file_unique_id": "du1", "file_name": "test.pdf", "mime_type": "application/pdf", "file_size": 1024, "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 50, "height": 50}}' - result = types.Document.de_json(json_str) - assert result.file_id == 'doc1' - assert result.file_unique_id == 'du1' - assert isinstance(result.thumbnail, types.PhotoSize) - assert result.file_name == 'test.pdf' - assert result.mime_type == 'application/pdf' - assert result.file_size == 1024 - assert isinstance(result, types.Document) - - -def test_json_photo_size(): - json_str = r'{"file_id": "photo1", "file_unique_id": "pu1", "width": 100, "height": 100, "file_size": 512}' - result = types.PhotoSize.de_json(json_str) - assert result.file_id == 'photo1' - assert result.file_unique_id == 'pu1' - assert result.width == 100 - assert result.height == 100 - assert result.file_size == 512 - assert isinstance(result, types.PhotoSize) - - -def test_json_video(): - json_str = r'{"file_id": "video1", "file_unique_id": "vu1", "width": 640, "height": 480, "duration": 30, "mime_type": "video/mp4", "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 50, "height": 50}, "file_name": "video.mp4", "file_size": 2048, "start_timestamp": 5, "qualities": [{"file_id": "q1", "file_unique_id": "qu1", "width": 240, "height": 360, "codec": "h264", "file_size": 1024}, {"file_id": "q2", "file_unique_id": "qu2", "width": 640, "height": 480, "codec": "h264", "file_size": 2048}]}' - result = types.Video.de_json(json_str) - assert result.file_id == 'video1' - assert result.file_unique_id == 'vu1' - assert result.width == 640 - assert result.height == 480 - assert result.duration == 30 - assert isinstance(result.thumbnail, types.PhotoSize) - assert result.file_name == 'video.mp4' - assert result.mime_type == 'video/mp4' - assert result.file_size == 2048 - assert result.cover is None - assert result.start_timestamp == 5 - assert isinstance(result.qualities, list) - assert isinstance(result, types.Video) - - -def test_json_audio(): - json_str = r'{"file_id": "audio1", "file_unique_id": "au1", "duration": 30, "mime_type": "audio/mpeg", "performer": "Artist", "title": "Song Title", "file_name": "song.mp3", "file_size": 512, "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 50, "height": 50}}' - result = types.Audio.de_json(json_str) - assert result.file_id == 'audio1' - assert result.file_unique_id == 'au1' - assert result.duration == 30 - assert result.performer == 'Artist' - assert result.title == 'Song Title' - assert result.file_name == 'song.mp3' - assert result.mime_type == 'audio/mpeg' - assert result.file_size == 512 - assert isinstance(result.thumbnail, types.PhotoSize) - assert isinstance(result, types.Audio) - - -def test_json_voice(): - json_str = r'{"file_id": "voice1", "file_unique_id": "vu1", "duration": 30, "mime_type": "audio/ogg", "file_size": 256}' - result = types.Voice.de_json(json_str) - assert result.file_id == 'voice1' - assert result.file_unique_id == 'vu1' - assert result.duration == 30 - assert result.mime_type == 'audio/ogg' - assert result.file_size == 256 - assert isinstance(result, types.Voice) - - -def test_json_animation(): - json_str = r'{"file_id": "anim1", "file_unique_id": "anu1", "width": 100, "height": 100, "duration": 10, "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 50, "height": 50}, "file_name": "anim.mp4", "mime_type": "video/mp4", "file_size": 1024}' - result = types.Animation.de_json(json_str) - assert result.file_id == 'anim1' - assert result.file_unique_id == 'anu1' - assert result.width == 100 - assert result.height == 100 - assert result.duration == 10 - assert isinstance(result.thumbnail, types.PhotoSize) - assert result.file_name == 'anim.mp4' - assert result.mime_type == 'video/mp4' - assert result.file_size == 1024 - assert isinstance(result, types.Animation) - - -def test_json_sticker(): - json_str = r'{"file_id": "sticker1", "file_unique_id": "stu1", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false, "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 100, "height": 100}, "emoji": "😀", "set_name": "TestSet", "mask_position": {"point": "forehead", "x_shift": 0.0, "y_shift": 0.0, "scale": 0.5}, "file_size": 4096, "premium_animation": {"file_id": "pa1", "file_unique_id": "pa1u"}, "custom_emoji_id": "ce1", "needs_repainting": true}' - result = types.Sticker.de_json(json_str) - assert result.file_id == 'sticker1' - assert result.file_unique_id == 'stu1' - assert result.type == 'regular' - assert result.width == 512 - assert result.height == 512 - assert result.is_animated == False - assert result.is_video == False - assert isinstance(result.thumbnail, types.PhotoSize) - assert result.emoji == '😀' - assert result.set_name == 'TestSet' - assert isinstance(result.mask_position, types.MaskPosition) - assert result.file_size == 4096 - assert isinstance(result.premium_animation, types.File) - assert result.custom_emoji_id == 'ce1' - assert result.needs_repainting == True - assert isinstance(result, types.Sticker) - - -def test_json_stickerset(): - json_str = r'{"name": "TestName", "title": "Test Title", "sticker_type": "regular", "stickers": [{"file_id": "st1", "file_unique_id": "su1", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}], "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 100, "height": 100}}' - result = types.StickerSet.de_json(json_str) - assert result.name == 'TestName' - assert result.title == 'Test Title' - assert result.sticker_type == 'regular' - assert isinstance(result.stickers, list) - assert isinstance(result.thumbnail, types.PhotoSize) - assert isinstance(result, types.StickerSet) - - -def test_json_chatlocation(): - json_str = r'{"location": {"latitude": 50.45, "longitude": 30.52}, "address": "New York, NY"}' - result = types.ChatLocation.de_json(json_str) - assert isinstance(result.location, types.Location) - assert result.address == 'New York, NY' - - -def test_json_reactiontypeemoji(): - json_str = r'{"type": "emoji", "emoji": "\u2764\uFE0F"}' - result = types.ReactionTypeEmoji.de_json(json_str) - assert result.emoji == '❤️' - assert isinstance(result, types.ReactionTypeEmoji) - - -def test_json_reactiontypecustomemoji(): - json_str = r'{"type": "custom_emoji", "custom_emoji_id": "ce123"}' - result = types.ReactionTypeCustomEmoji.de_json(json_str) - assert result.custom_emoji_id == 'ce123' - assert isinstance(result, types.ReactionTypeCustomEmoji) - - -def test_json_reactioncount(): - json_str = r'{"type": {"type": "emoji", "emoji": "\u2764\uFE0F"}, "total_count": 5}' - result = types.ReactionCount.de_json(json_str) - assert isinstance(result.type, types.ReactionType) - assert result.total_count == 5 - assert isinstance(result, types.ReactionCount) - - -def test_json_chatinvitelink(): - json_str = r'{"invite_link": "https://t.me/joinchat/ABC", "creator": {"id": 12345, "is_bot": false, "first_name": "Test"}, "creates_join_request": false, "is_primary": true, "is_revoked": false, "name": "Invite", "expire_date": 1704067200, "member_limit": 10, "pending_join_request_count": 3}' - result = types.ChatInviteLink.de_json(json_str) - assert result.invite_link == 'https://t.me/joinchat/ABC' - assert isinstance(result.creator, types.User) - assert result.creates_join_request == False - assert result.is_primary == True - assert result.is_revoked == False - assert result.name == 'Invite' - assert result.expire_date == 1704067200 - assert result.member_limit == 10 - assert result.pending_join_request_count == 3 - assert isinstance(result, types.ChatInviteLink) - - -def test_json_forumtopic(): - json_str = r'{"message_thread_id": 42, "name": "Topic", "icon_color": 4294967295, "icon_custom_emoji_id": "emoji1", "is_name_implicit": true}' - result = types.ForumTopic.de_json(json_str) - assert result.message_thread_id == 42 - assert result.name == 'Topic' - assert result.icon_color == 4294967295 - assert result.icon_custom_emoji_id == 'emoji1' - assert result.is_name_implicit == True - assert isinstance(result, types.ForumTopic) - - -def test_json_loginurl(): - json_str = r'{"url": "https://example.com", "forward_text": "Forward", "bot_username": "botuser", "request_write_access": true}' - result = types.LoginUrl.de_json(json_str) - assert result.url == 'https://example.com' - assert result.forward_text == 'Forward' - assert result.bot_username == 'botuser' - assert result.request_write_access == True - assert isinstance(result, types.LoginUrl) - - -def test_json_webappinfo(): - json_str = r'{"url": "https://example.com"}' - result = types.WebAppInfo.de_json(json_str) - assert result.url == 'https://example.com' - assert isinstance(result, types.WebAppInfo) - - -def test_json_webappdata(): - json_str = r'{"data": "test_data", "button_text": "Button"}' - result = types.WebAppData.de_json(json_str) - assert result.data == 'test_data' - assert result.button_text == 'Button' - assert isinstance(result, types.WebAppData) - - -def test_json_maskposition(): - json_str = r'{"point": "forehead", "x_shift": 0.0, "y_shift": 0.0, "scale": 0.5}' - result = types.MaskPosition.de_json(json_str) - assert result.point == 'forehead' - assert result.x_shift == 0.0 - assert result.y_shift == 0.0 - assert result.scale == 0.5 - assert isinstance(result, types.MaskPosition) - - -def test_json_messageentity(): - json_str = r'{"type": "bold", "offset": 0, "length": 5, "url": "https://example.com", "language": "en", "unix_time": 1682189507, "date_time_format": "YYYY-MM-DD"}' - result = types.MessageEntity.de_json(json_str) - assert result.type == 'bold' - assert result.offset == 0 - assert result.length == 5 - assert result.url == 'https://example.com' - assert result.language == 'en' - assert result.unix_time == 1682189507 - assert result.date_time_format == 'YYYY-MM-DD' - assert isinstance(result, types.MessageEntity) - - -def test_json_messageentitycustomemoji(): - json_str = r'{"type": "custom_emoji", "offset": 0, "length": 10, "custom_emoji_id": "ce123"}' - result = types.MessageEntity.de_json(json_str) - assert result.type == 'custom_emoji' - assert result.offset == 0 - assert result.length == 10 - assert result.custom_emoji_id == 'ce123' - assert isinstance(result, types.MessageEntity) - - -def test_json_messageentitytextmention(): - json_str = r'{"type": "text_mention", "offset": 0, "length": 10, "user": {"id": 12345, "is_bot": false, "first_name": "Test"}}' - result = types.MessageEntity.de_json(json_str) - assert result.type == 'text_mention' - assert result.offset == 0 - assert result.length == 10 - assert isinstance(result.user, types.User) - assert isinstance(result, types.MessageEntity) - - -def test_json_chatshared(): - json_str = r'{"request_id": 1, "chat_id": 12345, "title": "Chat Title", "photo": {"small_file_id": "s", "small_file_unique_id": "su", "big_file_id": "b", "big_file_unique_id": "bu"}, "username": "chatuser"}' - result = types.ChatShared.de_json(json_str) - assert result.request_id == 1 - assert result.chat_id == 12345 - assert result.title == 'Chat Title' - # photo is returned as dict in this fork (not parsed to ChatPhoto) - assert isinstance(result.photo, dict) - assert result.photo.get('small_file_id') == 's' - assert result.username == 'chatuser' - assert isinstance(result, types.ChatShared) - - -def test_json_shareduser(): - json_str = r'{"user_id": 12345, "first_name": "Test", "last_name": "User", "username": "testuser", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}' - result = types.SharedUser.de_json(json_str) - assert result.user_id == 12345 - assert result.first_name == 'Test' - assert result.last_name == 'User' - assert result.username == 'testuser' - assert isinstance(result.photo, list) - assert isinstance(result.photo[0], types.PhotoSize) - assert isinstance(result, types.SharedUser) - - -def test_json_usersshared(): - json_str = r'{"request_id": 1, "users": [{"user_id": 12345, "first_name": "Test", "last_name": "User"}]}' - result = types.UsersShared.de_json(json_str) - assert result.request_id == 1 - assert isinstance(result.users, list) - assert isinstance(result, types.UsersShared) - - -def test_json_chatboost(): - json_str = r'{"boost_item_id": "b1", "add_date": 1682189507, "expiration_date": 1682275907, "source": {"source": "premium", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}}' - result = types.ChatBoost.de_json(json_str) - assert result.boost_id is None - assert result.add_date == 1682189507 - assert result.expiration_date == 1682275907 - assert isinstance(result.source, types.ChatBoostSourcePremium) - assert result.source.source == 'premium' - assert isinstance(result.source.user, types.User) - assert isinstance(result, types.ChatBoost) - - -def test_json_gift(): - json_str = r'{"id": 123456789, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100, "total_count": 5, "remaining_count": 3, "upgrade_star_count": 50, "personal_total_count": 10, "personal_remaining_count": 2, "is_premium": true, "has_colors": true, "background": {"center_color": 16777215, "edge_color": 16711680, "text_color": 0}, "publisher_chat": {"id": 1, "type": "channel", "title": "Publisher"}, "unique_gift_variant_count": 3}' - result = types.Gift.de_json(json_str) - assert result.id == 123456789 - assert isinstance(result.sticker, types.Sticker) - assert result.star_count == 100 - assert result.total_count == 5 - assert result.remaining_count == 3 - assert result.upgrade_star_count == 50 - assert result.personal_total_count == 10 - assert result.personal_remaining_count == 2 - assert result.is_premium == True - assert result.has_colors == True - assert isinstance(result.background, types.GiftBackground) - assert isinstance(result.publisher_chat, types.Chat) - assert result.unique_gift_variant_count == 3 - assert isinstance(result, types.Gift) - - -def test_json_giftinfo(): - json_str = r'{"gift": {"id": 123456789, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100}, "owned_gift_id": "og_123", "convert_star_count": 50, "prepaid_upgrade_star_count": 100, "can_be_upgraded": true, "text": {"type": "bold", "text": "Gift text"}, "entities": [{"type": "bold", "offset": 0, "length": 4}], "is_private": false, "is_upgrade_separate": false, "unique_gift_number": 42}' - result = types.GiftInfo.de_json(json_str) - assert isinstance(result.gift, types.Gift) - assert result.owned_gift_id == 'og_123' - assert result.convert_star_count == 50 - assert result.prepaid_upgrade_star_count == 100 - assert result.can_be_upgraded == True - assert result.text == {'type': 'bold', 'text': 'Gift text'} - assert isinstance(result.entities, list) - assert result.is_private == False - assert result.is_upgrade_separate == False - assert result.unique_gift_number == 42 - assert isinstance(result, types.GiftInfo) - - -def test_json_gifts(): - json_str = r'{"gifts": [{"id": 123456789, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100}]}' - result = types.Gifts.de_json(json_str) - assert isinstance(result.gifts, list) - assert isinstance(result, types.Gifts) - - -def test_json_richtextbold(): - json_str = r'{"type": "bold", "text": "Test"}' - result = types.RichText.de_json(json_str) - assert result.text == 'Test' - assert isinstance(result, types.RichTextBold) - - -def test_json_richtextitalic(): - json_str = r'{"type": "italic", "text": "Test"}' - result = types.RichText.de_json(json_str) - assert result.text == 'Test' - assert isinstance(result, types.RichTextItalic) - - -def test_json_richtextunderline(): - json_str = r'{"type": "underline", "text": "Test"}' - result = types.RichText.de_json(json_str) - assert result.text == 'Test' - assert isinstance(result, types.RichTextUnderline) - - -def test_json_richtextstrikethrough(): - json_str = r'{"type": "strikethrough", "text": "Test"}' - result = types.RichText.de_json(json_str) - assert result.text == 'Test' - assert isinstance(result, types.RichTextStrikethrough) - - -def test_json_richtextspoiler(): - json_str = r'{"type": "spoiler", "text": "Test"}' - result = types.RichText.de_json(json_str) - assert result.text == 'Test' - assert isinstance(result, types.RichTextSpoiler) - - -def test_json_richtextsubscript(): - json_str = r'{"type": "subscript", "text": "sub"}' - result = types.RichText.de_json(json_str) - assert result.text == 'sub' - assert isinstance(result, types.RichTextSubscript) - - -def test_json_richtextsuperscript(): - json_str = r'{"type": "superscript", "text": "sup"}' - result = types.RichText.de_json(json_str) - assert result.text == 'sup' - assert isinstance(result, types.RichTextSuperscript) - - -def test_json_richtextmarked(): - json_str = r'{"type": "marked", "text": "marked"}' - result = types.RichText.de_json(json_str) - assert result.text == 'marked' - assert isinstance(result, types.RichTextMarked) - - -def test_json_richtextcode(): - json_str = r'{"type": "code", "text": "code"}' - result = types.RichText.de_json(json_str) - assert result.text == 'code' - assert isinstance(result, types.RichTextCode) - - -def test_json_richtextanchor(): - json_str = r'{"type": "anchor", "name": "anchor"}' - result = types.RichText.de_json(json_str) - assert result.name == 'anchor' - assert isinstance(result, types.RichTextAnchor) - - -def test_json_richtextdatetime(): - json_str = r'{"type": "date_time", "text": "2024-01-01", "unix_time": 1704067200, "date_time_format": "YYYY-MM-DD"}' - result = types.RichText.de_json(json_str) - assert result.text == '2024-01-01' - assert result.unix_time == 1704067200 - assert result.date_time_format == 'YYYY-MM-DD' - assert isinstance(result, types.RichTextDateTime) - - -def test_json_richtexttextmention(): - json_str = r'{"type": "text_mention", "text": "test text", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}}' - result = types.RichText.de_json(json_str) - assert result.text == 'test text' - assert isinstance(result.user, types.User) - assert isinstance(result, types.RichTextTextMention) - - -def test_json_richtextanchorlink(): - json_str = r'{"type": "anchor_link", "text": "Link", "anchor_name": "anchor"}' - result = types.RichText.de_json(json_str) - assert result.text == 'Link' - assert result.anchor_name == 'anchor' - assert isinstance(result, types.RichTextAnchorLink) - - -def test_json_richtexturl(): - json_str = r'{"type": "url", "text": "click here", "url": "https://example.com"}' - result = types.RichText.de_json(json_str) - assert result.text == 'click here' - assert result.url == 'https://example.com' - assert isinstance(result, types.RichTextUrl) - - -def test_json_richtextemailaddress(): - json_str = r'{"type": "email_address", "text": "test@example.com", "email_address": "test@example.com"}' - result = types.RichText.de_json(json_str) - assert result.text == 'test@example.com' - assert result.email_address == 'test@example.com' - assert isinstance(result, types.RichTextEmailAddress) - - -def test_json_richtextphonenumber(): - json_str = r'{"type": "phone_number", "text": "+123****7890", "phone_number": "+123****7890"}' - result = types.RichText.de_json(json_str) - assert result.text == '+123****7890' - assert result.phone_number == '+123****7890' - assert isinstance(result, types.RichTextPhoneNumber) - - -def test_json_richtextbankcardnumber(): - json_str = r'{"type": "bank_card_number", "text": "1234 5678 9012 3456", "bank_card_number": "1234 5678 9012 3456"}' - result = types.RichText.de_json(json_str) - assert result.text == '1234 5678 9012 3456' - assert result.bank_card_number == '1234 5678 9012 3456' - assert isinstance(result, types.RichTextBankCardNumber) - - -def test_json_richblockparagraph(): - json_str = r'{"type": "paragraph", "text": "Test"}' - result = types.RichBlock.de_json(json_str) - assert result.text == 'Test' - assert isinstance(result, types.RichBlockParagraph) - - -def test_json_richblockpreformatted(): - json_str = r'{"type": "pre", "text": "Code", "language": "python"}' - result = types.RichBlock.de_json(json_str) - assert result.text == 'Code' - assert result.language == 'python' - assert isinstance(result, types.RichBlockPreformatted) - - -def test_json_richblockfooter(): - json_str = r'{"type": "footer", "text": "Footer"}' - result = types.RichBlock.de_json(json_str) - assert result.text == 'Footer' - assert isinstance(result, types.RichBlockFooter) - - -def test_json_richblockcaption(): - json_str = r'{"text": "Caption", "credit": "Author"}' - result = types.RichBlockCaption.de_json(json_str) - assert result.text == 'Caption' - assert result.credit == 'Author' - assert isinstance(result, types.RichBlockCaption) - - -def test_json_richblockanimation(): - json_str = r'{"type": "animation", "animation": {"file_id": "anim_id", "file_unique_id": "anim_uid", "width": 100, "height": 100, "duration": 10}, "caption": {"type": "bold", "text": "anim caption"}, "has_spoiler": true}' - result = types.RichBlock.de_json(json_str) - assert isinstance(result.animation, types.Animation) - assert result.has_spoiler == True - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockAnimation) - - -def test_json_richblockdetails(): - json_str = r'{"type": "details", "summary": {"text": "summary text"}, "blocks": [{"text": "detail"}], "is_open": false}' - result = types.RichBlock.de_json(json_str) - assert isinstance(result.summary, dict) or result.summary is None - assert isinstance(result.blocks, list) - assert result.is_open == False - assert isinstance(result, types.RichBlockDetails) - - -def test_json_richblocklistitem(): - json_str = r'{"label": {"text": "label text"}, "blocks": [{"text": "item block"}], "has_checkbox": true, "is_checked": true, "value": "item value", "type": null}' - result = types.RichBlockListItem.de_json(json_str) - assert isinstance(result.label, dict) - assert isinstance(result.blocks, list) - assert result.has_checkbox == True - assert result.is_checked == True - assert result.value == 'item value' - assert result.type is None - assert isinstance(result, types.RichBlockListItem) - - -def test_json_richblockvoicenote(): - json_str = r'{"type": "voice_note", "voice_note": {"file_id": "voice_id", "file_unique_id": "voice_uid", "duration": 30}, "caption": {"type": "bold", "text": "voice caption"}}' - result = types.RichBlock.de_json(json_str) - assert isinstance(result.voice_note, types.Voice) - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockVoiceNote) - - -def test_json_chatadministratorrights(): - json_str = r'{"is_anonymous": true, "can_manage_chat": true, "can_delete_messages": true, "can_manage_video_chats": true, "can_restrict_members": true, "can_promote_members": true, "can_change_info": true, "can_invite_users": true, "can_post_messages": true, "can_edit_messages": true, "can_pin_messages": true, "can_manage_topics": true, "can_post_stories": true, "can_edit_stories": true, "can_delete_stories": true, "can_manage_direct_messages": true, "can_manage_tags": true}' - result = types.ChatAdministratorRights.de_json(json_str) - assert result.is_anonymous == True - assert result.can_manage_chat == True - assert result.can_delete_messages == True - assert result.can_manage_video_chats == True - assert result.can_restrict_members == True - assert result.can_promote_members == True - assert result.can_change_info == True - assert result.can_invite_users == True - assert result.can_post_messages == True - assert result.can_edit_messages == True - assert result.can_pin_messages == True - assert result.can_manage_topics == True - assert result.can_post_stories == True - assert result.can_edit_stories == True - assert result.can_delete_stories == True - assert result.can_manage_direct_messages == True - assert result.can_manage_tags == True - assert isinstance(result, types.ChatAdministratorRights) - - -def test_json_chatpermissions(): - json_str = r'{"can_send_messages": true, "can_send_audios": true, "can_send_documents": true, "can_send_photos": true, "can_send_videos": true, "can_send_video_notes": true, "can_send_voice_notes": true, "can_send_polls": true, "can_send_other_messages": true, "can_add_web_page_previews": true, "can_change_info": true, "can_invite_users": true, "can_pin_messages": true, "can_manage_topics": true, "can_edit_tag": true, "can_react_to_messages": true}' - result = types.ChatPermissions.de_json(json_str) - assert result.can_send_messages == True - # can_send_media_messages is deprecated in this fork, not a real attribute - assert result.can_send_audios == True - assert result.can_send_documents == True - assert result.can_send_photos == True - assert result.can_send_videos == True - assert result.can_send_video_notes == True - assert result.can_send_voice_notes == True - assert result.can_send_polls == True - assert result.can_send_other_messages == True - assert result.can_add_web_page_previews == True - assert result.can_change_info == True - assert result.can_invite_users == True - assert result.can_pin_messages == True - assert result.can_manage_topics == True - assert result.can_edit_tag == True - assert result.can_react_to_messages == True - assert isinstance(result, types.ChatPermissions) - - -def test_json_chatmembermember(): - json_str = r'{"user": {"id": 1, "is_bot": false, "first_name": "Test"}, "status": "member", "until_date": 1682275907, "tag": "member_tag"}' - result = types.ChatMemberMember.de_json(json_str) - assert isinstance(result.user, types.User) - assert result.status == 'member' - assert result.until_date == 1682275907 - assert result.tag == 'member_tag' - assert isinstance(result, types.ChatMemberMember) - - -def test_json_chatmemberowner(): - json_str = r'{"status": "creator", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "is_anonymous": false, "custom_title": "Owner"}' - result = types.ChatMemberOwner.de_json(json_str) - assert isinstance(result.user, types.User) - assert result.status == 'creator' - assert result.is_anonymous == False - assert result.custom_title == 'Owner' - assert isinstance(result, types.ChatMemberOwner) - - -def test_json_chatmemberadministrator(): - json_str = r'{"status": "administrator", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "is_anonymous": true, "can_be_edited": true, "can_manage_chat": true, "can_delete_messages": true, "can_manage_video_chats": true, "can_restrict_members": true, "can_promote_members": true, "can_change_info": true, "can_invite_users": true, "can_post_stories": true, "can_edit_stories": true, "can_delete_stories": true, "can_post_messages": true, "can_edit_messages": true, "can_pin_messages": true, "can_manage_topics": true, "can_manage_direct_messages": true, "can_manage_tags": true, "custom_title": "mod"}' - result = types.ChatMemberAdministrator.de_json(json_str) - assert isinstance(result.user, types.User) - assert result.status == 'administrator' - assert result.can_be_edited == True - assert result.is_anonymous == True - assert result.can_manage_chat == True - assert result.can_delete_messages == True - assert result.can_manage_video_chats == True - assert result.can_restrict_members == True - assert result.can_promote_members == True - assert result.can_change_info == True - assert result.can_invite_users == True - assert result.can_post_stories == True - assert result.can_edit_stories == True - assert result.can_delete_stories == True - assert result.can_post_messages == True - assert result.can_edit_messages == True - assert result.can_pin_messages == True - assert result.can_manage_topics == True - assert result.custom_title == "mod" - assert result.can_manage_direct_messages == True - assert result.can_manage_tags == True - assert isinstance(result, types.ChatMemberAdministrator) - - -def test_json_chatmemberrestricted(): - json_str = r'{"status": "restricted", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "is_member": true, "can_send_messages": true, "can_send_audios": true, "can_send_documents": true, "can_send_photos": true, "can_send_videos": true, "can_send_video_notes": true, "can_send_voice_notes": true, "can_send_polls": true, "can_send_other_messages": true, "can_add_web_page_previews": true, "can_change_info": false, "can_invite_users": false, "can_pin_messages": false, "can_manage_topics": false, "until_date": 1682189507, "tag": "test_tag", "can_edit_tag": true, "can_react_to_messages": true}' - result = types.ChatMemberRestricted.de_json(json_str) - assert isinstance(result.user, types.User) - assert result.status == 'restricted' - assert result.is_member == True - assert result.can_send_messages == True - assert result.can_send_audios == True - assert result.can_send_documents == True - assert result.can_send_photos == True - assert result.can_send_videos == True - assert result.can_send_video_notes == True - assert result.can_send_voice_notes == True - assert result.can_send_polls == True - assert result.can_send_other_messages == True - assert result.can_add_web_page_previews == True - assert result.can_change_info == False - assert result.can_invite_users == False - assert result.can_pin_messages == False - assert result.can_manage_topics == False - assert result.until_date == 1682189507 - assert result.tag == 'test_tag' - assert result.can_edit_tag == True - assert result.can_react_to_messages == True - assert isinstance(result, types.ChatMemberRestricted) - - -def test_json_chatmemberleft(): - json_str = r'{"status": "left", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}}' - result = types.ChatMemberLeft.de_json(json_str) - assert isinstance(result.user, types.User) - assert result.status == 'left' - assert isinstance(result, types.ChatMemberLeft) - - -def test_json_chatmemberbanned(): - json_str = r'{"status": "kicked", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "until_date": 1682189507}' - result = types.ChatMemberBanned.de_json(json_str) - assert isinstance(result.user, types.User) - assert result.status == 'kicked' - assert result.until_date == 1682189507 - assert isinstance(result, types.ChatMemberBanned) - - -def test_json_botcommand(): - json_str = r'{"command": "/start", "description": "Start command", "is_ephemeral": true}' - result = types.BotCommand.de_json(json_str) - assert result.command == '/start' - assert result.description == 'Start command' - assert result.is_ephemeral == True - assert isinstance(result, types.BotCommand) - - -def test_json_botdescription(): - json_str = r'{"language_code": "en", "description": "Bot description"}' - result = types.BotDescription.de_json(json_str) - assert result.description == 'Bot description' - assert isinstance(result, types.BotDescription) - - -def test_json_botname(): - json_str = r'{"language_code": "en", "name": "Bot Name"}' - result = types.BotName.de_json(json_str) - assert result.name == 'Bot Name' - assert isinstance(result, types.BotName) - - -def test_json_botshortdescription(): - json_str = r'{"language_code": "en", "short_description": "Short"}' - result = types.BotShortDescription.de_json(json_str) - assert result.short_description == 'Short' - assert isinstance(result, types.BotShortDescription) - - -def test_json_inlinekeyboardbutton(): - json_str = r'{"text": "Button", "url": "https://example.com", "callback_data": "data", "web_app": {"url": "https://example.com"}, "switch_inline_query": "query", "switch_inline_query_current_chat": "query", "switch_inline_query_chosen_chat": {"query": "q", "allow_user_chats": true, "allow_bot_chats": true, "allow_group_chats": true, "allow_channel_chats": true}, "callback_game": {"type": "test"}, "pay": true, "login_url": {"url": "https://example.com", "forward_text": "Forward", "bot_username": "bot", "request_write_access": true}, "copy_text": {"text": "copy"}, "icon_custom_emoji_id": "emoji123", "style": "primary"}' - result = types.InlineKeyboardButton.de_json(json_str) - assert result.text == 'Button' - assert result.url == 'https://example.com' - assert result.callback_data == 'data' - assert isinstance(result.web_app, types.WebAppInfo) - assert result.switch_inline_query == 'query' - assert result.switch_inline_query_current_chat == 'query' - assert isinstance(result.switch_inline_query_chosen_chat, types.SwitchInlineQueryChosenChat) - assert isinstance(result.callback_game, dict) - assert result.pay == True - assert isinstance(result.login_url, types.LoginUrl) - assert isinstance(result.copy_text, types.CopyTextButton) - assert result.icon_custom_emoji_id == 'emoji123' - assert result.style == 'primary' - assert isinstance(result, types.InlineKeyboardButton) - - -def test_json_menubuttoncommands(): - json_str = r'{"type": "commands", "default_width": 100}' - result = types.MenuButtonCommands.de_json(json_str) - assert result.type == 'commands' - assert isinstance(result, types.MenuButtonCommands) - - -def test_json_menubuttondefault(): - json_str = r'{"type": "default"}' - result = types.MenuButtonDefault.de_json(json_str) - assert result.type == 'default' - assert isinstance(result, types.MenuButtonDefault) - - -def test_json_menubuttonwebapp(): - json_str = r'{"type": "web_app", "text": "Open App", "web_app": {"url": "https://example.com"}}' - result = types.MenuButtonWebApp.de_json(json_str) - assert result.type == 'web_app' - assert result.text == 'Open App' - assert isinstance(result.web_app, dict) - assert isinstance(result, types.MenuButtonWebApp) - - -def test_json_pollanswer(): - json_str = r'{"poll_id": "poll_id", "option_ids": [0], "option_persistent_ids": [0], "user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "voter_chat": {"id": 67890, "type": "channel", "title": "Channel"}}' - result = types.PollAnswer.de_json(json_str) - assert result.poll_id == 'poll_id' - assert isinstance(result.option_ids, list) - assert isinstance(result.option_persistent_ids, list) - assert isinstance(result.user, types.User) - assert isinstance(result.voter_chat, types.Chat) - assert isinstance(result, types.PollAnswer) - -def test_json_reactiontype(): - json_str = r'{"type": "emoji", "emoji": "\u2764\uFE0F"}' - result = types.ReactionType.de_json(json_str) - assert result.type == 'emoji' - assert isinstance(result, types.ReactionType) - - -def test_linkpreviewoptionsto_dict(): - obj = types.LinkPreviewOptions(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_sentwebappmessageto_dict(): - obj = types.SentWebAppMessage(message_id=1) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_json_reactiontypepaid(): - json_str = r'{"type": "paid"}' - result = types.ReactionTypePaid.de_json(json_str) - assert isinstance(result, types.ReactionTypePaid) - - -def test_json_businessbotrights(): - result = types.BusinessBotRights.de_json({}) - assert result.can_reply is None - assert result.can_read_messages is None - assert result.can_delete_outgoing_messages is None - assert result.can_delete_all_messages is None - assert result.can_edit_name is None - assert result.can_edit_bio is None - assert result.can_edit_profile_photo is None - assert result.can_edit_username is None - assert result.can_change_gift_settings is None - assert result.can_view_gifts_and_stars is None - assert result.can_convert_gifts_to_stars is None - assert result.can_transfer_and_upgrade_gifts is None - assert result.can_transfer_stars is None - assert result.can_manage_stories is None - assert isinstance(result, types.BusinessBotRights) - - -def test_json_businessintro(): - json_str = r'{"title": "Business Title", "message": "Business message text", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}}' - result = types.BusinessIntro.de_json(json_str) - assert result.title == 'Business Title' - assert result.message == 'Business message text' - assert isinstance(result.sticker, types.Sticker) - assert isinstance(result, types.BusinessIntro) - - -def test_json_chatownerleft(): - result = types.ChatOwnerLeft.de_json({}) - assert isinstance(result, types.ChatOwnerLeft) or result is None - assert result.new_owner is None - - -def test_json_checklisttasksdone(): - json_str = r'{"checklist_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "checklist"}, "marked_as_done_task_ids": [1, 2], "marked_as_not_done_task_ids": [3]}' - result = types.ChecklistTasksDone.de_json(json_str) - assert isinstance(result.checklist_message, types.Message) - assert isinstance(result.marked_as_done_task_ids, list) - assert result.marked_as_done_task_ids == [1, 2] - assert isinstance(result.marked_as_not_done_task_ids, list) - assert result.marked_as_not_done_task_ids == [3] - assert isinstance(result, types.ChecklistTasksDone) - - -def test_json_communitychatadded(): - result = types.CommunityChatAdded.de_json({}) - assert isinstance(result, types.CommunityChatAdded) or result is None - assert result.community is None +def test_json_message(): + jsonstring = r'{"message_id":1,"from":{"id":108929734,"first_name":"Frank","last_name":"Wang","username":"eternnoir","is_bot":true},"chat":{"id":1734,"first_name":"F","type":"private","last_name":"Wa","username":"oir"},"date":1435296025,"text":"HIHI"}' + msg = types.Message.de_json(jsonstring) + assert msg.text == 'HIHI' -def test_json_communitychatremoved(): - result = types.CommunityChatRemoved.de_json({}) - assert isinstance(result, types.CommunityChatRemoved) or result is None - - -def test_json_forumtopicclosed(): - result = types.ForumTopicClosed.de_json({}) - assert isinstance(result, types.ForumTopicClosed) or result is None +def test_json_message_with_reply_markup(): + jsonstring = r'{"message_id":48,"from":{"id":153587469,"is_bot":false,"first_name":"Neko","username":"Neko"},"chat":{"id":153587469,"first_name":"Neko","username":"Neko","type":"private"},"date":1598879570,"text":"test","reply_markup":{"inline_keyboard":[[{"text":"Google","url":"http://www.google.com"},{"text":"Yahoo","url":"http://www.yahoo.com"}]]}}' + msg = types.Message.de_json(jsonstring) + assert msg.content_type == 'text' + assert msg.reply_markup.keyboard[0][0].text == 'Google' -def test_json_forumtopicedited(): - result = types.ForumTopicEdited.de_json({'name': 'New Name', 'icon_custom_emoji_id': 'custom_emoji'}) - assert result.name == 'New Name' - assert result.icon_custom_emoji_id == 'custom_emoji' - assert isinstance(result, types.ForumTopicEdited) +def test_json_InlineKeyboardMarkup(): + jsonstring = r'{"inline_keyboard":[[{"text":"Google","url":"http://www.google.com"},{"text":"Yahoo","url":"http://www.yahoo.com"}]]}' + markup = types.InlineKeyboardMarkup.de_json(jsonstring) + assert markup.keyboard[0][0].text == 'Google' + assert markup.keyboard[0][1].url == 'http://www.yahoo.com' -def test_json_forumtopicreopened(): - result = types.ForumTopicReopened.de_json({}) - assert isinstance(result, types.ForumTopicReopened) or result is None +def test_json_InlineKeyboardButton(): + jsonstring = r'{"text":"Google","url":"http://www.google.com"}' + button = types.InlineKeyboardButton.de_json(jsonstring) + assert button.text == 'Google' + assert button.url == 'http://www.google.com' -def test_json_generalforumtopichidden(): - result = types.GeneralForumTopicHidden.de_json({}) - assert isinstance(result, types.GeneralForumTopicHidden) or result is None +def test_json_message_with_dice(): + jsonstring = r'{"message_id":5560,"from":{"id":879343317,"is_bot":false,"first_name":"George","last_name":"Forse","username":"dr_fxrse","language_code":"ru"},"chat":{"id":879343317,"first_name":"George","last_name":"Forse","username":"dr_fxrse","type":"private"},"date":1586926330,"dice":{"value": 4, "emoji": "\ud83c\udfaf"}}' + msg = types.Message.de_json(jsonstring) + assert msg.content_type == 'dice' + assert isinstance(msg.dice, types.Dice) + assert msg.dice.value == 4 + assert msg.dice.emoji == '🎯' -def test_json_generalforumtopicunhidden(): - result = types.GeneralForumTopicUnhidden.de_json({}) - assert isinstance(result, types.GeneralForumTopicUnhidden) or result is None +def test_json_message_group(): + json_string = r'{"message_id":10,"from":{"id":12345,"first_name":"g","last_name":"G","username":"GG","is_bot":true},"chat":{"id":-866,"type":"private","title":"\u4ea4"},"date":1435303157,"text":"HIHI","has_protected_content":true}' + msg = types.Message.de_json(json_string) + assert msg.text == 'HIHI' + assert len(msg.chat.title) != 0 + assert msg.from_user.username == 'GG' -def test_json_giveawaycreated(): - result = types.GiveawayCreated.de_json({}) - assert isinstance(result, types.GiveawayCreated) or result is None - assert hasattr(result, 'prize_star_count') +def test_json_GroupChat(): + json_string = r'{"id":8926,"title":"\u5c4e\u4f2f\u98ef\u98ef\u4e4b\u4ea4"}' + gc = types.GroupChat.de_json(json_string) + assert gc.id == 8926 -def test_json_linkpreviewoptions(): - result = types.LinkPreviewOptions.de_json({}) - assert result.is_disabled is None - assert result.url is None - assert result.prefer_small_media is None - assert result.prefer_large_media is None - assert result.show_above_text is None - assert isinstance(result, types.LinkPreviewOptions) +def test_json_Document(): + json_string = r'{"file_name":"Text File","thumbnail":{},"file_id":"BQADBQADMwIAAsYifgZ_CEh0u682xwI","file_unique_id": "AgADJQEAAqfhOEY","file_size":446}' + doc = types.Document.de_json(json_string) + assert doc.thumbnail is None + assert doc.file_name == 'Text File' -def test_json_orderinfo(): - json_str = {'name': 'John', 'phone_number': '+1234567890', 'email': 'john@example.com', 'shipping_address': {'country_code': 'US', 'city': 'New York', 'street_line1': '123 Main St', 'street_line2': 'Apt 4B', 'postal_code': '10001', 'state': 'NY', 'post_code': '10001'}} - result = types.OrderInfo.de_json(json_str) - assert result.name == 'John' - assert result.phone_number == '+1234567890' - assert result.email == 'john@example.com' - assert isinstance(result.shipping_address, types.ShippingAddress) - assert isinstance(result, types.OrderInfo) or result is None - assert hasattr(result, 'name') - assert hasattr(result, 'phone_number') - assert hasattr(result, 'email') +def test_json_Message_Audio(): + json_string = r'{"message_id":131,"from":{"id":12775,"first_name":"dd","username":"dd","is_bot":true },"chat":{"id":10834,"first_name":"dd","type":"private","type":"private","last_name":"dd","username":"dd"},"date":1439978364,"audio":{"duration":1,"mime_type":"audio\/mpeg","title":"pyTelegram","performer":"eternnoir","file_id":"BQADBQADDH1JaB8-1KyWUss2-Ag","file_unique_id": "AgADawEAAn8VSFY","file_size":20096}}' + msg = types.Message.de_json(json_string) + assert msg.audio.duration == 1 + assert msg.content_type == 'audio' + assert msg.audio.performer == 'eternnoir' + assert msg.audio.title == 'pyTelegram' -def test_json_pollmedia(): - json_str = r'{"animation": {"file_id": "a", "file_unique_id": "au", "width": 100, "height": 100, "duration": 10}, "audio": {"file_id": "au1", "file_unique_id": "au1u", "duration": 30}, "document": {"file_id": "d", "file_unique_id": "du", "file_name": "test.pdf"}, "live_photo": {"file_id": "lp", "file_unique_id": "lpu", "width": 100, "height": 100, "duration": 5}, "location": {"latitude": 50.45, "longitude": 30.52}, "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}], "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "venue": {"location": {"latitude": 50.45, "longitude": 30.52}, "title": "Place", "address": "Addr"}, "video": {"file_id": "v", "file_unique_id": "vu", "width": 640, "height": 480, "duration": 30}, "link": {"url": "https://example.com", "shows_above_caption": true, "enhanced_smileys": true, "prefer_large_media": true}}' - result = types.PollMedia.de_json(json_str) - assert isinstance(result.animation, types.Animation) - assert isinstance(result.audio, types.Audio) - assert isinstance(result.document, types.Document) - assert isinstance(result.live_photo, types.LivePhoto) - assert isinstance(result.location, types.Location) - assert isinstance(result.photo, list) - assert isinstance(result.sticker, types.Sticker) - assert isinstance(result.venue, types.Venue) - assert isinstance(result.video, types.Video) - assert isinstance(result.link, types.Link) - assert isinstance(result, types.PollMedia) +def test_json_Message_Sticker(): + json_string = r'{"message_id": 21552, "from": {"id": 590740002, "is_bot": false, "first_name": "⚜️ Ƥυrуα ⚜️", "username": "Purya", "language_code": "en"}, "chat": {"id": -1001309982000, "title": "123", "type": "supergroup"}, "date": 1594068909, "sticker": {"type": "regular", "width": 368, "height": 368, "emoji": "🤖", "set_name": "ipuryapack", "is_animated": false, "is_video": true, "thumbnail": {"file_id": "AAMCBAADHQJOFL7mAAJUMF8Dj62hpmDhpRAYvkc8CtIqipolAAJ8AAPA-8cF9yxjgjkLS97A0D4iXQARtQAHbQADHy4AAhoE", "file_unique_id": "AQADwNA-Il0AAx8uAAI", "file_size": 7776, "width": 60, "height": 60}, "file_id": "CAACAgQAAx0CThS-5gACVDBfA4-toaZg4aUQGL5HWerSKoqaJQACArADwPvHBfcsY4I5C3feGgQ", "file_unique_id": "AgADfAADsPvHWQ", "file_size": 14602}}' + msg = types.Message.de_json(json_string) + assert msg.sticker.height == 368 + assert msg.sticker.thumbnail.height == 60 + assert msg.content_type == 'sticker' -def test_json_richblockdivider(): - json_str = r'{"type": "divider"}' - result = types.RichBlock.de_json(json_str) - assert isinstance(result, types.RichBlockDivider) +def test_json_Message_Sticker_without_thumbnail(): + json_string = r'{"message_id": 21552, "from": {"id": 590740002, "is_bot": false, "first_name": "⚜️ Ƥυrуα ⚜️", "username": "Purya", "language_code": "en"}, "chat": {"id": -1001309982000, "title": "123", "type": "supergroup"}, "date": 1594068909, "sticker": {"type": "regular", "width": 368, "height": 368, "emoji": "🤖", "set_name": "ipuryapack", "is_animated": false, "is_video": true, "file_id": "CAACAgQAAx0CThS-5gACVDBfA4-toaZg4aUQGL5HWerSKoqaJQACArADwPvHBfcsY4I5C3feGgQ", "file_unique_id": "AgADfAADsPvHWQ", "file_size": 14602}}' + msg = types.Message.de_json(json_string) + assert msg.sticker.height == 368 + assert msg.sticker.thumbnail is None + assert msg.content_type == 'sticker' -def test_json_sentwebappmessage(): - result = types.SentWebAppMessage.de_json({}) - assert isinstance(result, types.SentWebAppMessage) or result is None - assert hasattr(result, 'inline_message_id') +def test_json_Message_Document(): + json_string = r'{"message_id":97,"from":{"id":10734,"first_name":"Fd","last_name":"Wd","username":"dd","is_bot":true },"chat":{"id":10,"first_name":"Fd","type":"private","last_name":"Wd","username":"dd"},"date":1435478744,"document":{"file_name":"Text File","thumbnail":{},"file_id":"BQADBQADMwIAAsYifgZ_CEh0u682xwI","file_unique_id": "AQAD_QIfa3QAAyA4BgAB","file_size":446}}' + msg = types.Message.de_json(json_string) + assert msg.document.file_name == 'Text File' + assert msg.content_type == 'document' -def test_json_suggestedpostdeclined(): - json_str = r'{"suggested_post_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "suggested"}, "comment": "declined reason"}' - result = types.SuggestedPostDeclined.de_json(json_str) - assert isinstance(result.suggested_post_message, types.Message) - assert result.comment == 'declined reason' - assert isinstance(result, types.SuggestedPostDeclined) +def test_json_Message_Photo(): + json_string = r'{"message_id":96,"from":{"id":109734,"first_name":"Fd","last_name":"Wd","username":"dd","is_bot":true },"chat":{"id":10734,"first_name":"Fd","type":"private","last_name":"dd","username":"dd"},"date":1435478191,"photo":[{"file_id":"AgADBQADIagxG8YifgYv8yLSj76i-dd","file_unique_id": "AQAD_QIfa3QAAyA4BgAB","file_size":615,"width":90,"height":67},{"file_id":"AgADBQADIagxG8YifgYv8yLSj76i-dd","file_unique_id": "AQAD_QIfa3QAAyA4BgAB","file_size":10174,"width":320,"height":240},{"file_id":"dd-A_LsTIABFNx-FUOaEa_3AABAQABAg","file_unique_id": "AQAD_QIfa3QAAyA4BgAB","file_size":53013,"width":759,"height":570}]}' + msg = types.Message.de_json(json_string) + assert len(msg.photo) == 3 + assert msg.content_type == 'photo' -def test_json_switchinlinequerychosenchat(): - json_str = r'{"query": "test", "allow_user_chats": true, "allow_bot_chats": true, "allow_group_chats": true, "allow_channel_chats": true}' - result = types.SwitchInlineQueryChosenChat.de_json(json_str) - assert result.query == 'test' - assert result.allow_user_chats == True - assert result.allow_bot_chats == True - assert result.allow_group_chats == True - assert result.allow_channel_chats == True - assert isinstance(result, types.SwitchInlineQueryChosenChat) +def test_json_Message_Video(): + json_string = r'{"message_id":101,"from":{"id":109734,"first_name":"dd","last_name":"dd","username":"dd","is_bot":true },"chat":{"id":109734,"first_name":"dd","type":"private","last_name":"dd","username":"dd"},"date":1435481960,"video":{"duration":3,"caption":"","width":360,"height":640,"thumbnail":{"file_id":"AAQFABPiYnBjkDwMAAIC","file_unique_id": "AQADTeisa3QAAz1nAAI","file_size":1597,"width":50,"height":90},"file_id":"BAADBQADNifgb_TOPEKErGoQI","file_unique_id": "AgADbgEAAn8VSFY","file_size":260699}}' + msg = types.Message.de_json(json_string) + assert msg.video + assert msg.video.duration == 3 + assert msg.video.thumbnail.width == 50 + assert msg.content_type == 'video' -def test_json_transactionpartnertelegramads(): - result = types.TransactionPartnerTelegramAds.de_json(None) - assert isinstance(result, types.TransactionPartnerTelegramAds) or result is None +def test_json_Message_Location(): + json_string = r'{"message_id":102,"from":{"id":108734,"first_name":"dd","last_name":"dd","username":"dd","is_bot":true },"chat":{"id":1089734,"first_name":"dd","type":"private","last_name":"dd","username":"dd"},"date":1535482469,"location":{"longitude":127.479471,"latitude":26.090577}}' + msg = types.Message.de_json(json_string) + assert msg.location.latitude == 26.090577 + assert msg.content_type == 'location' -def test_json_videochatstarted(): - result = types.VideoChatStarted.de_json({}) - assert isinstance(result, types.VideoChatStarted) or result is None +def test_json_UserProfilePhotos(): + json_string = r'{"total_count":1,"photos":[[{"file_id":"AgADAgADqacxG6wpRwABvEB6fpeIcKS4HAIkAATZH_SpyZjzIwdVAAIC","file_unique_id": "AQAD_QIfa3QAAyA4BgAB","file_size":6150,"width":160,"height":160},{"file_id":"AgADAgADqacxG6wpRwABvEB6fpeIcKS4HAIkAATOiTNi_YoJMghVAAIC","file_unique_id": "AQAD_QIfa3QAAyA4BgAB","file_size":13363,"width":320,"height":320},{"file_id":"AgADAgADqacxG6wpRwABvEB6fpeIcKS4HAIkAAQW4DyFv0-lhglVAAIC","file_unique_id": "AQAD_QIfa3QAAyA4BgAB","file_size":28347,"width":640,"height":640},{"file_id":"AgADAgADqacxG6wpRwABvEB6fpeIcKS4HAIkAAT50RvJCg0GQApVAAIC","file_unique_id": "AQAD_QIfa3QAAyA4BgAB","file_size":33953,"width":800,"height":800}]]}' + upp = types.UserProfilePhotos.de_json(json_string) + assert upp.photos[0][0].width == 160 + assert upp.photos[0][-1].height == 800 -def test_json_voicechatstarted(): - result = types.VoiceChatStarted.de_json({}) - assert isinstance(result, types.VoiceChatStarted) or result is None - - -def test_json_writeaccessallowed(): - result = types.WriteAccessAllowed.de_json({'from_request': True, 'web_app_name': 'TestApp', 'from_attachment_menu': False}) - assert result.from_request == True - assert result.web_app_name == 'TestApp' - assert result.from_attachment_menu == False - assert isinstance(result, types.WriteAccessAllowed) - - -def test_json_acceptedgifttypes(): - json_str = r'{"unlimited_gifts": "test", "limited_gifts": "test", "unique_gifts": "test", "premium_subscription": "test", "gifts_from_channels": "test"}' - result = types.AcceptedGiftTypes.de_json(json_str) - assert result.unlimited_gifts == 'test' - assert result.limited_gifts == 'test' - assert result.unique_gifts == 'test' - assert result.premium_subscription == 'test' - assert result.gifts_from_channels == 'test' - assert isinstance(result, types.AcceptedGiftTypes) - - -def test_json_copytextbutton(): - json_str = r'{"text": "Test"}' - result = types.CopyTextButton.de_json(json_str) - assert result.text == 'Test' - assert isinstance(result, types.CopyTextButton) - - -def test_json_dice(): - json_str = r'{"value": "test", "emoji": "😀"}' - result = types.Dice.de_json(json_str) - assert result.value == 'test' - assert result.emoji == '😀' - assert isinstance(result, types.Dice) - - -def test_json_richblocktablecell(): - json_str = r'{"align": "test", "valign": "test", "text": "Test", "is_header": true, "colspan": "test", "rowspan": "test"}' - result = types.RichBlockTableCell.de_json(json_str) - assert result.align == 'test' - assert result.valign == 'test' - assert result.text == 'Test' - assert result.is_header == True - assert result.colspan == 'test' - assert result.rowspan == 'test' - assert isinstance(result, types.RichBlockTableCell) +def test_json_contact(): + json_string = r'{"phone_number":"00011111111","first_name":"dd","last_name":"ddl","user_id":8633,"vcard":"SomeContactString"}' + contact = types.Contact.de_json(json_string) + assert contact.first_name == 'dd' + assert contact.last_name == 'ddl' -def test_json_richtextbotcommand(): - json_str = r'{"type": "bot_command", "text": "Test", "bot_command": "test"}' - result = types.RichText.de_json(json_str) - assert result.text == 'Test' - assert result.bot_command == 'test' - assert isinstance(result, types.RichTextBotCommand) +def test_json_voice(): + json_string = r'{"duration": 0,"mime_type": "audio/ogg","file_id": "AwcccccccDH1JaB7w_gyFjYQxVAg","file_unique_id": "AgADbAEAAn8VSFY","file_size": 10481}' + voice = types.Voice.de_json(json_string) + assert voice.duration == 0 + assert voice.file_size == 10481 -def test_json_richtextcashtag(): - json_str = r'{"type": "cashtag", "text": "Test", "cashtag": "test"}' - result = types.RichText.de_json(json_str) - assert result.text == 'Test' - assert result.cashtag == 'test' - assert isinstance(result, types.RichTextCashtag) +def test_json_update(): + json_string = r'{"update_id":938203,"message":{"message_id":241,"from":{"is_bot":true,"id":9734,"first_name":"Fk","last_name":"Wg","username":"nir"},"chat":{"id":1111,"first_name":"Fk","type":"private","last_name":"Wg","username":"oir"},"date":1441447009,"text":"HIHI"}}' + update = types.Update.de_json(json_string) + assert update.update_id == 938203 + assert update.message.message_id == 241 + assert update.message.from_user.id == 9734 -def test_json_richtextcustomemoji(): - json_str = r'{"type": "custom_emoji", "custom_emoji_id": "test", "alternative_text": "test"}' - result = types.RichText.de_json(json_str) - assert result.custom_emoji_id == 'test' - assert result.alternative_text == 'test' - assert isinstance(result, types.RichTextCustomEmoji) +def test_json_chat(): + json_string = r'{"id": -111111,"title": "Test Title","type": "group", "join_to_send_messages": true, "join_by_request": true}' + chat = types.Chat.de_json(json_string) + assert chat.id == -111111 + assert chat.type == 'group' + assert chat.title == 'Test Title' + assert chat.join_to_send_messages is True + assert chat.join_by_request is True + + +def test_InlineQueryResultCachedPhoto(): + iq = types.InlineQueryResultCachedPhoto('aaa', 'Fileid') + json_str = iq.to_json() + assert 'aa' in json_str + assert 'Fileid' in json_str + assert 'caption' not in json_str + + +def test_InlineQueryResultCachedPhoto_with_title(): + iq = types.InlineQueryResultCachedPhoto('aaa', 'Fileid', title='Title') + json_str = iq.to_json() + assert 'aa' in json_str + assert 'Fileid' in json_str + assert 'Title' in json_str + assert 'caption' not in json_str + + +def test_InlineQueryResultCachedPhoto_with_markup(): + markup = types.InlineKeyboardMarkup() + markup.add(types.InlineKeyboardButton("Google", url="http://www.google.com")) + markup.add(types.InlineKeyboardButton("Yahoo", url="http://www.yahoo.com")) + iq = types.InlineQueryResultCachedPhoto('aaa', 'Fileid', title='Title', reply_markup=markup) + json_str = iq.to_json() + assert 'aa' in json_str + assert 'Fileid' in json_str + assert 'Title' in json_str + assert 'caption' not in json_str + assert 'reply_markup' in json_str + + +def test_json_poll_1(): + jsonstring = r'{"message_id":2649246,"from":{"id":927266710,"is_bot":false,"first_name":"a","username":"b","language_code":"en"},"chat":{"id":1234,"first_name":"a","username":"b","type":"private"},"date":1775379138,"poll":{"id":"5373272187744556440","question":"Test","options":[{"persistent_id":"0","text":"1","voter_count":0},{"persistent_id":"1","text":"2","voter_count":0}],"total_voter_count":0,"is_closed":false,"is_anonymous":true,"allows_multiple_answers":false,"allows_revoting":false,"type":"quiz","correct_option_id":0,"correct_option_ids":[0]}}' + msg = types.Message.de_json(jsonstring) + assert msg.poll is not None + assert isinstance(msg.poll, types.Poll) + assert msg.poll.id == '5373272187744556440' + assert msg.poll.question == 'Test' + assert len(msg.poll.options) == 2 + assert msg.poll.options[0].text == '1' + assert msg.poll.options[1].text == '2' + assert msg.poll.options[0].voter_count == 0 + assert msg.poll.options[1].voter_count == 0 + assert msg.poll.options[0].persistent_id == '0' + assert msg.poll.options[1].persistent_id == '1' + assert msg.poll.total_voter_count == 0 + assert msg.poll.is_closed is False + assert msg.poll.is_anonymous is True + assert msg.poll.allows_multiple_answers is False + assert msg.poll.allows_revoting is False + assert msg.poll.type == 'quiz' + assert msg.poll.correct_option_id == 0 + assert msg.poll.correct_option_ids == [0] + + +def test_json_poll_answer(): + jsonstring = r'{"poll_id": "5895675970559410186", "option_persistent_ids": ["0"], "user": {"id": 329343347, "is_bot": false, "first_name": "Test", "username": "test_user", "last_name": "User", "language_code": "en"}, "option_ids": [1]}' + __import__('pprint').pprint(__import__('json').loads(jsonstring)) + poll_answer = types.PollAnswer.de_json(jsonstring) + assert poll_answer.poll_id == '5895675970559410186' + assert isinstance(poll_answer.user, types.User) + assert poll_answer.option_ids == [1] + + +def test_KeyboardButtonPollType(): + markup = types.ReplyKeyboardMarkup() + markup.add(types.KeyboardButton('send me a poll', request_poll=types.KeyboardButtonPollType(type='quiz'))) + json_str = markup.to_json() + assert 'request_poll' in json_str + assert 'quiz' in json_str + + +def test_json_chat_invite_link(): + json_string = r'{"invite_link":"https://t.me/joinchat/MeASP-Wi...","creator":{"id":927266710,"is_bot":false,"first_name":">_run","username":"coder2020","language_code":"ru"},"pending_join_request_count":1,"creates_join_request":true,"is_primary":false,"is_revoked":false}' + invite_link = types.ChatInviteLink.de_json(json_string) + assert invite_link.invite_link == 'https://t.me/joinchat/MeASP-Wi...' + assert isinstance(invite_link.creator, types.User) + assert not invite_link.is_primary + assert not invite_link.is_revoked + assert invite_link.expire_date is None + assert invite_link.member_limit is None + assert invite_link.name is None + assert invite_link.creator.id == 927266710 + assert invite_link.pending_join_request_count == 1 + assert invite_link.creates_join_request + + +def test_chat_member_updated(): + json_string = r'{"chat": {"id": -1234567890123, "type": "supergroup", "title": "No Real Group", "username": "NoRealGroup"}, "from": {"id": 133869498, "is_bot": false, "first_name": "Vincent"}, "date": 1624119999, "old_chat_member": {"user": {"id": 77777777, "is_bot": false, "first_name": "Pepe"}, "status": "member"}, "new_chat_member": {"user": {"id": 77777777, "is_bot": false, "first_name": "Pepe"}, "status": "left"}}' + cm_updated = types.ChatMemberUpdated.de_json(json_string) + assert cm_updated.chat.id == -1234567890123 + assert cm_updated.from_user.id == 133869498 + assert cm_updated.date == 1624119999 + assert cm_updated.old_chat_member.status == "member" + assert cm_updated.new_chat_member.status == "left" + + +def test_webhook_info(): + json_string = r'{"url": "https://example.com/webhook", "has_custom_certificate": true, "pending_update_count": 1, "last_error_date": 0, "last_error_message": "", "last_synchronization_error_date": 489309, "max_connections": 40, "allowed_updates": ["message"]}' + webhook_info = types.WebhookInfo.de_json(json_string) + print(webhook_info) + assert webhook_info.url == 'https://example.com/webhook' + assert webhook_info.has_custom_certificate is True + assert webhook_info.pending_update_count == 1 + assert webhook_info.last_error_date == 0 + assert webhook_info.last_error_message == '' + assert webhook_info.max_connections == 40 + assert webhook_info.last_synchronization_error_date == 489309 + assert webhook_info.allowed_updates == ['message'] + + +def test_sent_web_app_message(): + json_string = r'{"inline_message_id": "29430"}' + sent_web_app_message = types.SentWebAppMessage.de_json(json_string) + assert sent_web_app_message.inline_message_id == '29430' + + +def test_message_entity(): + # TODO: Add support for nesting entities + + + sample_string_1 = r'{"update_id":934522126,"message":{"message_id":1374510,"from":{"id":927266710,"is_bot":false,"first_name":">_run","username":"coder2020","language_code":"en","is_premium":true},"chat":{"id":927266710,"first_name":">_run","username":"coder2020","type":"private"},"date":1682177590,"text":"b b b","entities":[{"offset":0,"length":2,"type":"bold"},{"offset":0,"length":1,"type":"italic"},{"offset":2,"length":2,"type":"bold"},{"offset":2,"length":1,"type":"italic"},{"offset":4,"length":1,"type":"bold"},{"offset":4,"length":1,"type":"italic"}]}}' + update = types.Update.de_json(sample_string_1) + message: types.Message = update.message + assert message.html_text == "b b b" + + sample_string_2 = r'{"update_id":934522166,"message":{"message_id":1374526,"from":{"id":927266710,"is_bot":false,"first_name":">_run","username":"coder2020","language_code":"en","is_premium":true},"chat":{"id":927266710,"first_name":">_run","username":"coder2020","type":"private"},"date":1682179716,"text":"b b b","entities":[{"offset":0,"length":1,"type":"bold"},{"offset":2,"length":1,"type":"bold"},{"offset":4,"length":1,"type":"italic"}]}}' + message_2 = types.Update.de_json(sample_string_2).message + assert message_2.html_text == "b b b" + + + + sample_string_3 = r'{"update_id":934522172,"message":{"message_id":1374530,"from":{"id":927266710,"is_bot":false,"first_name":">_run","username":"coder2020","language_code":"en","is_premium":true},"chat":{"id":927266710,"first_name":">_run","username":"coder2020","type":"private"},"date":1682179968,"text":"This is a bold text with a nested italic and bold text.","entities":[{"offset":10,"length":4,"type":"bold"},{"offset":27,"length":7,"type":"italic"},{"offset":34,"length":15,"type":"bold"},{"offset":34,"length":15,"type":"italic"}]}}' + message_3 = types.Update.de_json(sample_string_3).message + assert \ + (message_3.html_text == "This is a bold text with a nested italic and bold text.") or \ + (message_3.html_text == "This is a bold text with a nested italic and bold text.") + + + sample_string_4 = r'{"update_id":934522437,"message":{"message_id":1374619,"from":{"id":927266710,"is_bot":false,"first_name":">_run","username":"coder2020","language_code":"en","is_premium":true},"chat":{"id":927266710,"first_name":">_run","username":"coder2020","type":"private"},"date":1682189507,"forward_from":{"id":927266710,"is_bot":false,"first_name":">_run","username":"coder2020","language_code":"en","is_premium":true},"forward_date":1682189124,"text":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa😋😋","entities":[{"offset":0,"length":76,"type":"bold"},{"offset":0,"length":76,"type":"italic"},{"offset":0,"length":76,"type":"underline"},{"offset":0,"length":76,"type":"strikethrough"},{"offset":76,"length":2,"type":"custom_emoji","custom_emoji_id":"5456188142006575553"},{"offset":78,"length":2,"type":"custom_emoji","custom_emoji_id":"5456188142006575553"}]}}' + message_4 = types.Update.de_json(sample_string_4).message + assert \ + (message_4.html_text == 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa😋😋') or \ + (message_4.html_text == 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa😋😋') + + + sample_string_5 = r'{"update_id":934522166,"message":{"message_id":1374526,"from":{"id":927266710,"is_bot":false,"first_name":">_run","username":"coder2020","language_code":"en","is_premium":true},"chat":{"id":927266710,"first_name":">_run","username":"coder2020","type":"private"},"date":1682179716,"text":"b b i","entities":[{"offset":0,"length":1,"type":"bold"}]}}' + message_5 = types.Update.de_json(sample_string_5).message + assert message_5.html_text == "b <b>b</b> <i>i</i>" + + + sample_string_6 = r'{"update_id":934522166,"message":{"message_id":1374526,"from":{"id":927266710,"is_bot":false,"first_name":">_run","username":"coder2020","language_code":"en","is_premium":true},"chat":{"id":927266710,"first_name":">_run","username":"coder2020","type":"private"},"date":1682179716,"text":"b i"}}' + message_6 = types.Update.de_json(sample_string_6).message + assert message_6.html_text == "<b>b</b> <i>i</i>" + + + sample_string_7 = r'{"update_id":934522167,"message":{"message_id":1374526,"from":{"id":927266710,"is_bot":false,"first_name":">_run","username":"coder2020","language_code":"en","is_premium":true},"chat":{"id":927266710,"first_name":">_run","username":"coder2020","type":"private"},"date":1682179716,"reply_to_message":{"message_id":1374510,"from":{"id":927266710,"is_bot":false,"first_name":">_run","username":"coder2020","language_code":"en"},"chat":{"id":927266710,"first_name":">_run","username":"coder2020","type":"private"},"date":1712765863,"text":"text @UserName b i s u c p #hashtag https://example.com","entities":[{"offset":5,"length":9,"type":"mention"},{"offset":15,"length":1,"type":"bold"},{"offset":17,"length":1,"type":"italic"},{"offset":19,"length":1,"type":"strikethrough"},{"offset":21,"length":1,"type":"underline"},{"offset":23,"length":1,"type":"code"},{"offset":25,"length":1,"type":"spoiler"},{"offset":27,"length":8,"type":"hashtag"},{"offset":36,"length":19,"type":"url"}],"link_preview_options":{"is_disabled":true}},"quote":{"text":"text @UserName b i s u c p #hashtag https://example.com","entities":[{"offset":15,"length":1,"type":"bold"},{"offset":17,"length":1,"type":"italic"},{"offset":19,"length":1,"type":"strikethrough"},{"offset":21,"length":1,"type":"underline"},{"offset":25,"length":1,"type":"spoiler"}],"position":0,"is_manual":true},"text":"quote reply"}}' + message_7 = types.Update.de_json(sample_string_7).message + assert message_7.quote.html_text == 'text @UserName b i s u c p #hashtag https://example.com' + + +def test_message_entity_date_time(): + entity = types.MessageEntity( + type='date_time', + offset=0, + length=10, + unix_time=1740787200, + date_time_format='short', + ) + assert entity.type == 'date_time' + assert entity.to_dict()['type'] == 'date_time' + assert entity.to_dict()['unix_time'] == 1740787200 + assert entity.to_dict()['date_time_format'] == 'short' + + +def test_message_sender_tag(): + jsonstring = r'{"message_id":1,"from":{"id":1,"first_name":"A","is_bot":false},"chat":{"id":1,"first_name":"A","type":"private"},"date":1435296025,"text":"hi","sender_tag":"blue"}' + msg = types.Message.de_json(jsonstring) + assert msg.sender_tag == 'blue' + + +def test_chat_member_member_tag(): + jsonstring = r'{"status":"member","user":{"id":1,"is_bot":false,"first_name":"A"},"tag":"alpha"}' + cm = types.ChatMember.de_json(jsonstring) + assert isinstance(cm, types.ChatMemberMember) + assert cm.tag == 'alpha' + + +def test_chat_member_restricted_tag_and_can_edit_tag(): + jsonstring = r'{"status":"restricted","user":{"id":1,"is_bot":false,"first_name":"A"},"is_member":true,"can_send_messages":true,"can_send_audios":true,"can_send_documents":true,"can_send_photos":true,"can_send_videos":true,"can_send_video_notes":true,"can_send_voice_notes":true,"can_send_polls":true,"can_send_other_messages":true,"can_add_web_page_previews":true,"can_change_info":false,"can_invite_users":false,"can_pin_messages":false,"can_manage_topics":false,"until_date":0,"tag":"beta","can_edit_tag":true}' + cm = types.ChatMember.de_json(jsonstring) + assert isinstance(cm, types.ChatMemberRestricted) + assert cm.tag == 'beta' + assert cm.can_edit_tag is True -def test_json_richtexthashtag(): - json_str = r'{"type": "hashtag", "text": "Test", "hashtag": "test"}' - result = types.RichText.de_json(json_str) - assert result.text == 'Test' - assert result.hashtag == 'test' - assert isinstance(result, types.RichTextHashtag) + +def test_chat_member_administrator_can_manage_tags(): + jsonstring = r'{"status":"administrator","user":{"id":1,"is_bot":false,"first_name":"A"},"can_be_edited":true,"is_anonymous":false,"can_manage_chat":true,"can_delete_messages":true,"can_manage_video_chats":true,"can_restrict_members":true,"can_promote_members":true,"can_change_info":true,"can_invite_users":true,"can_post_stories":true,"can_edit_stories":true,"can_delete_stories":true,"can_manage_tags":true}' + cm = types.ChatMember.de_json(jsonstring) + assert isinstance(cm, types.ChatMemberAdministrator) + assert cm.can_manage_tags is True -def test_json_richtextmathematicalexpression(): - json_str = r'{"type": "mathematical_expression", "expression": "test"}' - result = types.RichText.de_json(json_str) - assert result.expression == 'test' - assert isinstance(result, types.RichTextMathematicalExpression) +def test_chat_permissions_can_edit_tag(): + permissions = types.ChatPermissions(can_send_messages=True, can_edit_tag=True) + assert permissions.to_dict()['can_edit_tag'] is True -def test_json_richtextmention(): - json_str = r'{"type": "mention", "text": "Test", "username": "test"}' - result = types.RichText.de_json(json_str) - assert result.text == 'Test' - assert result.username == 'test' - assert isinstance(result, types.RichTextMention) - - -def test_json_richtextreference(): - json_str = r'{"type": "reference", "text": "Test", "name": "Test"}' - result = types.RichText.de_json(json_str) - assert result.text == 'Test' - assert result.name == 'Test' - assert isinstance(result, types.RichTextReference) - - -def test_json_richtextreferencelink(): - json_str = r'{"type": "reference_link", "text": "Test", "reference_name": "test"}' - result = types.RichText.de_json(json_str) - assert result.text == 'Test' - assert result.reference_name == 'test' - assert isinstance(result, types.RichTextReferenceLink) - - -def test_json_suggestedpostprice(): - json_str = r'{"currency": "en", "amount": 1}' - result = types.SuggestedPostPrice.de_json(json_str) - assert result.currency == 'en' - assert result.amount == 1 - assert isinstance(result, types.SuggestedPostPrice) - - -def test_json_affiliateinfo(): - json_str = r'{"commission_per_mille": 1000, "amount": 100, "affiliate_user": {"id": 1, "is_bot": false, "first_name": "User"}, "affiliate_chat": {"id": -1001234567890, "type": "channel", "title": "Channel"}, "nanostar_amount": 10000000}' - result = types.AffiliateInfo.de_json(json_str) - assert result.commission_per_mille == 1000 - assert result.amount == 100 - assert isinstance(result.affiliate_user, types.User) - assert isinstance(result.affiliate_chat, types.Chat) - assert result.nanostar_amount == 10000000 - assert isinstance(result, types.AffiliateInfo) - - -def test_json_backgroundfill(): - # BackgroundFill is abstract - test BackgroundFillSolid directly - json_str = r'{"type": "solid", "color": 123456}' - result = types.BackgroundFillSolid.de_json(json_str) - assert isinstance(result, types.BackgroundFillSolid) - - -def test_json_backgroundfillfreeformgradient(): - json_str = r'{"type": "freeform_gradient", "colors": [123456, 654321, 111222]}' - result = types.BackgroundFillFreeformGradient.de_json(json_str) - assert result.type == 'freeform_gradient' - assert isinstance(result.colors, list) - assert isinstance(result, types.BackgroundFillFreeformGradient) - - -def test_json_backgroundfillgradient(): - json_str = r'{"type": "gradient", "top_color": 123456, "bottom_color": 654321, "rotation_angle": 180}' - result = types.BackgroundFillGradient.de_json(json_str) - assert result.type == 'gradient' - assert result.top_color == 123456 - assert result.bottom_color == 654321 - assert result.rotation_angle == 180 - assert isinstance(result, types.BackgroundFillGradient) - - -def test_json_backgroundfillsolid(): - json_str = r'{"type": "solid", "color": 123456}' - result = types.BackgroundFillSolid.de_json(json_str) - assert result.type == 'solid' - assert result.color == 123456 - assert isinstance(result, types.BackgroundFillSolid) - - -def test_json_backgroundtype(): - # BackgroundType is abstract - test BackgroundTypeFill directly - json_str = r'{"type": "fill", "fill": {"type": "solid", "color": 123456}, "dark_theme_dimming": 0}' - result = types.BackgroundTypeFill.de_json(json_str) - assert isinstance(result, types.BackgroundTypeFill) - - -def test_json_backgroundtypechattheme(): - json_str = r'{"type": "fill", "theme_name": "test"}' - result = types.BackgroundTypeChatTheme.de_json(json_str) - assert result.type == 'fill' - assert result.theme_name == 'test' - assert isinstance(result, types.BackgroundTypeChatTheme) - - -def test_json_backgroundtypefill(): - json_str = r'{"type": "solid", "fill": {"type": "solid", "color": 123456}, "dark_theme_dimming": 0}' - result = types.BackgroundTypeFill.de_json(json_str) - assert result.type == 'solid' - assert isinstance(result.fill, types.BackgroundFill) - assert result.dark_theme_dimming == 0 - assert isinstance(result, types.BackgroundTypeFill) - - -def test_json_backgroundtypepattern(): - json_str = r'{"type": "pattern", "document": {"file_id": "doc", "file_unique_id": "docu", "mime_type": "application/pdf", "file_name": "test.pdf"}, "fill": {"type": "solid", "color": 123456}, "intensity": 0, "is_inverted": true, "is_moving": true}' - result = types.BackgroundTypePattern.de_json(json_str) - assert result.type == 'pattern' - assert isinstance(result.document, types.Document) - assert isinstance(result.fill, dict) or result.fill is None - assert result.intensity == 0 - assert result.is_inverted == True - assert result.is_moving == True - assert isinstance(result, types.BackgroundTypePattern) - - -def test_json_backgroundtypewallpaper(): - json_str = r'{"type": "wallpaper", "document": {"file_id": "doc", "file_unique_id": "docu", "mime_type": "application/pdf", "file_name": "test.pdf"}, "dark_theme_dimming": 0, "is_blurred": true, "is_moving": true}' - result = types.BackgroundTypeWallpaper.de_json(json_str) - assert result.type == 'wallpaper' - assert isinstance(result.document, types.Document) - assert result.dark_theme_dimming == 0 - assert result.is_blurred == True - assert result.is_moving == True - assert isinstance(result, types.BackgroundTypeWallpaper) - - -def test_json_birthdate(): - json_str = r'{"day": "test", "month": "test", "year": 1990}' - result = types.Birthdate.de_json(json_str) - assert result.day == 'test' - assert result.month == 'test' - assert result.year == 1990 - assert isinstance(result, types.Birthdate) - - -def test_json_botaccesssettings(): - json_str = r'{"is_access_restricted": false, "added_users": [{"id": 1, "is_bot": false, "first_name": "Test"}, {"id": 2, "is_bot": false, "first_name": "User2"}]}' - result = types.BotAccessSettings.de_json(json_str) - assert result.is_access_restricted == False - assert isinstance(result.added_users, list) - assert len(result.added_users) == 2 - assert isinstance(result.added_users[0], types.User) - assert result.added_users[0].id == 1 - assert isinstance(result, types.BotAccessSettings) - - -def test_json_botsubscriptionupdated(): - json_str = r'{"user": {"id": 1, "is_bot": false, "first_name": "Test"}, "invoice_payload": "test_payload", "state": "default"}' - result = types.BotSubscriptionUpdated.de_json(json_str) - assert isinstance(result.user, types.User) - assert result.invoice_payload == 'test_payload' - assert result.state == 'default' - assert isinstance(result, types.BotSubscriptionUpdated) - - -def test_json_businessconnection(): - json_str = r'{"id": "1", "user": {"id": 1, "is_bot": false, "first_name": "Test"}, "user_chat_id": 1, "date": 1682189507, "is_enabled": false, "rights": {"can_reply": true, "can_read_messages": true, "can_delete_outgoing_messages": false, "can_delete_all_messages": false, "can_edit_name": true, "can_edit_bio": false, "can_edit_profile_photo": true, "can_edit_username": false, "can_change_gift_settings": true, "can_view_gifts_and_stars": false, "can_convert_gifts_to_stars": true, "can_transfer_and_upgrade_gifts": false, "can_transfer_stars": true, "can_manage_stories": false}}' - result = types.BusinessConnection.de_json(json_str) - assert result.id == '1' - assert isinstance(result.user, types.User) - assert result.user_chat_id == 1 - assert result.date == 1682189507 - assert result.is_enabled == False - assert isinstance(result.rights, types.BusinessBotRights) - assert result.rights.can_reply == True - assert result.rights.can_read_messages == True - assert result.rights.can_delete_outgoing_messages == False - assert result.rights.can_delete_all_messages == False - assert result.rights.can_edit_name == True - assert result.rights.can_edit_bio == False - assert result.rights.can_edit_profile_photo == True - assert result.rights.can_edit_username == False - assert result.rights.can_change_gift_settings == True - assert result.rights.can_view_gifts_and_stars == False - assert result.rights.can_convert_gifts_to_stars == True - assert result.rights.can_transfer_and_upgrade_gifts == False - assert result.rights.can_transfer_stars == True - assert result.rights.can_manage_stories == False - assert isinstance(result, types.BusinessConnection) - - -def test_json_businesslocation(): - json_str = r'{"address": "NY", "location": {"latitude": 50.45, "longitude": 30.52, "horizontal_accuracy": 1.5}}' - result = types.BusinessLocation.de_json(json_str) - assert result.address == 'NY' - assert isinstance(result.location, types.Location) - assert result.location.latitude == 50.45 - assert result.location.longitude == 30.52 - assert result.location.horizontal_accuracy == 1.5 - assert isinstance(result, types.BusinessLocation) - - -def test_json_businessmessagesdeleted(): - json_str = r'{"business_connection_id": 1, "chat": {"id": 1, "type": "private", "title": "Test"}, "message_ids": "test"}' - result = types.BusinessMessagesDeleted.de_json(json_str) - assert result.business_connection_id == 1 - assert isinstance(result.chat, types.Chat) - assert result.message_ids == 'test' - assert isinstance(result, types.BusinessMessagesDeleted) - - -def test_json_businessopeninghours(): - json_str = r'{"time_zone_name": "test", "opening_hours": [{"opening_minute": 0, "closing_minute": 60}]}' - result = types.BusinessOpeningHours.de_json(json_str) - assert result.time_zone_name == 'test' - assert isinstance(result.opening_hours, list) - assert isinstance(result, types.BusinessOpeningHours) - - -def test_json_businessopeninghoursinterval(): - json_str = r'{"opening_minute": 0, "closing_minute": 60}' - result = types.BusinessOpeningHoursInterval.de_json(json_str) - assert result.opening_minute == 0 - assert result.closing_minute == 60 - assert isinstance(result, types.BusinessOpeningHoursInterval) - - -def test_json_callbackquery(): - # json_string is internal field, not covered (like Message.options/json_string) - json_str = r'{"id": "cq1", "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "data": "test", "chat_instance": "ci1", "message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "Hello"}, "inline_message_id": "im1", "game_short_name": "game"}' - result = types.CallbackQuery.de_json(json_str) - assert result.id == 'cq1' - assert isinstance(result.from_user, types.User) - assert result.data == 'test' - assert result.chat_instance == 'ci1' - assert isinstance(result.message, types.Message) - assert result.inline_message_id == 'im1' - assert result.game_short_name == 'game' - assert isinstance(result, types.CallbackQuery) - - -def test_json_chatbackground(): - json_str = r'{"type": {"type": "fill", "fill": {"type": "solid", "color": 123456}, "dark_theme_dimming": 0}}' - result = types.ChatBackground.de_json(json_str) - assert isinstance(result.type, types.BackgroundTypeFill) or isinstance(result.type, dict) - assert isinstance(result, types.ChatBackground) - assert hasattr(result, 'type') - - -def test_json_chatboostadded(): - json_str = r'{"boost_count": "test"}' - result = types.ChatBoostAdded.de_json(json_str) - assert result.boost_count == 'test' - assert isinstance(result, types.ChatBoostAdded) - - -def test_json_chatboostremoved(): - json_str = r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "boost_id": 1, "remove_date": 1682189507, "source": {"source": "premium", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}}' - result = types.ChatBoostRemoved.de_json(json_str) - assert isinstance(result.chat, types.Chat) - assert result.boost_id == 1 - assert result.remove_date == 1682189507 - assert isinstance(result.source, types.ChatBoostSource) - assert isinstance(result, types.ChatBoostRemoved) - - -def test_json_chatboostsource(): - # ChatBoostSource is abstract - test ChatBoostSourcePremium directly - json_str = r'{"source": "premium", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}' - result = types.ChatBoostSourcePremium.de_json(json_str) - assert isinstance(result, types.ChatBoostSourcePremium) - - -def test_json_chatboostsourcegiftcode(): - json_str = r'{"source": "gift_code", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}' - result = types.ChatBoostSourceGiftCode.de_json(json_str) - assert result.source == 'gift_code' - assert isinstance(result.user, types.User) - assert isinstance(result, types.ChatBoostSourceGiftCode) - - -def test_json_chatboostsourcegiveaway(): - json_str = r'{"source": "giveaway", "giveaway_message_id": 1, "user": {"id": 1, "is_bot": false, "first_name": "Test"}, "is_unclaimed": false, "prize_star_count": 100}' - result = types.ChatBoostSourceGiveaway.de_json(json_str) - assert result.source == 'giveaway' - assert result.giveaway_message_id == 1 - assert isinstance(result.user, types.User) - assert result.is_unclaimed == False - assert result.prize_star_count == 100 - assert isinstance(result, types.ChatBoostSourceGiveaway) - - -def test_json_chatboostsourcepremium(): - json_str = r'{"source": "premium", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}' - result = types.ChatBoostSourcePremium.de_json(json_str) - assert result.source == 'premium' - assert isinstance(result.user, types.User) - assert isinstance(result, types.ChatBoostSourcePremium) - - -def test_json_chatboostupdated(): - json_str = r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "boost": {"boost_item_id": "b1", "add_date": 1682189507, "expiration_date": 1682275907}}' - result = types.ChatBoostUpdated.de_json(json_str) - assert isinstance(result.chat, types.Chat) - assert isinstance(result.boost, types.ChatBoost) - assert isinstance(result.boost.boost_id, str) or result.boost.boost_id is None - assert isinstance(result.boost.add_date, int) - assert isinstance(result.boost.expiration_date, int) - assert isinstance(result, types.ChatBoostUpdated) - - -def test_json_chatjoinrequest(): - json_str = r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "user_chat_id": 1, "date": 1682189507, "bio": "Hello", "invite_link": {"invite_link": "https://t.me/joinchat/ABC", "creator": {"id": 1, "is_bot": false, "first_name": "Test"}, "is_primary": true, "is_revoked": false, "creates_join_request": false}, "query_id": "query123"}' - result = types.ChatJoinRequest.de_json(json_str) - assert isinstance(result.chat, types.Chat) - assert isinstance(result.from_user, types.User) - assert result.from_user.id == 1 - assert result.from_user.first_name == 'Test' - assert result.user_chat_id == 1 - assert result.date == 1682189507 - assert result.bio == 'Hello' - assert isinstance(result.invite_link, types.ChatInviteLink) - assert result.query_id == 'query123' - assert isinstance(result, types.ChatJoinRequest) - - -def test_json_chatfullinfo(): - json_str = r'{"id": 1, "type": "private", "title": "Test Chat", "username": "testchat", "first_name": "John", "last_name": "Doe", "photo": {"small_file_id": "s", "small_file_unique_id": "su", "big_file_id": "b", "big_file_unique_id": "bu"}, "bio": "bio text", "has_private_forwards": true, "description": "desc", "pinned_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}}, "permissions": {"can_send_messages": true, "can_send_audios": true, "can_send_documents": true, "can_send_photos": true, "can_send_videos": true, "can_send_video_notes": true, "can_send_voice_notes": true, "can_send_polls": true, "can_send_other_messages": true, "can_add_web_page_previews": true, "can_change_info": true, "can_invite_users": true, "can_pin_messages": true, "can_manage_topics": true}, "slow_mode_delay": 30, "message_auto_delete_time": 86400, "has_protected_content": true, "sticker_set_name": "sticker_set", "can_set_sticker_set": false, "linked_chat_id": 2, "location": {"chat": {"id": 1, "type": "supergroup", "title": "Loc"}, "location": {"latitude": 50.45, "longitude": 30.52}, "address": "Main St"}, "join_to_send_messages": false, "join_by_request": true, "has_restricted_voice_and_video_messages": false, "is_forum": true, "max_reaction_count": 10, "active_usernames": ["test"], "emoji_status_custom_emoji_id": "custom_emoji", "has_hidden_members": false, "has_aggressive_anti_spam_enabled": false, "emoji_status_expiration_date": 1682275907, "available_reactions": ["emoji", "custom_emoji"], "accent_color_id": 1, "background_custom_emoji_id": "bg_emoji", "profile_accent_color_id": 2, "profile_background_custom_emoji_id": "profile_bg", "has_visible_history": true, "unrestrict_boost_count": 5, "custom_emoji_sticker_set_name": "custom_stickers", "personal_chat": {"id": 3, "type": "private", "title": "Personal"}, "birthdate": {"day": "15", "month": "6"}, "can_send_paid_media": true, "is_direct_messages": true, "parent_chat": {"id": 4, "type": "supergroup", "title": "Parent"}, "rating": {"level": "test", "rating": "test", "current_level_rating": "test"}, "paid_message_star_count": 5, "invite_link": "https://t.me/joinchat/ABC", "business_intro": {"title": "B", "description": "D"}, "business_location": {"address": "NY", "has_active_address": true}, "business_opening_hours": {"time_zone_name": "UTC", "opening_hours": [{"opening_minute": 540, "closing_minute": 1020, "day_of_week": 1, "is_recurring": true}]}, "accepted_gift_types": {"unlimited_gifts": false, "limited_gifts": false, "unique_gifts": true, "premium_subscription": false, "gifts_from_channels": false}, "first_profile_audio": {"file_id": "fa1", "file_unique_id": "fa1u", "duration": 30, "mime_type": "audio/ogg"}, "unique_gift_colors": {"model_custom_emoji_id": 1, "symbol_custom_emoji_id": 1, "light_theme_main_color": 333333, "light_theme_other_colors": [444444], "dark_theme_main_color": 555555, "dark_theme_other_colors": [666666]}, "guard_bot": {"id": 2, "is_bot": true, "first_name": "GuardBot"}, "community": {"id": 5, "name": "Community"}}' - result = types.ChatFullInfo.de_json(json_str) - assert result.id == 1 - assert result.type == 'private' - assert result.title == 'Test Chat' - assert result.username == 'testchat' - assert result.first_name == 'John' - assert result.last_name == 'Doe' - assert isinstance(result.photo, types.ChatPhoto) - assert result.bio == 'bio text' - assert result.has_private_forwards == True - assert result.description == 'desc' - assert result.invite_link == "https://t.me/joinchat/ABC" - assert isinstance(result.pinned_message, types.Message) - assert isinstance(result.permissions, types.ChatPermissions) - assert result.slow_mode_delay == 30 - assert result.message_auto_delete_time == 86400 - assert result.has_protected_content == True - assert result.sticker_set_name == 'sticker_set' - assert result.can_set_sticker_set == False - assert result.linked_chat_id == 2 - assert isinstance(result.location, types.ChatLocation) - assert result.join_to_send_messages == False - assert result.join_by_request == True - assert result.has_restricted_voice_and_video_messages == False - assert result.is_forum == True - assert result.max_reaction_count == 10 - assert result.active_usernames == ['test'] - assert result.emoji_status_custom_emoji_id == 'custom_emoji' - assert result.has_hidden_members == False - assert result.has_aggressive_anti_spam_enabled == False - assert result.emoji_status_expiration_date == 1682275907 - assert isinstance(result.available_reactions, list) - assert result.accent_color_id == 1 - assert result.background_custom_emoji_id == 'bg_emoji' - assert result.profile_accent_color_id == 2 - assert result.profile_background_custom_emoji_id == 'profile_bg' - assert result.has_visible_history == True - assert result.unrestrict_boost_count == 5 - assert result.custom_emoji_sticker_set_name == 'custom_stickers' - assert isinstance(result.business_intro, types.BusinessIntro) - assert isinstance(result.business_location, types.BusinessLocation) - assert isinstance(result.business_opening_hours, types.BusinessOpeningHours) - assert isinstance(result.personal_chat, types.Chat) - assert isinstance(result.birthdate, types.Birthdate) - assert result.can_send_paid_media == True - assert isinstance(result.accepted_gift_types, types.AcceptedGiftTypes) - assert result.is_direct_messages == True - assert isinstance(result.parent_chat, types.Chat) - assert isinstance(result.rating, types.UserRating) - assert result.paid_message_star_count == 5 - assert isinstance(result.unique_gift_colors, types.UniqueGiftColors) - assert isinstance(result.first_profile_audio, types.Audio) - assert isinstance(result.guard_bot, types.User) - assert isinstance(result.community, types.Community) - assert isinstance(result, types.ChatFullInfo) - - -def test_json_chatmember(): - # ChatMember is abstract - test ChatMemberMember directly - json_str = r'{"status": "member", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}' - result = types.ChatMemberMember.de_json(json_str) - assert isinstance(result.user, types.User) - assert result.status == 'member' - assert isinstance(result, types.ChatMemberMember) - - -def test_json_chatmemberupdated(): - json_str = r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "date": 1682189507, "old_chat_member": {"user": {"id": 1, "is_bot": false, "first_name": "Test"}, "status": "member"}, "new_chat_member": {"user": {"id": 1, "is_bot": false, "first_name": "Test"}, "status": "member"}, "via_join_request": true, "via_chat_folder_invite_link": true, "invite_link": {"invite_link": "https://t.me/joinchat/ABC", "creator": {"id": 1, "is_bot": false, "first_name": "Test"}, "creates_join_request": false, "is_primary": true, "is_revoked": false}}' - result = types.ChatMemberUpdated.de_json(json_str) - assert isinstance(result.chat, types.Chat) - assert isinstance(result.from_user, types.User) - assert result.date == 1682189507 - assert isinstance(result.old_chat_member, types.ChatMember) - assert isinstance(result.new_chat_member, types.ChatMember) - assert isinstance(result.invite_link, types.ChatInviteLink) - assert result.invite_link.invite_link == 'https://t.me/joinchat/ABC' - assert isinstance(result.invite_link.creator, types.User) - assert result.invite_link.creates_join_request == False - assert result.invite_link.is_primary == True - assert result.invite_link.is_revoked == False - assert result.via_join_request == True - assert result.via_chat_folder_invite_link == True - assert isinstance(result, types.ChatMemberUpdated) - - -def test_json_chatownerchanged(): - json_str = r'{"new_owner": {"id": 1, "is_bot": false, "first_name": "Test"}}' - result = types.ChatOwnerChanged.de_json(json_str) - assert isinstance(result.new_owner, types.User) - assert isinstance(result, types.ChatOwnerChanged) - - -def test_json_chatphoto(): - json_str = r'{"small_file_id": 1, "small_file_unique_id": 1, "big_file_id": 1, "big_file_unique_id": 1}' - result = types.ChatPhoto.de_json(json_str) - assert result.small_file_id == 1 - assert result.small_file_unique_id == 1 - assert result.big_file_id == 1 - assert result.big_file_unique_id == 1 - assert isinstance(result, types.ChatPhoto) - - -def test_json_checklist(): - json_str = r'{"title": "test", "tasks": [{"id": 1, "text": "test", "is_checked": false}], "others_can_add_tasks": true, "others_can_mark_tasks_as_done": true, "title_entities": [{"type": "bold", "offset": 0, "length": 4}]}' - result = types.Checklist.de_json(json_str) - assert result.title == 'test' - assert isinstance(result.tasks, list) - assert isinstance(result.title_entities, list) - assert result.others_can_add_tasks == True - assert result.others_can_mark_tasks_as_done == True - assert isinstance(result, types.Checklist) - - -def test_json_checklisttask(): - json_str = r'{"id": 1, "text": {"type": "bold", "text": "Task text"}, "text_entities": [{"type": "bold", "offset": 0, "length": 9}], "completed_by_user": {"id": 1, "is_bot": false, "first_name": "User"}, "completed_by_chat": {"id": 1, "type": "private"}, "completion_date": 1682189507}' - result = types.ChecklistTask.de_json(json_str) - assert result.id == 1 - assert result.text == {"type": "bold", "text": "Task text"} - assert isinstance(result.text_entities, list) - assert isinstance(result.completed_by_user, types.User) - assert isinstance(result.completed_by_chat, types.Chat) - assert result.completion_date == 1682189507 - assert isinstance(result, types.ChecklistTask) - - -def test_json_checklisttasksadded(): - json_str = r'{"tasks": [{"id": "t1", "text": "task"}], "checklist_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "checklist"}}' - result = types.ChecklistTasksAdded.de_json(json_str) - assert isinstance(result.tasks, list) - assert isinstance(result.checklist_message, types.Message) - assert isinstance(result, types.ChecklistTasksAdded) - - -def test_json_choseninlineresult(): - json_str = r'{"result_id": "res1", "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "query": "test", "location": {"latitude": 50.45, "longitude": 30.52, "horizontal_accuracy": 1.5, "live_period": 3600}, "inline_message_id": "im1"}' - result = types.ChosenInlineResult.de_json(json_str) - assert result.result_id == 'res1' - assert isinstance(result.from_user, types.User) - assert result.query == 'test' - assert isinstance(result.location, types.Location) - assert result.inline_message_id == 'im1' - assert isinstance(result, types.ChosenInlineResult) - - -def test_json_community(): - json_str = r'{"id": 1, "name": "test"}' - result = types.Community.de_json(json_str) - assert result.id == 1 - assert result.name == 'test' - assert isinstance(result, types.Community) - - -def test_json_directmessagepricechanged(): - json_str = r'{"are_direct_messages_enabled": true, "direct_message_star_count": 5}' - result = types.DirectMessagePriceChanged.de_json(json_str) - assert result.are_direct_messages_enabled == True - assert result.direct_message_star_count == 5 - assert isinstance(result, types.DirectMessagePriceChanged) - - -def test_json_directmessagestopic(): - json_str = r'{"topic_id": 1, "user": {"id": 1, "is_bot": false, "first_name": "Test"}}' - result = types.DirectMessagesTopic.de_json(json_str) - assert result.topic_id == 1 - assert isinstance(result.user, types.User) - assert result.user.id == 1 - assert result.user.first_name == 'Test' - assert isinstance(result, types.DirectMessagesTopic) - - -def test_json_externalreplyinfo(): - json_str = r'{"origin": {"type": "user", "date": 1682189507, "sender_user": {"id": 1, "is_bot": false, "first_name": "Test"}}, "chat": {"id": 1, "type": "private"}, "message_id": 42, "link_preview_options": {"url": "https://example.com", "shows_above_caption": true, "enhanced_smileys": true, "prefer_large_media": true}, "animation": {"file_id": "anim", "file_unique_id": "aniu", "width": 100, "height": 100, "duration": 10}, "audio": {"file_id": "au1", "file_unique_id": "au1u", "duration": 30}, "document": {"file_id": "doc1", "file_unique_id": "doc1u", "file_name": "test.pdf"}, "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}], "sticker": {"file_id": "st1", "file_unique_id": "st1u", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "story": {"chat": {"id": 1, "type": "private"}, "id": 1}, "video": {"file_id": "v1", "file_unique_id": "v1u", "width": 640, "height": 480, "duration": 30}, "video_note": {"file_id": "vn1", "file_unique_id": "vn1u", "duration": 10, "length": 512}, "voice": {"file_id": "vo1", "file_unique_id": "vo1u", "duration": 10}, "has_media_spoiler": true, "contact": {"phone_number": "+123", "first_name": "John"}, "dice": {"emoji": "🎲", "value": 5}, "game": {"id": "g1", "title": "Game", "description": "Test", "text": "Play", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}, "giveaway": {"chats": [{"id": 1, "type": "private"}], "winners_selection_date": 1682189507, "winner_count": 1, "only_new_members": false, "has_public_winners": false, "prize_description": "Prize", "premium_subscription_month_count": 0, "prize_star_count": 0}, "giveaway_winners": {"chat": {"id": 1, "type": "private"}, "giveaway_message_id": 1, "winners_selection_date": 1682189507, "winner_count": 1, "winners": [{"id": 1, "is_bot": false, "first_name": "Test"}], "additional_chat_count": 0, "premium_subscription_month_count": 0, "unclaimed_prize_count": 0, "only_new_members": false, "was_refunded": false, "prize_description": "", "prize_star_count": 0}, "invoice": {"title": "Test", "description": "Desc", "start_parameter": "sp", "currency": "USD", "total_amount": 100, "invoice_payload": "payload", "shipping_option_id": "opt", "order_info": {"user_name": "User", "user_phone": "+123", "shipping_address": {"country_code": "US", "state": "CA", "city": "SJ", "street_line1": "123", "street_line2": "", "post_code": "95113"}}, "telegram_payment_charge_id": "chg1", "provider_payment_charge_id": "chg2"}, "location": {"latitude": 50.45, "longitude": 30.52}, "poll": {"id": "p1", "question": "test question", "options": [{"text": "Opt1", "persistent_id": "opt1"}], "type": "quiz"}, "venue": {"location": {"latitude": 50.45, "longitude": 30.52}, "title": "Place", "address": "Addr"}, "paid_media": {"star_count": 10, "paid_media": [{"type": "photo", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}]}, "live_photo": {"file_id": "lp1", "file_unique_id": "lp1u", "width": 100, "height": 100, "duration": 5}, "checklist": {"title": "Check", "tasks": [{"id": "t1", "text": "Task1", "status": "pending"}]}}' - result = types.ExternalReplyInfo.de_json(json_str) - assert isinstance(result.origin, types.MessageOrigin) - assert isinstance(result.chat, types.Chat) - assert result.message_id == 42 - assert isinstance(result.link_preview_options, types.LinkPreviewOptions) - assert isinstance(result.animation, types.Animation) - assert isinstance(result.audio, types.Audio) - assert isinstance(result.document, types.Document) - assert isinstance(result.photo, list) - assert isinstance(result.sticker, types.Sticker) - assert isinstance(result.story, types.Story) - assert isinstance(result.video, types.Video) - assert isinstance(result.video_note, types.VideoNote) - assert isinstance(result.voice, types.Voice) - assert result.has_media_spoiler == True - assert isinstance(result.contact, types.Contact) - assert isinstance(result.dice, types.Dice) - assert isinstance(result.game, types.Game) - assert isinstance(result.giveaway, types.Giveaway) - assert isinstance(result.giveaway.chats, list) - assert result.giveaway.winner_count == 1 - assert isinstance(result.giveaway_winners, types.GiveawayWinners) - assert isinstance(result.invoice, types.Invoice) - assert isinstance(result.location, types.Location) - assert isinstance(result.poll, types.Poll) - assert result.poll.id == 'p1' - assert result.poll.question == 'test question' - assert isinstance(result.poll.options, list) - assert result.poll.type == 'quiz' - assert isinstance(result.venue, types.Venue) - assert isinstance(result.paid_media, types.PaidMediaInfo) - assert isinstance(result.live_photo, types.LivePhoto) - assert isinstance(result.checklist, types.Checklist) - assert isinstance(result, types.ExternalReplyInfo) - - -def test_json_file(): - json_str = r'{"file_id": "test_file_id", "file_unique_id": "test_unique_id", "file_size": 1024, "file_path": "docs/test.pdf"}' - result = types.File.de_json(json_str) - assert result.file_id == 'test_file_id' - assert result.file_unique_id == 'test_unique_id' - assert result.file_size == 1024 - assert result.file_path == 'docs/test.pdf' - assert isinstance(result, types.File) - - -def test_json_forumtopiccreated(): - json_str = r'{"name": "test", "icon_color": 4294967295, "icon_custom_emoji_id": "custom_emoji", "is_name_implicit": true}' - result = types.ForumTopicCreated.de_json(json_str) - assert result.name == 'test' - assert result.icon_color == 4294967295 - assert result.icon_custom_emoji_id == 'custom_emoji' - assert result.is_name_implicit == True - assert isinstance(result, types.ForumTopicCreated) - - -def test_json_game(): - json_str = r'{"id": "1", "title": "test", "description": "test", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}], "text": "game text", "animation": {"file_id": "anim", "file_unique_id": "aniu", "width": 100, "height": 100, "duration": 10}, "text_entities": [{"type": "bold", "offset": 0, "length": 4}]}' - result = types.Game.de_json(json_str) - assert result.title == 'test' - assert result.description == 'test' - assert isinstance(result.photo, list) - assert result.text == 'game text' - assert isinstance(result.text_entities, list) - assert isinstance(result.animation, types.Animation) - assert isinstance(result, types.Game) - - -def test_json_gamehighscore(): - json_str = r'{"position": 0, "user": {"id": 1, "is_bot": false, "first_name": "Test"}, "score": 1}' - result = types.GameHighScore.de_json(json_str) - assert result.position == 0 - assert isinstance(result.user, types.User) - assert result.score == 1 - assert isinstance(result, types.GameHighScore) - - -def test_json_giveaway(): - json_str = r'{"chats": [{"id": 1, "type": "private", "title": "Test"}], "winners_selection_date": 1682189507, "winner_count": 1, "only_new_members": true, "has_public_winners": false, "prize_description": "Prize", "country_codes": ["US", "GB"], "premium_subscription_month_count": 3, "prize_star_count": 100}' - result = types.Giveaway.de_json(json_str) - assert isinstance(result.chats, list) - assert result.winners_selection_date == 1682189507 - assert result.winner_count == 1 - assert result.only_new_members == True - assert result.has_public_winners == False - assert result.prize_description == 'Prize' - assert isinstance(result.country_codes, list) - assert result.premium_subscription_month_count == 3 - assert result.prize_star_count == 100 - assert isinstance(result, types.Giveaway) - - -def test_json_giveawaycompleted(): - json_str = r'{"winner_count": 1, "unclaimed_prize_count": 5, "giveaway_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "giveaway"}, "is_star_giveaway": true}' - result = types.GiveawayCompleted.de_json(json_str) - assert result.winner_count == 1 - assert result.unclaimed_prize_count == 5 - assert isinstance(result.giveaway_message, types.Message) - assert result.is_star_giveaway == True - assert isinstance(result, types.GiveawayCompleted) - - -def test_json_giveawaywinners(): - json_str = r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "giveaway_message_id": 1, "winners_selection_date": 1682189507, "winner_count": 1, "winners": [{"id": 1, "is_bot": false, "first_name": "Test"}], "additional_chat_count": 5, "premium_subscription_month_count": 3, "unclaimed_prize_count": 10, "only_new_members": true, "was_refunded": false, "prize_description": "Prize desc", "prize_star_count": 100}' - result = types.GiveawayWinners.de_json(json_str) - assert isinstance(result.chat, types.Chat) - assert result.giveaway_message_id == 1 - assert result.winners_selection_date == 1682189507 - assert result.winner_count == 1 - assert isinstance(result.winners, list) - assert result.additional_chat_count == 5 - assert result.premium_subscription_month_count == 3 - assert result.unclaimed_prize_count == 10 - assert result.only_new_members == True - assert result.was_refunded == False - assert result.prize_description == 'Prize desc' - assert result.prize_star_count == 100 - assert isinstance(result, types.GiveawayWinners) - - -def test_json_groupchat(): - json_str = r'{"id": 1, "title": "test"}' - result = types.GroupChat.de_json(json_str) - assert result.id == 1 - assert result.title == 'test' - assert isinstance(result, types.GroupChat) - - -def test_json_inaccessiblemessage(): - json_str = r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "message_id": 1, "date": 1682189507}' - result = types.InaccessibleMessage.de_json(json_str) - assert isinstance(result.chat, types.Chat) - assert result.message_id == 1 - assert result.date == 1682189507 - assert isinstance(result, types.InaccessibleMessage) - - -def test_json_inlinequery(): - json_str = r'{"id": "iq1", "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "query": "test", "offset": "off1", "chat_type": "private", "location": {"latitude": 50.45, "longitude": 30.52, "horizontal_accuracy": 1.5, "live_period": 3600}}' - result = types.InlineQuery.de_json(json_str) - assert result.id == 'iq1' - assert isinstance(result.from_user, types.User) - assert result.query == 'test' - assert result.offset == 'off1' - assert result.chat_type == 'private' - assert isinstance(result.location, types.Location) - assert isinstance(result, types.InlineQuery) - - -def test_json_invoice(): - json_str = r'{"title": "test", "description": "test", "start_parameter": "test_sp", "currency": "test", "total_amount": 1}' - result = types.Invoice.de_json(json_str) - assert result.title == 'test' - assert result.description == 'test' - assert result.start_parameter == 'test_sp' - assert result.currency == 'test' - assert result.total_amount == 1 - assert isinstance(result, types.Invoice) - - -def test_json_jsondeserializable(): - # JsonDeserializable is abstract base class, skip - pass - - -def test_json_link(): - json_str = r'{"url": "https://example.com"}' - result = types.Link.de_json(json_str) - assert result.url == 'https://example.com' - assert isinstance(result, types.Link) - - -def test_json_livephoto(): - json_str = r'{"file_id": "test_file_id", "file_unique_id": "test_unique_id", "width": 100, "height": 100, "duration": 30, "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}], "mime_type": "image/jpeg", "file_size": 20480}' - result = types.LivePhoto.de_json(json_str) - assert result.file_id == 'test_file_id' - assert result.file_unique_id == 'test_unique_id' - assert result.width == 100 - assert result.height == 100 - assert result.duration == 30 - assert isinstance(result.photo, list) - assert result.mime_type == 'image/jpeg' - assert result.file_size == 20480 - assert isinstance(result, types.LivePhoto) - - -def test_json_managedbotcreated(): - json_str = r'{"bot": {"id": 1, "is_bot": true, "first_name": "Bot"}}' - result = types.ManagedBotCreated.de_json(json_str) - assert isinstance(result, types.ManagedBotCreated) - assert hasattr(result, 'bot') - - -def test_json_managedbotupdated(): - json_str = r'{"user": {"id": 1, "is_bot": false, "first_name": "Test"}, "bot": {"id": 2, "is_bot": true, "first_name": "Bot"}}' - result = types.ManagedBotUpdated.de_json(json_str) - assert isinstance(result.user, types.User) - assert result.user.id == 1 - assert isinstance(result.bot, types.User) - assert result.bot.id == 2 - assert isinstance(result, types.ManagedBotUpdated) - - -def test_json_menubutton(): - # MenuButton dispatches on type - test concrete subclass - json_str = r'{"type": "default"}' - result = types.MenuButtonDefault.de_json(json_str) - assert isinstance(result, types.MenuButtonDefault) - - -def test_json_messageautodeletetimerchanged(): - json_str = r'{"message_auto_delete_time": 60}' - result = types.MessageAutoDeleteTimerChanged.de_json(json_str) - assert result.message_auto_delete_time == 60 - assert isinstance(result, types.MessageAutoDeleteTimerChanged) - - -def test_json_messageid(): - json_str = r'{"message_id": 1}' - result = types.MessageID.de_json(json_str) - assert isinstance(result, types.MessageID) - - -def test_json_messageorigin(): - # MessageOrigin is abstract - test MessageOriginUser directly - json_str = r'{"type": "user", "date": 1682189507, "sender_user": {"id": 1, "is_bot": false, "first_name": "Test"}}' - result = types.MessageOriginUser.de_json(json_str) - assert result.type == 'user' - assert result.date == 1682189507 - assert isinstance(result.sender_user, types.User) - assert result.sender_user.id == 1 - assert result.sender_user.first_name == 'Test' - assert isinstance(result, types.MessageOriginUser) - - -def test_json_messagereactioncountupdated(): - json_str = r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "message_id": 1, "date": 1682189507, "reactions": [{"type": {"type": "emoji", "emoji": "\u2764\ufe0f"}, "total_count": 5}]}' - result = types.MessageReactionCountUpdated.de_json(json_str) - assert isinstance(result.chat, types.Chat) - assert result.message_id == 1 - assert result.date == 1682189507 - assert isinstance(result.reactions, list) - assert isinstance(result, types.MessageReactionCountUpdated) - - -def test_json_messagereactionupdated(): - json_str = r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "message_id": 1, "date": 1682189507, "old_reaction": [{"type": "emoji", "emoji": "\u0001f600"}], "new_reaction": [{"type": "emoji", "emoji": "\u0001f600"}], "user": {"id": 1, "is_bot": false, "first_name": "Test"}, "actor_chat": {"id": -1, "type": "channel", "title": "Channel"}}' - result = types.MessageReactionUpdated.de_json(json_str) - assert isinstance(result.chat, types.Chat) - assert result.message_id == 1 - assert result.date == 1682189507 - assert isinstance(result.old_reaction, list) - assert isinstance(result.new_reaction, list) - assert isinstance(result.user, types.User) - assert isinstance(result.actor_chat, types.Chat) - assert isinstance(result, types.MessageReactionUpdated) - - -def test_json_ownedgift(): - # OwnedGift is abstract - test OwnedGiftRegular directly - json_str = r'{"type": "regular", "gift": {"id": 1, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100}}' - result = types.OwnedGiftRegular.de_json(json_str) - assert result.type == 'regular' - assert isinstance(result, types.OwnedGiftRegular) - - -def test_json_ownedgiftregular(): - json_str = r'{"type": "regular", "gift": {"id": 1, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100}, "owned_gift_id": "og_123", "sender_user": {"id": 1, "is_bot": false, "first_name": "Sender"}, "send_date": 1682189507, "text": {"type": "bold", "text": "Gift text"}, "entities": [{"type": "bold", "offset": 0, "length": 4}], "is_private": false, "is_saved": false, "can_be_upgraded": true, "was_refunded": false, "convert_star_count": 50, "prepaid_upgrade_star_count": 100, "is_upgrade_separate": false, "unique_gift_number": 42}' - result = types.OwnedGiftRegular.de_json(json_str) - assert result.type == 'regular' - assert isinstance(result.gift, types.Gift) - assert result.owned_gift_id == 'og_123' - assert isinstance(result.sender_user, types.User) - assert result.send_date == 1682189507 - assert isinstance(result.text, dict) - assert isinstance(result.entities, list) - assert result.is_private == False - assert result.is_saved == False - assert result.can_be_upgraded == True - assert result.was_refunded == False - assert result.convert_star_count == 50 - assert result.prepaid_upgrade_star_count == 100 - assert result.is_upgrade_separate == False - assert result.unique_gift_number == 42 - assert isinstance(result, types.OwnedGiftRegular) - - -def test_json_ownedgiftunique(): - json_str = r'{"type": "unique", "gift": {"base_name": "test", "name": "test", "number": 1, "model": {"name": "m", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "symbol": {"name": "s", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "backdrop": {"name": "b", "colors": {"center_color": 123456, "edge_color": 654321, "symbol_color": 111111, "text_color": 222222}, "rarity_per_mille": 1000}, "gift_id": 1}, "gift_id": 1, "owned_gift_id": "og_456", "sender_user": {"id": 2, "is_bot": false, "first_name": "Sender"}, "send_date": 1682189507, "is_saved": false, "can_be_transferred": true, "transfer_star_count": 50, "next_transfer_date": 1704067200}' - result = types.OwnedGiftUnique.de_json(json_str) - assert result.type == 'unique' - assert isinstance(result.gift, types.UniqueGift) - assert result.owned_gift_id == 'og_456' - assert isinstance(result.sender_user, types.User) - assert result.send_date == 1682189507 - assert result.is_saved == False - assert result.can_be_transferred == True - assert result.transfer_star_count == 50 - assert result.next_transfer_date == 1704067200 - assert isinstance(result, types.OwnedGiftUnique) - - -def test_json_ownedgifts(): - json_str = r'{"total_count": 1, "gifts": [{"type": "regular", "gift": {"id": 1, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100}}], "next_offset": "offset123"}' - result = types.OwnedGifts.de_json(json_str) - assert result.total_count == 1 - assert isinstance(result.gifts, list) - assert result.next_offset == 'offset123' - assert isinstance(result, types.OwnedGifts) - - -def test_json_paidmedia(): - # PaidMedia is abstract - test PaidMediaPhoto directly - json_str = r'{"type": "photo", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}' - result = types.PaidMediaPhoto.de_json(json_str) - assert isinstance(result, types.PaidMediaPhoto) - - -def test_json_paidmediainfo(): - json_str = r'{"star_count": 100, "paid_media": [{"type": "photo", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}]}' - result = types.PaidMediaInfo.de_json(json_str) - assert result.star_count == 100 - assert isinstance(result.paid_media, list) - assert isinstance(result, types.PaidMediaInfo) - - -def test_json_paidmedialivephoto(): - json_str = r'{"type": "live_photo", "live_photo": {"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100, "duration": 10}}' - result = types.PaidMediaLivePhoto.de_json(json_str) - assert result.type == 'live_photo' - assert isinstance(result.live_photo, types.LivePhoto) - assert isinstance(result, types.PaidMediaLivePhoto) - - -def test_json_paidmediaphoto(): - json_str = r'{"type": "photo", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}' - result = types.PaidMediaPhoto.de_json(json_str) - assert result.type == 'photo' - assert isinstance(result.photo, list) - assert isinstance(result, types.PaidMediaPhoto) - - -def test_json_paidmediapreview(): - json_str = r'{"type": "default", "width": 640, "height": 480, "duration": 30}' - result = types.PaidMediaPreview.de_json(json_str) - assert result.type == 'default' - assert result.width == 640 - assert result.height == 480 - assert result.duration == 30 - assert isinstance(result, types.PaidMediaPreview) - - -def test_json_paidmediapurchased(): - json_str = r'{"from_user": {"id": 1, "is_bot": false, "first_name": "Test"}, "paid_media_payload": "test"}' - result = types.PaidMediaPurchased.de_json(json_str) - assert isinstance(result.from_user, types.User) - assert result.paid_media_payload == 'test' - assert isinstance(result, types.PaidMediaPurchased) - - -def test_json_paidmediavideo(): - json_str = r'{"type": "video", "video": {"file_id": "v", "file_unique_id": "vu", "width": 640, "height": 480, "duration": 30}}' - result = types.PaidMediaVideo.de_json(json_str) - assert result.type == 'video' - assert isinstance(result.video, types.Video) - assert isinstance(result, types.PaidMediaVideo) - - -def test_json_paidmessagepricechanged(): - json_str = r'{"paid_message_star_count": 1}' - result = types.PaidMessagePriceChanged.de_json(json_str) - assert isinstance(result, types.PaidMessagePriceChanged) - assert hasattr(result, 'paid_message_star_count') - - -def test_json_poll(): - # Poll.poll_type is deprecated in Telegram API, not covered - json_str = r'{"id": "poll1", "question": "test question", "options": [{"text": "Opt1", "persistent_id": "opt1"}], "total_voter_count": 10, "is_closed": false, "is_anonymous": true, "type": "quiz", "allows_multiple_answers": false, "explanation": "explanation text", "explanation_entities": [{"type": "bold", "offset": 0, "length": 4}], "open_period": 3600, "close_date": 1682193107, "question_entities": [{"type": "bold", "offset": 0, "length": 5}], "correct_option_ids": [0], "allows_revoting": true, "description": "poll desc", "description_entities": [{"type": "italic", "offset": 0, "length": 9}], "members_only": true, "country_codes": ["US", "GB"], "explanation_media": {"file_id": "em1", "file_unique_id": "emu1", "mime_type": "image/jpeg", "file_name": "media.jpg"}}' - result = types.Poll.de_json(json_str) - # __init__ param is "poll_id" but de_json sets "id" attribute (from JSON "id" key) - # Use Poll.id, NOT Poll.poll_id - assert result.id == "poll1" - assert result.question == "test question" - assert isinstance(result.options, list) - assert result.total_voter_count == 10 - assert result.is_closed == False - assert result.is_anonymous == True - assert result.type == "quiz" - assert result.allows_multiple_answers == False - assert result.explanation == "explanation text" - assert isinstance(result.explanation_entities, list) - assert result.open_period == 3600 - assert result.close_date == 1682193107 - assert isinstance(result.question_entities, list) - assert isinstance(result.correct_option_ids, list) - assert result.allows_revoting == True - assert result.description == "poll desc" - assert isinstance(result.description_entities, list) - assert result.media is None - assert result.members_only == True - assert isinstance(result.country_codes, list) - assert isinstance(result.explanation_media, types.PollMedia) - assert isinstance(result, types.Poll) - - -def test_json_polloption(): - json_str = r'{"text": "test", "persistent_id": 1, "voter_count": 5, "text_entities": [{"type": "bold", "offset": 0, "length": 4}], "added_by_user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "added_by_chat": {"id": -1, "type": "channel", "title": "Channel"}, "addition_date": 1682189507}' - result = types.PollOption.de_json(json_str) - assert result.text == 'test' - assert result.persistent_id == 1 - assert result.voter_count == 5 - assert isinstance(result.text_entities, list) - assert isinstance(result.added_by_user, types.User) - assert result.added_by_user.id == 12345 - assert isinstance(result.added_by_chat, types.Chat) - assert result.addition_date == 1682189507 - assert result.media is None - assert isinstance(result, types.PollOption) - - -def test_json_polloptionadded(): - json_str = r'{"option_persistent_id": 1, "option_text": "test", "poll_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "poll"}, "option_text_entities": [{"type": "bold", "offset": 0, "length": 4}]}' - result = types.PollOptionAdded.de_json(json_str) - assert result.option_persistent_id == 1 - assert result.option_text == 'test' - assert isinstance(result.poll_message, types.Message) - assert isinstance(result.option_text_entities, list) - assert isinstance(result, types.PollOptionAdded) - - -def test_json_polloptiondeleted(): - json_str = r'{"option_persistent_id": 1, "option_text": "test", "poll_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "poll"}, "option_text_entities": [{"type": "bold", "offset": 0, "length": 4}]}' - result = types.PollOptionDeleted.de_json(json_str) - assert result.option_persistent_id == 1 - assert result.option_text == 'test' - assert isinstance(result.poll_message, types.Message) - assert isinstance(result.option_text_entities, list) - assert isinstance(result, types.PollOptionDeleted) - - -def test_json_precheckoutquery(): - json_str = r'{"id": 1, "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "currency": "USD", "total_amount": 1234, "invoice_payload": "test_payload", "shipping_option_id": "opt1", "order_info": {"user_name": "Buyer", "user_phone": "+123", "shipping_address": {"country_code": "US", "state": "CA", "city": "San Jose", "street_line1": "123 Main St", "street_line2": "", "post_code": "95113"}}}' - result = types.PreCheckoutQuery.de_json(json_str) - assert result.id == 1 - assert isinstance(result.from_user, types.User) - assert result.currency == 'USD' - assert result.total_amount == 1234 - assert result.invoice_payload == 'test_payload' - assert result.shipping_option_id == 'opt1' - assert isinstance(result.order_info, types.OrderInfo) - assert isinstance(result, types.PreCheckoutQuery) - - -def test_json_preparedinlinemessage(): - json_str = r'{"id": "prep1", "expiration_date": 1682189507}' - result = types.PreparedInlineMessage.de_json(json_str) - assert result.id == 'prep1' - assert result.expiration_date == 1682189507 - assert isinstance(result, types.PreparedInlineMessage) - - -def test_json_preparedkeyboardbutton(): - json_str = r'{"id": 1}' - result = types.PreparedKeyboardButton.de_json(json_str) - assert result.id == 1 - assert isinstance(result, types.PreparedKeyboardButton) - - -def test_json_proximityalerttriggered(): - json_str = r'{"traveler": {"id": 1, "is_bot": false, "first_name": "Test"}, "watcher": {"id": 1, "is_bot": false, "first_name": "Test"}, "distance": "test"}' - result = types.ProximityAlertTriggered.de_json(json_str) - assert isinstance(result.traveler, dict) - assert isinstance(result.watcher, dict) - assert result.distance == 'test' - assert isinstance(result, types.ProximityAlertTriggered) - - -def test_json_refundedpayment(): - json_str = r'{"currency": "USD", "total_amount": 100, "invoice_payload": "test_payload", "telegram_payment_charge_id": "chg1", "provider_payment_charge_id": "chg2"}' - result = types.RefundedPayment.de_json(json_str) - assert result.currency == 'USD' - assert result.total_amount == 100 - assert result.invoice_payload == 'test_payload' - assert result.telegram_payment_charge_id == 'chg1' - assert result.provider_payment_charge_id == 'chg2' - assert isinstance(result, types.RefundedPayment) - - -def test_json_revenuewithdrawalstate(): - # RevenueWithdrawalState is abstract - test RevenueWithdrawalStatePending directly - json_str = r'{"type": "pending"}' - result = types.RevenueWithdrawalStatePending.de_json(json_str) - assert isinstance(result, types.RevenueWithdrawalStatePending) - - -def test_json_revenuewithdrawalstatefailed(): - json_str = r'{"type": "failed"}' - result = types.RevenueWithdrawalStateFailed.de_json(json_str) - assert result.type == 'failed' - assert isinstance(result, types.RevenueWithdrawalStateFailed) - - -def test_json_revenuewithdrawalstatepending(): - json_str = r'{"type": "pending"}' - result = types.RevenueWithdrawalStatePending.de_json(json_str) - assert result.type == 'pending' - assert isinstance(result, types.RevenueWithdrawalStatePending) - - -def test_json_revenuewithdrawalstatesucceeded(): - json_str = r'{"type": "succeeded", "date": 1682189507, "url": "https://example.com"}' - result = types.RevenueWithdrawalStateSucceeded.de_json(json_str) - assert result.type == 'succeeded' - assert result.date == 1682189507 - assert result.url == 'https://example.com' - assert isinstance(result, types.RevenueWithdrawalStateSucceeded) - - -def test_json_richblockanchor(): - json_str = r'{"type": "anchor", "name": "test"}' - result = types.RichBlock.de_json(json_str) - assert result.name == 'test' - assert isinstance(result, types.RichBlockAnchor) - - -def test_json_richblockaudio(): - json_str = r'{"type": "audio", "audio": {"file_id": "a", "file_unique_id": "au", "duration": 30}, "caption": {"type": "bold", "text": "audio caption"}}' - result = types.RichBlock.de_json(json_str) - assert isinstance(result.audio, types.Audio) - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockAudio) - - -def test_json_richblockblockquotation(): - json_str = r'{"type": "blockquote", "blocks": [{"text": "Test"}], "credit": "Credit text"}' - result = types.RichBlock.de_json(json_str) - assert isinstance(result.blocks, list) - assert result.credit == 'Credit text' - assert isinstance(result, types.RichBlockBlockQuotation) - - -def test_json_richblockcollage(): - json_str = r'{"type": "collage", "blocks": [{"text": "Test"}], "caption": {"type": "bold", "text": "Caption"}}' - result = types.RichBlock.de_json(json_str) - assert isinstance(result.blocks, list) - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockCollage) - - -def test_json_richblocklist(): - json_str = r'{"type": "list", "items": [{"type": "list_item", "label": {"text": "label"}, "blocks": [{"text": "Test"}]}]}' - result = types.RichBlock.de_json(json_str) - assert isinstance(result.items, list) - assert isinstance(result, types.RichBlockList) - assert hasattr(result, 'items') - - -def test_json_richblockmap(): - json_str = r'{"type": "map", "location": {"latitude": 50.0, "longitude": 30.0}, "zoom": 1.0, "width": 100, "height": 100, "caption": {"type": "bold", "text": "Map caption"}}' - result = types.RichBlock.de_json(json_str) - assert isinstance(result.location, types.Location) - assert result.zoom == 1.0 - assert result.width == 100 - assert result.height == 100 - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockMap) - - -def test_json_richblockmathematicalexpression(): - json_str = r'{"type": "mathematical_expression", "expression": "test"}' - result = types.RichBlock.de_json(json_str) - assert result.expression == 'test' - assert isinstance(result, types.RichBlockMathematicalExpression) - - -def test_json_richblockphoto(): - json_str = r'{"type": "photo", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}], "has_spoiler": true, "caption": {"type": "bold", "text": "Photo caption"}}' - result = types.RichBlock.de_json(json_str) - assert isinstance(result.photo, list) - assert result.has_spoiler == True - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockPhoto) - - -def test_json_richblockpullquotation(): - json_str = r'{"type": "pullquote", "text": "test quote", "credit": "Author Name"}' - result = types.RichBlock.de_json(json_str) - assert result.text == 'test quote' - assert result.credit == 'Author Name' - assert isinstance(result, types.RichBlockPullQuotation) - - -def test_json_richblocksectionheading(): - json_str = r'{"type": "heading", "text": "test", "size": "test"}' - result = types.RichBlock.de_json(json_str) - assert result.text == 'test' - assert result.size == 'test' - assert isinstance(result, types.RichBlockSectionHeading) - - -def test_json_richblockslideshow(): - json_str = r'{"type": "slideshow", "blocks": [{"text": "Test"}], "caption": {"type": "bold", "text": "slide caption"}}' - result = types.RichBlock.de_json(json_str) - assert isinstance(result.blocks, list) - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockSlideshow) - assert hasattr(result, 'caption') - assert hasattr(result, 'blocks') - - -def test_json_richblocktable(): - json_str = r'{"type": "table", "cells": [[{"align": "left", "valign": "top", "text": "cell", "is_header": false, "colspan": 1, "rowspan": 1}]], "is_bordered": true, "is_striped": true, "caption": {"type": "bold", "text": "table caption"}}' - result = types.RichBlock.de_json(json_str) - assert isinstance(result.cells, list) - assert result.is_bordered == True - assert result.is_striped == True - assert isinstance(result.caption, types.RichText) - assert isinstance(result, types.RichBlockTable) - assert hasattr(result, 'is_striped') - assert hasattr(result, 'is_bordered') - assert hasattr(result, 'cells') - - -def test_json_richblockthinking(): - json_str = r'{"type": "thinking", "text": "test"}' - result = types.RichBlock.de_json(json_str) - assert result.text == 'test' - assert isinstance(result, types.RichBlockThinking) - - -def test_json_richblockvideo(): - json_str = r'{"type": "video", "video": {"file_id": "v", "file_unique_id": "vu", "width": 640, "height": 480, "duration": 30}, "has_spoiler": true, "caption": {"type": "bold", "text": "video caption"}}' - result = types.RichBlock.de_json(json_str) - assert isinstance(result.video, types.Video) - assert result.has_spoiler == True - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockVideo) - assert hasattr(result, 'has_spoiler') - - -def test_json_richmessage(): - json_str = r'{"blocks": [{"type": "text", "text": "Test"}], "is_rtl": true}' - result = types.RichMessage.de_json(json_str) - assert isinstance(result.blocks, list) - assert result.is_rtl == True - assert isinstance(result, types.RichMessage) - - -def test_json_sentguestmessage(): - json_str = r'{"inline_message_id": 1}' - result = types.SentGuestMessage.de_json(json_str) - assert result.inline_message_id == 1 - assert isinstance(result, types.SentGuestMessage) - - -def test_json_shippingaddress(): - json_str = r'{"country_code": "US", "state": "CA", "city": "San Jose", "street_line1": "123 Main St", "street_line2": "Apt 4", "post_code": "95113"}' - result = types.ShippingAddress.de_json(json_str) - assert result.country_code == 'US' - assert result.state == 'CA' - assert result.city == 'San Jose' - assert result.street_line1 == '123 Main St' - assert result.street_line2 == 'Apt 4' - assert result.post_code == '95113' - assert isinstance(result, types.ShippingAddress) - - -def test_json_shippingquery(): - json_str = r'{"id": "1", "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "invoice_payload": "test_payload", "shipping_address": {"country_code": "US", "state": "CA", "city": "Test", "street_line1": "Test St", "street_line2": "", "post_code": "12345"}}' - result = types.ShippingQuery.de_json(json_str) - assert result.id == '1' - assert isinstance(result.from_user, types.User) - assert result.invoice_payload == 'test_payload' - assert result.shipping_address.country_code == 'US' - assert result.shipping_address.state == 'CA' - assert result.shipping_address.city == 'Test' - assert result.shipping_address.street_line1 == 'Test St' - assert result.shipping_address.street_line2 == '' - assert result.shipping_address.post_code == '12345' - assert isinstance(result, types.ShippingQuery) - - -def test_json_staramount(): - json_str = r'{"amount": "100", "nanostar_amount": 1000000000}' - result = types.StarAmount.de_json(json_str) - assert result.amount == '100' - assert result.nanostar_amount == 1000000000 - assert isinstance(result, types.StarAmount) - - -def test_json_startransaction(): - json_str = r'{"id": 1, "amount": 100, "date": 1682189507, "source": {"type": "fragment"}, "receiver": {"type": "telegram_ads"}, "nanostar_amount": 10000000}' - result = types.StarTransaction.de_json(json_str) - assert result.id == 1 - assert result.amount == 100 - assert result.date == 1682189507 - assert isinstance(result.source, types.TransactionPartnerFragment) - assert isinstance(result.receiver, dict) - assert result.receiver['type'] == 'telegram_ads' - assert result.nanostar_amount == 10000000 - assert isinstance(result, types.StarTransaction) - - -def test_json_startransactions(): - json_str = r'{"transactions": [{"id": "tx1", "amount": 100, "date": 1682189507}]}' - result = types.StarTransactions.de_json(json_str) - assert isinstance(result, types.StarTransactions) - assert hasattr(result, 'transactions') - - -def test_json_story(): - json_str = r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "id": 1}' - result = types.Story.de_json(json_str) - assert isinstance(result.chat, types.Chat) - assert result.id == 1 - assert isinstance(result, types.Story) - - -def test_json_successfulpayment(): - json_str = r'{"currency": "USD", "total_amount": 1234, "invoice_payload": "test_payload", "shipping_option_id": "opt1", "order_info": {"user_name": "Buyer", "user_phone": "+123", "shipping_address": {"country_code": "US", "state": "CA", "city": "San Jose", "street_line1": "123 Main St", "street_line2": "", "post_code": "95113"}}, "telegram_payment_charge_id": "chg1", "provider_payment_charge_id": "chg2", "subscription_expiration_date": 1704067200, "is_recurring": true, "is_first_recurring": true}' - result = types.SuccessfulPayment.de_json(json_str) - assert result.currency == 'USD' - assert result.total_amount == 1234 - assert result.invoice_payload == 'test_payload' - assert result.shipping_option_id == 'opt1' - assert isinstance(result.order_info, types.OrderInfo) - assert result.telegram_payment_charge_id == 'chg1' - assert result.provider_payment_charge_id == 'chg2' - assert result.subscription_expiration_date == 1704067200 - assert result.is_recurring == True - assert result.is_first_recurring == True - assert isinstance(result, types.SuccessfulPayment) - - -def test_json_suggestedpostapprovalfailed(): - json_str = r'{"price": {"currency": "USD", "amount": 100}, "suggested_post_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "suggested"}}' - result = types.SuggestedPostApprovalFailed.de_json(json_str) - assert isinstance(result.price, types.SuggestedPostPrice) - assert isinstance(result.suggested_post_message, types.Message) - assert result.suggested_post_message.message_id == 1 - assert isinstance(result, types.SuggestedPostApprovalFailed) - - -def test_json_suggestedpostapproved(): - json_str = r'{"send_date": 1682189507, "suggested_post_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "suggested"}, "price": {"amount": "100", "currency": "XTR"}}' - result = types.SuggestedPostApproved.de_json(json_str) - assert result.send_date == 1682189507 - assert isinstance(result.suggested_post_message, types.Message) - assert isinstance(result.price, types.SuggestedPostPrice) - assert isinstance(result, types.SuggestedPostApproved) - - -def test_json_suggestedpostinfo(): - json_str = r'{"state": "default", "price": {"amount": "100", "currency": "XTR"}, "send_date": 1682189507}' - result = types.SuggestedPostInfo.de_json(json_str) - assert result.state == 'default' - assert isinstance(result.price, types.SuggestedPostPrice) - assert result.send_date == 1682189507 - assert isinstance(result, types.SuggestedPostInfo) - - -def test_json_suggestedpostpaid(): - json_str = r'{"currency": "test", "suggested_post_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "suggested"}, "amount": 100, "star_amount": {"amount": 50}}' - result = types.SuggestedPostPaid.de_json(json_str) - assert result.currency == 'test' - assert isinstance(result.suggested_post_message, types.Message) - assert result.amount == 100 - assert isinstance(result.star_amount, types.StarAmount) - assert result.star_amount.amount == 50 - assert isinstance(result, types.SuggestedPostPaid) - - -def test_json_suggestedpostrefunded(): - json_str = r'{"reason": "test", "suggested_post_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "suggested"}}' - result = types.SuggestedPostRefunded.de_json(json_str) - assert result.reason == 'test' - assert isinstance(result.suggested_post_message, types.Message) - assert result.suggested_post_message.message_id == 1 - assert isinstance(result, types.SuggestedPostRefunded) - - -def test_json_textquote(): - json_str = r'{"text": "test", "position": 0, "entities": [{"type": "bold", "offset": 0, "length": 4}], "is_manual": true}' - result = types.TextQuote.de_json(json_str) - assert result.text == 'test' - assert result.position == 0 - assert isinstance(result.entities, list) - assert result.is_manual == True - assert isinstance(result, types.TextQuote) - - -def test_json_transactionpartner(): - # TransactionPartner is abstract - test TransactionPartnerUser directly - json_str = r'{"type": "user", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}' - result = types.TransactionPartnerUser.de_json(json_str) - assert isinstance(result, types.TransactionPartnerUser) - - -def test_json_transactionpartneraffiliateprogram(): - json_str = r'{"type": "affiliate_program", "commission_per_mille": 1000, "sponsor_user": {"id": 1, "is_bot": false, "first_name": "Sponsor"}}' - result = types.TransactionPartnerAffiliateProgram.de_json(json_str) - assert result.type == 'affiliate_program' - assert result.commission_per_mille == 1000 - assert isinstance(result.sponsor_user, types.User) - assert result.sponsor_user.id == 1 - assert isinstance(result, types.TransactionPartnerAffiliateProgram) - - -def test_json_transactionpartnerchat(): - json_str = r'{"type": "chat", "chat": {"id": 1, "type": "private", "title": "Test"}, "gift": {"id": 123456789, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100, "total_count": 5, "remaining_count": 3, "upgrade_star_count": 50, "personal_total_count": 10, "personal_remaining_count": 2, "is_premium": true, "has_colors": true, "publisher_chat": {"id": 1, "type": "channel", "title": "Publisher"}, "unique_gift_variant_count": 3}}' - result = types.TransactionPartnerChat.de_json(json_str) - assert result.type == 'chat' - assert isinstance(result.chat, types.Chat) - assert isinstance(result.gift, types.Gift) - assert result.gift.id == 123456789 - assert isinstance(result, types.TransactionPartnerChat) - - -def test_json_transactionpartnerfragment(): - json_str = r'{"type": "fragment", "withdrawal_state": {"type": "pending"}}' - result = types.TransactionPartnerFragment.de_json(json_str) - assert result.type == 'fragment' - assert isinstance(result.withdrawal_state, types.RevenueWithdrawalState) - assert isinstance(result, types.TransactionPartnerFragment) - - -def test_json_transactionpartnerother(): - json_str = r'{"type": "other"}' - result = types.TransactionPartnerOther.de_json(json_str) - assert result.type == 'other' - assert isinstance(result, types.TransactionPartnerOther) - - -def test_json_transactionpartnertelegramapi(): - json_str = r'{"type": "default", "request_count": 10}' - result = types.TransactionPartnerTelegramApi.de_json(json_str) - assert result.type == 'default' - assert result.request_count == 10 - assert isinstance(result, types.TransactionPartnerTelegramApi) - - -def test_json_transactionpartneruser(): - json_str = r'{"type": "default", "user": {"id": 1, "is_bot": false, "first_name": "Test"}, "affiliate": {"commission_per_mille": 5500, "amount": 100, "affiliate_user": {"id": 1, "is_bot": false, "first_name": "User"}, "affiliate_chat": {"id": 1, "type": "private"}, "nanostar_amount": 1000000}, "invoice_payload": "payload", "paid_media": [{"type": "photo", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}], "subscription_period": 30, "gift": {"id": 1, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100, "total_count": 1000, "remaining_count": 999, "upgrade_star_count": 50, "personal_total_count": 5, "personal_remaining_count": 3, "is_premium": true, "has_colors": false, "publisher_chat": {"id": 1, "type": "channel", "title": "Pub"}, "unique_gift_variant_count": 10}, "premium_subscription_duration": 12, "transaction_type": "purchase"}' - result = types.TransactionPartnerUser.de_json(json_str) - assert result.type == 'default' - assert isinstance(result.user, types.User) - assert isinstance(result.affiliate, types.AffiliateInfo) - assert result.invoice_payload == 'payload' - assert isinstance(result.paid_media, list) - assert result.subscription_period == 30 - assert isinstance(result.gift, types.Gift) - assert result.premium_subscription_duration == 12 - assert result.transaction_type == 'purchase' - assert isinstance(result, types.TransactionPartnerUser) - - -def test_json_uniquegift(): - json_str = r'{"base_name": "test", "name": "test", "number": 1, "model": {"name": "model_name", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "symbol": {"name": "symbol_name", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "backdrop": {"name": "backdrop_name", "colors": {"center_color": 123456, "edge_color": 654321, "symbol_color": 111111, "text_color": 222222}, "rarity_per_mille": 1000}, "gift_id": 1, "publisher_chat": {"id": -1001234567890, "type": "channel", "title": "Channel"}, "is_from_blockchain": true, "is_premium": false, "colors": {"model_custom_emoji_id": 1, "symbol_custom_emoji_id": 1, "light_theme_main_color": 333333, "light_theme_other_colors": [444444], "dark_theme_main_color": 555555, "dark_theme_other_colors": [666666]}, "is_burned": false}' - result = types.UniqueGift.de_json(json_str) - assert result.base_name == 'test' - assert result.name == 'test' - assert result.number == 1 - assert isinstance(result.model, types.UniqueGiftModel) - assert isinstance(result.symbol, types.UniqueGiftSymbol) - assert isinstance(result.backdrop, types.UniqueGiftBackdrop) - assert result.gift_id == 1 - assert isinstance(result.publisher_chat, types.Chat) - assert result.is_from_blockchain == True - assert result.is_premium == False - assert isinstance(result.colors, types.UniqueGiftColors) - assert result.is_burned == False - assert isinstance(result, types.UniqueGift) - - -def test_json_uniquegiftbackdrop(): - json_str = r'{"name": "test", "colors": {"center_color": 123456, "edge_color": 654321, "symbol_color": 111111, "text_color": 222222}, "rarity_per_mille": 1000}' - result = types.UniqueGiftBackdrop.de_json(json_str) - assert result.name == 'test' - assert isinstance(result.colors, types.UniqueGiftBackdropColors) - assert result.rarity_per_mille == 1000 - assert isinstance(result, types.UniqueGiftBackdrop) - - -def test_json_uniquegiftbackdropcolors(): - json_str = r'{"center_color": 123456, "edge_color": 654321, "symbol_color": 111111, "text_color": 222222}' - result = types.UniqueGiftBackdropColors.de_json(json_str) - assert result.center_color == 123456 - assert result.edge_color == 654321 - assert result.symbol_color == 111111 - assert result.text_color == 222222 - assert isinstance(result, types.UniqueGiftBackdropColors) - - -def test_json_uniquegiftcolors(): - json_str = r'{"model_custom_emoji_id": 1, "symbol_custom_emoji_id": 1, "light_theme_main_color": 333333, "light_theme_other_colors": [444444], "dark_theme_main_color": 555555, "dark_theme_other_colors": [666666]}' - result = types.UniqueGiftColors.de_json(json_str) - assert result.model_custom_emoji_id == 1 - assert result.symbol_custom_emoji_id == 1 - assert result.light_theme_main_color == 333333 - assert isinstance(result.light_theme_other_colors, list) - assert result.dark_theme_main_color == 555555 - assert isinstance(result.dark_theme_other_colors, list) - assert isinstance(result, types.UniqueGiftColors) - - -def test_json_uniquegiftinfo(): - json_str = r'{"gift": {"base_name": "b", "name": "n", "number": 1, "model": {"name": "m", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "symbol": {"name": "s", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "backdrop": {"name": "b", "colors": {"center_color": 123456, "edge_color": 654321, "symbol_color": 111111, "text_color": 222222}, "rarity_per_mille": 1000}, "gift_id": 1}, "origin": "test", "owned_gift_id": "og123", "transfer_star_count": 100, "next_transfer_date": 1682189507, "last_resale_currency": "USD", "last_resale_amount": 500}' - result = types.UniqueGiftInfo.de_json(json_str) - assert isinstance(result.gift, types.UniqueGift) - assert result.origin == 'test' - assert result.owned_gift_id == 'og123' - assert result.transfer_star_count == 100 - assert result.next_transfer_date == 1682189507 - assert result.last_resale_currency == 'USD' - assert result.last_resale_amount == 500 - assert isinstance(result, types.UniqueGiftInfo) - - -def test_json_uniquegiftmodel(): - json_str = r'{"name": "test", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000, "rarity": "common"}' - result = types.UniqueGiftModel.de_json(json_str) - assert result.name == 'test' - assert isinstance(result.sticker, types.Sticker) - assert result.rarity_per_mille == 1000 - assert result.rarity == 'common' - assert isinstance(result, types.UniqueGiftModel) - - -def test_json_uniquegiftsymbol(): - json_str = r'{"name": "test", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}' - result = types.UniqueGiftSymbol.de_json(json_str) - assert result.name == 'test' - assert isinstance(result.sticker, types.Sticker) - assert result.rarity_per_mille == 1000 - assert isinstance(result, types.UniqueGiftSymbol) - - -# NOTE: Update is an abstract/registry class that dispatches to specific -# update types (message_update, callback_query_update, etc.). Its __init__ -# only contains 'update_id' in practice; other 'update_type' fields are -# handled by subclasses. Full field coverage is intentionally not required. -def test_json_update(): - json_str = r'{"update_id": 1}' - result = types.Update.de_json(json_str) - assert result.update_id == 1 - assert isinstance(result, types.Update) - - -def test_json_userchatboosts(): - json_str = r'{"boosts": [{"boost_item_id": "b1", "add_date": 1682189507, "expiration_date": 1682275907}]}' - result = types.UserChatBoosts.de_json(json_str) - assert isinstance(result.boosts, list) - assert isinstance(result, types.UserChatBoosts) - assert hasattr(result, 'boosts') - - -def test_json_userprofileaudios(): - json_str = r'{"total_count": 1, "audios": [{"file_id": "a1", "file_unique_id": "au1", "duration": 180, "title": "Test", "performer": "Perf", "type": "song"}]}' - result = types.UserProfileAudios.de_json(json_str) - assert result.total_count == 1 - assert isinstance(result.audios, list) - assert isinstance(result, types.UserProfileAudios) - - -def test_json_userprofilephotos(): - json_str = r'{"total_count": 1, "photos": [[{"file_id": "p1", "file_unique_id": "pu1", "width": 100, "height": 100}]]}' - result = types.UserProfilePhotos.de_json(json_str) - assert result.total_count == 1 - assert isinstance(result.photos, list) - assert isinstance(result.photos[0], list) - assert isinstance(result.photos[0][0], types.PhotoSize) - assert isinstance(result, types.UserProfilePhotos) - - -def test_json_userrating(): - json_str = r'{"level": "test", "rating": "test", "current_level_rating": "test", "next_level_rating": "next_test"}' - result = types.UserRating.de_json(json_str) - assert result.level == 'test' - assert result.rating == 'test' - assert result.current_level_rating == 'test' - assert result.next_level_rating == 'next_test' - assert isinstance(result, types.UserRating) - - -def test_json_videochatended(): - json_str = r'{"duration": 30}' - result = types.VideoChatEnded.de_json(json_str) - assert result.duration == 30 - assert isinstance(result, types.VideoChatEnded) - - -def test_json_videochatscheduled(): - json_str = r'{"start_date": 1682189507}' - result = types.VideoChatScheduled.de_json(json_str) - assert result.start_date == 1682189507 - assert isinstance(result, types.VideoChatScheduled) - - -def test_json_videonote(): - json_str = r'{"file_id": "test_file_id", "file_unique_id": "test_unique_id", "length": 100, "duration": 30, "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 50, "height": 50}, "file_size": 1024}' - result = types.VideoNote.de_json(json_str) - assert result.file_id == 'test_file_id' - assert result.file_unique_id == 'test_unique_id' - assert result.length == 100 - assert result.duration == 30 - assert isinstance(result.thumbnail, types.PhotoSize) - assert result.file_size == 1024 - assert isinstance(result, types.VideoNote) - - -def test_json_videoquality(): - json_str = r'{"file_id": "test_file_id", "file_unique_id": "test_unique_id", "width": 100, "height": 100, "codec": "h264", "file_size": 1024}' - result = types.VideoQuality.de_json(json_str) - assert result.file_id == 'test_file_id' - assert result.file_unique_id == 'test_unique_id' - assert result.width == 100 - assert result.height == 100 - assert result.codec == 'h264' - assert result.file_size == 1024 - assert isinstance(result, types.VideoQuality) - - -def test_json_webhookinfo(): - json_str = r'{"url": "https://example.com", "has_custom_certificate": false, "pending_update_count": 1}' - result = types.WebhookInfo.de_json(json_str) - assert result.url == 'https://example.com' - assert result.has_custom_certificate == False - assert result.pending_update_count == 1 - assert isinstance(result, types.WebhookInfo) \ No newline at end of file +def test_chat_administrator_rights_can_manage_tags(): + rights = types.ChatAdministratorRights( + is_anonymous=False, + can_manage_chat=True, + can_delete_messages=True, + can_manage_video_chats=True, + can_restrict_members=True, + can_promote_members=True, + can_change_info=True, + can_invite_users=True, + can_manage_tags=True, + ) + assert rights.to_dict()['can_manage_tags'] is True diff --git a/tests/test_types.to_dict b/tests/test_types.to_dict deleted file mode 100644 index 314d36035..000000000 --- a/tests/test_types.to_dict +++ /dev/null @@ -1,3465 +0,0 @@ -# -*- coding: utf-8 -*- -import sys - -sys.path.append('../') -from telebot import types -import json - - -def test_json_user(): - json_dict = json.loads(r'{"id": 123456789, "is_bot": false, "first_name": "John", "last_name": "Doe", "username": "@johndoe", "language_code": "en", "can_join_groups": true, "can_read_all_group_messages": false, "supports_inline_queries": true, "is_premium": true, "added_to_attachment_menu": false, "can_connect_to_business": true, "has_main_web_app": false, "has_topics_enabled": true, "allows_users_to_create_topics": true, "can_manage_bots": true, "supports_guest_queries": true, "supports_join_request_queries": true}') - result = types.User.de_json(json_dict) - assert result.id == 123456789 - assert result.is_bot == False - assert result.first_name == 'John' - assert result.last_name == 'Doe' - assert result.username == '@johndoe' - assert result.language_code == 'en' - assert result.can_join_groups == True - assert result.can_read_all_group_messages == False - assert result.supports_inline_queries == True - assert result.is_premium == True - assert result.added_to_attachment_menu == False - assert result.can_connect_to_business == True - assert result.has_main_web_app == False - assert result.has_topics_enabled == True - assert result.allows_users_to_create_topics == True - assert result.can_manage_bots == True - assert result.supports_guest_queries == True - assert result.supports_join_request_queries == True - assert isinstance(result, types.User) - - -def test_user_to_dict(): - obj = types.User(id=123456789, is_bot=False, first_name='John') - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_json_chat(): - json_dict = json.loads(r'{"id": 12345, "type": "private", "title": "Test Chat", "username": "@testchat", "first_name": "John", "last_name": "Doe", "photo": {"small_file_id": "s", "small_file_unique_id": "su", "big_file_id": "b", "big_file_unique_id": "bu"}, "bio": "bio text", "has_private_forwards": true, "description": "chat description", "invite_link": "https://t.me/joinchat/ABC", "pinned_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "pinned"}, "permissions": {"can_send_messages": true, "can_send_audios": true, "can_send_documents": true, "can_send_photos": true, "can_send_videos": true, "can_send_video_notes": true, "can_send_voice_notes": true, "can_send_polls": true, "can_send_other_messages": true, "can_add_web_page_previews": true, "can_change_info": true, "can_invite_users": true, "can_pin_messages": true, "can_manage_topics": true}, "slow_mode_delay": 30, "message_auto_delete_time": 86400, "has_protected_content": true, "sticker_set_name": "TestStickerSet", "can_set_sticker_set": false, "linked_chat_id": 2, "location": {"chat": {"id": 1, "type": "supergroup", "title": "Loc"}, "location": {"latitude": 50.45, "longitude": 30.52}, "address": "Main St"}, "join_to_send_messages": false, "join_by_request": true, "has_restricted_voice_and_video_messages": false, "is_forum": true, "max_reaction_count": 10, "active_usernames": ["test"], "emoji_status_custom_emoji_id": "custom_emoji", "has_hidden_members": false, "has_aggressive_anti_spam_enabled": false, "emoji_status_expiration_date": 1682275907, "available_reactions": ["emoji", "custom_emoji"], "accent_color_id": 1, "background_custom_emoji_id": "bg_emoji", "profile_accent_color_id": 2, "profile_background_custom_emoji_id": "profile_bg", "has_visible_history": true, "unrestrict_boost_count": 5, "custom_emoji_sticker_set_name": "custom_stickers", "business_intro": {"title": "Business", "description": "Business desc", "has_visible_history": true}, "business_location": {"address": "New York, NY", "has_active_address": true}, "business_opening_hours": {"time_zone_name": "America/New_York", "opening_hours": [{"opening_minute": 540, "closing_minute": 1020, "day_of_week": 1, "is_recurring": true}]}, "personal_chat": {"id": 3, "type": "private", "title": "Personal"}, "birthdate": {"day": "15", "month": "6"}, "can_send_paid_media": true, "accepted_gift_types": {"unlimited_gifts": false, "limited_gifts": false, "unique_gifts": true, "premium_subscription": false, "gifts_from_channels": false}, "is_direct_messages": true, "parent_chat": {"id": 4, "type": "supergroup", "title": "Parent"}, "rating": {"level": "test", "rating": "test", "current_level_rating": "test"}, "paid_message_star_count": 5, "first_profile_audio": {"file_id": "fa1", "file_unique_id": "fa1u", "duration": 30, "mime_type": "audio/ogg"}}') - result = types.Chat.de_json(json_dict) - assert result.id == 12345 - assert result.type == 'private' - assert result.title == 'Test Chat' - assert result.username == "@testchat" - assert result.first_name == "John" - assert result.last_name == "Doe" - assert isinstance(result.photo, types.ChatPhoto) - assert result.bio == "bio text" - assert result.has_private_forwards == True - assert result.description == "chat description" - assert result.invite_link == "https://t.me/joinchat/ABC" - assert isinstance(result.pinned_message, types.Message) - assert isinstance(result.permissions, types.ChatPermissions) - assert result.slow_mode_delay == 30 - assert result.message_auto_delete_time == 86400 - assert result.has_protected_content == True - assert result.sticker_set_name == "TestStickerSet" - assert result.can_set_sticker_set == False - assert result.linked_chat_id == 2 - assert isinstance(result.location, types.ChatLocation) - assert result.join_to_send_messages == False - assert result.join_by_request == True - assert result.has_restricted_voice_and_video_messages == False - assert result.is_forum == True - assert result.max_reaction_count == 10 - assert isinstance(result.active_usernames, list) - assert result.emoji_status_custom_emoji_id == "custom_emoji" - assert result.has_hidden_members == False - assert result.has_aggressive_anti_spam_enabled == False - assert result.emoji_status_expiration_date == 1682275907 - assert isinstance(result.available_reactions, list) - assert result.accent_color_id == 1 - assert result.background_custom_emoji_id == "bg_emoji" - assert result.profile_accent_color_id == 2 - assert result.profile_background_custom_emoji_id == "profile_bg" - assert result.has_visible_history == True - assert result.unrestrict_boost_count == 5 - assert result.custom_emoji_sticker_set_name == "custom_stickers" - assert isinstance(result.business_intro, types.BusinessIntro) - assert isinstance(result.business_location, types.BusinessLocation) - assert isinstance(result.business_opening_hours, types.BusinessOpeningHours) - assert isinstance(result.personal_chat, types.Chat) - assert isinstance(result.birthdate, types.Birthdate) - assert result.can_send_paid_media == True - assert isinstance(result.accepted_gift_types, types.AcceptedGiftTypes) - assert result.is_direct_messages == True - assert isinstance(result.parent_chat, types.Chat) - assert isinstance(result.rating, types.UserRating) - assert result.paid_message_star_count == 5 - assert isinstance(result.first_profile_audio, types.Audio) - assert isinstance(result, types.Chat) - - -def test_json_message(): - json_dict = json.loads(r'{"message_id": 1, "date": 1682189507, "chat": {"id": 12345, "type": "private", "title": "Chat"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "Hello", "content_type": "text"}') - result = types.Message.de_json(json_dict) - assert result.message_id == 1 - assert isinstance(result.from_user, types.User) - assert result.date == 1682189507 - assert isinstance(result.chat, types.Chat) - assert result.content_type == 'text' - assert isinstance(result, types.Message) - - -def test_json_location(): - json_dict = json.loads(r'{"latitude": 50.4501, "longitude": 30.5234, "horizontal_accuracy": 1.5, "live_period": 3600, "heading": 45, "proximity_alert_radius": 100}') - result = types.Location.de_json(json_dict) - assert result.longitude == 30.5234 - assert result.latitude == 50.4501 - assert result.horizontal_accuracy == 1.5 - assert result.live_period == 3600 - assert result.heading == 45 - assert result.proximity_alert_radius == 100 - assert isinstance(result, types.Location) - - -def test_json_venue(): - json_dict = json.loads(r'{"location": {"latitude": 50.45, "longitude": 30.52}, "title": "Kyiv", "address": "Khreshchatyk St", "foursquare_id": "12345", "foursquare_type": "restaurant", "google_place_id": "ChI123456", "google_place_type": "locality"}') - result = types.Venue.de_json(json_dict) - assert isinstance(result.location, types.Location) - assert result.title == 'Kyiv' - assert result.address == 'Khreshchatyk St' - assert result.foursquare_id == '12345' - assert result.foursquare_type == 'restaurant' - assert result.google_place_id == 'ChI123456' - assert result.google_place_type == 'locality' - assert isinstance(result, types.Venue) - - -def test_json_contact(): - json_dict = json.loads(r'{"phone_number": "+123****7890", "first_name": "John", "user_id": 12345, "last_name": "Doe", "vcard": "some vcard data"}') - result = types.Contact.de_json(json_dict) - assert result.phone_number == '+123****7890' - assert result.first_name == 'John' - assert result.last_name == 'Doe' - assert result.user_id == 12345 - assert result.vcard == 'some vcard data' - assert isinstance(result, types.Contact) - - -def test_json_document(): - json_dict = json.loads(r'{"file_id": "doc1", "file_unique_id": "du1", "file_name": "test.pdf", "mime_type": "application/pdf", "file_size": 1024, "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 50, "height": 50}}') - result = types.Document.de_json(json_dict) - assert result.file_id == 'doc1' - assert result.file_unique_id == 'du1' - assert isinstance(result.thumbnail, types.PhotoSize) - assert result.file_name == 'test.pdf' - assert result.mime_type == 'application/pdf' - assert result.file_size == 1024 - assert isinstance(result, types.Document) - - -def test_json_photo_size(): - json_dict = json.loads(r'{"file_id": "photo1", "file_unique_id": "pu1", "width": 100, "height": 100, "file_size": 512}') - result = types.PhotoSize.de_json(json_dict) - assert result.file_id == 'photo1' - assert result.file_unique_id == 'pu1' - assert result.width == 100 - assert result.height == 100 - assert result.file_size == 512 - assert isinstance(result, types.PhotoSize) - - -def test_json_video(): - json_dict = json.loads(r'{"file_id": "video1", "file_unique_id": "vu1", "width": 640, "height": 480, "duration": 30, "mime_type": "video/mp4", "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 50, "height": 50}, "file_name": "video.mp4", "file_size": 2048, "start_timestamp": 5, "qualities": [{"file_id": "q1", "file_unique_id": "qu1", "width": 240, "height": 360, "codec": "h264", "file_size": 1024}, {"file_id": "q2", "file_unique_id": "qu2", "width": 640, "height": 480, "codec": "h264", "file_size": 2048}]}') - result = types.Video.de_json(json_dict) - assert result.file_id == 'video1' - assert result.file_unique_id == 'vu1' - assert result.width == 640 - assert result.height == 480 - assert result.duration == 30 - assert isinstance(result.thumbnail, types.PhotoSize) - assert result.file_name == 'video.mp4' - assert result.mime_type == 'video/mp4' - assert result.file_size == 2048 - assert result.cover is None - assert result.start_timestamp == 5 - assert isinstance(result.qualities, list) - assert isinstance(result, types.Video) - - -def test_json_audio(): - json_dict = json.loads(r'{"file_id": "audio1", "file_unique_id": "au1", "duration": 30, "mime_type": "audio/mpeg", "performer": "Artist", "title": "Song Title", "file_name": "song.mp3", "file_size": 512, "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 50, "height": 50}}') - result = types.Audio.de_json(json_dict) - assert result.file_id == 'audio1' - assert result.file_unique_id == 'au1' - assert result.duration == 30 - assert result.performer == 'Artist' - assert result.title == 'Song Title' - assert result.file_name == 'song.mp3' - assert result.mime_type == 'audio/mpeg' - assert result.file_size == 512 - assert isinstance(result.thumbnail, types.PhotoSize) - assert isinstance(result, types.Audio) - - -def test_json_voice(): - json_dict = json.loads(r'{"file_id": "voice1", "file_unique_id": "vu1", "duration": 30, "mime_type": "audio/ogg", "file_size": 256}') - result = types.Voice.de_json(json_dict) - assert result.file_id == 'voice1' - assert result.file_unique_id == 'vu1' - assert result.duration == 30 - assert result.mime_type == 'audio/ogg' - assert result.file_size == 256 - assert isinstance(result, types.Voice) - - -def test_json_animation(): - json_dict = json.loads(r'{"file_id": "anim1", "file_unique_id": "anu1", "width": 100, "height": 100, "duration": 10, "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 50, "height": 50}, "file_name": "anim.mp4", "mime_type": "video/mp4", "file_size": 1024}') - result = types.Animation.de_json(json_dict) - assert result.file_id == 'anim1' - assert result.file_unique_id == 'anu1' - assert result.width == 100 - assert result.height == 100 - assert result.duration == 10 - assert isinstance(result.thumbnail, types.PhotoSize) - assert result.file_name == 'anim.mp4' - assert result.mime_type == 'video/mp4' - assert result.file_size == 1024 - assert isinstance(result, types.Animation) - - -def test_json_sticker(): - json_dict = json.loads(r'{"file_id": "sticker1", "file_unique_id": "stu1", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false, "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 100, "height": 100}, "emoji": "😀", "set_name": "TestSet", "mask_position": {"point": "forehead", "x_shift": 0.0, "y_shift": 0.0, "scale": 0.5}, "file_size": 4096, "premium_animation": {"file_id": "pa1", "file_unique_id": "pa1u"}, "custom_emoji_id": "ce1", "needs_repainting": true}') - result = types.Sticker.de_json(json_dict) - assert result.file_id == 'sticker1' - assert result.file_unique_id == 'stu1' - assert result.type == 'regular' - assert result.width == 512 - assert result.height == 512 - assert result.is_animated == False - assert result.is_video == False - assert isinstance(result.thumbnail, types.PhotoSize) - assert result.emoji == '😀' - assert result.set_name == 'TestSet' - assert isinstance(result.mask_position, types.MaskPosition) - assert result.file_size == 4096 - assert isinstance(result.premium_animation, types.File) - assert result.custom_emoji_id == 'ce1' - assert result.needs_repainting == True - assert isinstance(result, types.Sticker) - - -def test_json_stickerset(): - json_dict = json.loads(r'{"name": "TestName", "title": "Test Title", "sticker_type": "regular", "stickers": [{"file_id": "st1", "file_unique_id": "su1", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}], "thumbnail": {"file_id": "th1", "file_unique_id": "thu1", "width": 100, "height": 100}}') - result = types.StickerSet.de_json(json_dict) - assert result.name == 'TestName' - assert result.title == 'Test Title' - assert result.sticker_type == 'regular' - assert isinstance(result.stickers, list) - assert isinstance(result.thumbnail, types.PhotoSize) - assert isinstance(result, types.StickerSet) - - -def test_json_chatlocation(): - json_dict = json.loads(r'{"location": {"latitude": 50.45, "longitude": 30.52}, "address": "New York, NY"}') - result = types.ChatLocation.de_json(json_dict) - assert isinstance(result.location, types.Location) - assert result.address == 'New York, NY' - - -def test_json_reactiontypeemoji(): - json_dict = json.loads(r'{"type": "emoji", "emoji": "\u2764\uFE0F"}') - result = types.ReactionTypeEmoji.de_json(json_dict) - assert result.emoji == '❤️' - assert isinstance(result, types.ReactionTypeEmoji) - - -def test_json_reactiontypecustomemoji(): - json_dict = json.loads(r'{"type": "custom_emoji", "custom_emoji_id": "ce123"}') - result = types.ReactionTypeCustomEmoji.de_json(json_dict) - assert result.custom_emoji_id == 'ce123' - assert isinstance(result, types.ReactionTypeCustomEmoji) - - -def test_json_reactioncount(): - json_dict = json.loads(r'{"type": {"type": "emoji", "emoji": "\u2764\uFE0F"}, "total_count": 5}') - result = types.ReactionCount.de_json(json_dict) - assert isinstance(result.type, types.ReactionType) - assert result.total_count == 5 - assert isinstance(result, types.ReactionCount) - - -def test_json_chatinvitelink(): - json_dict = json.loads(r'{"invite_link": "https://t.me/joinchat/ABC", "creator": {"id": 12345, "is_bot": false, "first_name": "Test"}, "creates_join_request": false, "is_primary": true, "is_revoked": false, "name": "Invite", "expire_date": 1704067200, "member_limit": 10, "pending_join_request_count": 3}') - result = types.ChatInviteLink.de_json(json_dict) - assert result.invite_link == 'https://t.me/joinchat/ABC' - assert isinstance(result.creator, types.User) - assert result.creates_join_request == False - assert result.is_primary == True - assert result.is_revoked == False - assert result.name == 'Invite' - assert result.expire_date == 1704067200 - assert result.member_limit == 10 - assert result.pending_join_request_count == 3 - assert isinstance(result, types.ChatInviteLink) - - -def test_json_forumtopic(): - json_dict = json.loads(r'{"message_thread_id": 42, "name": "Topic", "icon_color": 4294967295, "icon_custom_emoji_id": "emoji1", "is_name_implicit": true}') - result = types.ForumTopic.de_json(json_dict) - assert result.message_thread_id == 42 - assert result.name == 'Topic' - assert result.icon_color == 4294967295 - assert result.icon_custom_emoji_id == 'emoji1' - assert result.is_name_implicit == True - assert isinstance(result, types.ForumTopic) - - -def test_json_loginurl(): - json_dict = json.loads(r'{"url": "https://example.com", "forward_text": "Forward", "bot_username": "botuser", "request_write_access": true}') - result = types.LoginUrl.de_json(json_dict) - assert result.url == 'https://example.com' - assert result.forward_text == 'Forward' - assert result.bot_username == 'botuser' - assert result.request_write_access == True - assert isinstance(result, types.LoginUrl) - - -def test_json_webappinfo(): - json_dict = json.loads(r'{"url": "https://example.com"}') - result = types.WebAppInfo.de_json(json_dict) - assert result.url == 'https://example.com' - assert isinstance(result, types.WebAppInfo) - - -def test_json_webappdata(): - json_dict = json.loads(r'{"data": "test_data", "button_text": "Button"}') - result = types.WebAppData.de_json(json_dict) - assert result.data == 'test_data' - assert result.button_text == 'Button' - assert isinstance(result, types.WebAppData) - - -def test_json_maskposition(): - json_dict = json.loads(r'{"point": "forehead", "x_shift": 0.0, "y_shift": 0.0, "scale": 0.5}') - result = types.MaskPosition.de_json(json_dict) - assert result.point == 'forehead' - assert result.x_shift == 0.0 - assert result.y_shift == 0.0 - assert result.scale == 0.5 - assert isinstance(result, types.MaskPosition) - - -def test_json_messageentity(): - json_dict = json.loads(r'{"type": "bold", "offset": 0, "length": 5, "url": "https://example.com", "language": "en"}') - result = types.MessageEntity.de_json(json_dict) - assert result.type == 'bold' - assert result.offset == 0 - assert result.length == 5 - assert result.url == 'https://example.com' - assert result.language == 'en' - assert isinstance(result, types.MessageEntity) - - -def test_json_messageentitycustomemoji(): - json_dict = json.loads(r'{"type": "custom_emoji", "offset": 0, "length": 10, "custom_emoji_id": "ce123"}') - result = types.MessageEntity.de_json(json_dict) - assert result.type == 'custom_emoji' - assert result.offset == 0 - assert result.length == 10 - assert result.custom_emoji_id == 'ce123' - assert isinstance(result, types.MessageEntity) - - -def test_json_messageentitytextmention(): - json_dict = json.loads(r'{"type": "text_mention", "offset": 0, "length": 10, "user": {"id": 12345, "is_bot": false, "first_name": "Test"}}') - result = types.MessageEntity.de_json(json_dict) - assert result.type == 'text_mention' - assert result.offset == 0 - assert result.length == 10 - assert isinstance(result.user, types.User) - assert isinstance(result, types.MessageEntity) - - -def test_json_chatshared(): - json_dict = json.loads(r'{"request_id": 1, "chat_id": 12345, "title": "Chat Title", "username": "chatuser"}') - result = types.ChatShared.de_json(json_dict) - assert result.request_id == 1 - assert result.chat_id == 12345 - assert result.title == 'Chat Title' - assert result.username == 'chatuser' - assert isinstance(result, types.ChatShared) - - -def test_json_shareduser(): - json_dict = json.loads(r'{"user_id": 12345, "first_name": "Test", "last_name": "User", "username": "testuser"}') - result = types.SharedUser.de_json(json_dict) - assert result.user_id == 12345 - assert result.first_name == 'Test' - assert result.last_name == 'User' - assert result.username == 'testuser' - assert isinstance(result, types.SharedUser) - - -def test_json_usersshared(): - json_dict = json.loads(r'{"request_id": 1, "users": [{"user_id": 12345, "first_name": "Test", "last_name": "User"}]}') - result = types.UsersShared.de_json(json_dict) - assert result.request_id == 1 - assert isinstance(result.users, list) - assert isinstance(result, types.UsersShared) - - -def test_json_chatboost(): - json_dict = json.loads(r'{"boost_item_id": "b1", "add_date": 1682189507, "expiration_date": 1682275907}') - result = types.ChatBoost.de_json(json_dict) - assert result.boost_id is None - assert result.add_date == 1682189507 - assert result.expiration_date == 1682275907 - assert isinstance(result, types.ChatBoost) - - -def test_json_gift(): - json_dict = json.loads(r'{"id": 123456789, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100, "total_count": 5, "remaining_count": 3, "upgrade_star_count": 50, "personal_total_count": 10, "personal_remaining_count": 2, "is_premium": true, "has_colors": true, "publisher_chat": {"id": 1, "type": "channel", "title": "Publisher"}, "unique_gift_variant_count": 3}') - result = types.Gift.de_json(json_dict) - assert result.id == 123456789 - assert isinstance(result.sticker, types.Sticker) - assert result.star_count == 100 - assert result.total_count == 5 - assert result.remaining_count == 3 - assert result.upgrade_star_count == 50 - assert result.personal_total_count == 10 - assert result.personal_remaining_count == 2 - assert result.is_premium == True - assert result.has_colors == True - assert isinstance(result.publisher_chat, types.Chat) - assert result.unique_gift_variant_count == 3 - assert isinstance(result, types.Gift) - - -def test_json_giftinfo(): - json_dict = json.loads(r'{"gift": {"id": 123456789, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100}, "owned_gift_id": "og_123", "convert_star_count": 50, "prepaid_upgrade_star_count": 100, "can_be_upgraded": true, "text": {"type": "bold", "text": "Gift text"}, "entities": [{"type": "bold", "offset": 0, "length": 4}], "is_private": false, "is_upgrade_separate": false, "unique_gift_number": 42}') - result = types.GiftInfo.de_json(json_dict) - assert isinstance(result.gift, types.Gift) - assert result.owned_gift_id == 'og_123' - assert result.convert_star_count == 50 - assert result.prepaid_upgrade_star_count == 100 - assert result.can_be_upgraded == True - assert result.text == {'type': 'bold', 'text': 'Gift text'} - assert isinstance(result.entities, list) - assert result.is_private == False - assert result.is_upgrade_separate == False - assert result.unique_gift_number == 42 - assert isinstance(result, types.GiftInfo) - - -def test_json_gifts(): - json_dict = json.loads(r'{"gifts": [{"id": 123456789, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100}]}') - result = types.Gifts.de_json(json_dict) - assert isinstance(result.gifts, list) - assert isinstance(result, types.Gifts) - - -def test_json_richtextbold(): - json_dict = json.loads(r'{"type": "bold", "text": "Test"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextBold.de_json(data) - assert result.text == 'Test' - assert isinstance(result, types.RichTextBold) - - -def test_json_richtextitalic(): - json_dict = json.loads(r'{"type": "italic", "text": "Test"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextItalic.de_json(data) - assert result.text == 'Test' - assert isinstance(result, types.RichTextItalic) - - -def test_json_richtextunderline(): - json_dict = json.loads(r'{"type": "underline", "text": "Test"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextUnderline.de_json(data) - assert result.text == 'Test' - assert isinstance(result, types.RichTextUnderline) - - -def test_json_richtextstrikethrough(): - json_dict = json.loads(r'{"type": "strikethrough", "text": "Test"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextStrikethrough.de_json(data) - assert result.text == 'Test' - assert isinstance(result, types.RichTextStrikethrough) - - -def test_json_richtextspoiler(): - json_dict = json.loads(r'{"type": "spoiler", "text": "Test"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextSpoiler.de_json(data) - assert result.text == 'Test' - assert isinstance(result, types.RichTextSpoiler) - - -def test_json_richtextsubscript(): - json_dict = json.loads(r'{"type": "subscript", "text": "sub"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextSubscript.de_json(data) - assert result.text == 'sub' - assert isinstance(result, types.RichTextSubscript) - - -def test_json_richtextsuperscript(): - json_dict = json.loads(r'{"type": "superscript", "text": "sup"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextSuperscript.de_json(data) - assert result.text == 'sup' - assert isinstance(result, types.RichTextSuperscript) - - -def test_json_richtextmarked(): - json_dict = json.loads(r'{"type": "marked", "text": "marked"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextMarked.de_json(data) - assert result.text == 'marked' - assert isinstance(result, types.RichTextMarked) - - -def test_json_richtextcode(): - json_dict = json.loads(r'{"type": "code", "text": "code"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextCode.de_json(data) - assert result.text == 'code' - assert isinstance(result, types.RichTextCode) - - -def test_json_richtextanchor(): - json_dict = json.loads(r'{"type": "anchor", "name": "anchor"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextAnchor.de_json(data) - assert result.name == 'anchor' - assert isinstance(result, types.RichTextAnchor) - - -def test_json_richtextdatetime(): - json_dict = json.loads(r'{"type": "date_time", "text": "2024-01-01", "unix_time": 1704067200, "date_time_format": "YYYY-MM-DD"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextDateTime.de_json(data) - assert result.text == '2024-01-01' - assert result.unix_time == 1704067200 - assert result.date_time_format == 'YYYY-MM-DD' - assert isinstance(result, types.RichTextDateTime) - - -def test_json_richtexttextmention(): - json_dict = json.loads(r'{"type": "text_mention", "text": "test text", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextTextMention.de_json(data) - assert result.text == 'test text' - assert isinstance(result.user, types.User) - assert isinstance(result, types.RichTextTextMention) - - -def test_json_richtextanchorlink(): - json_dict = json.loads(r'{"type": "anchor_link", "text": "Link", "anchor_name": "anchor"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextAnchorLink.de_json(data) - assert result.text == 'Link' - assert result.anchor_name == 'anchor' - assert isinstance(result, types.RichTextAnchorLink) - - -def test_json_richtexturl(): - json_dict = json.loads(r'{"type": "url", "text": "click here", "url": "https://example.com"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextUrl.de_json(data) - assert result.text == 'click here' - assert result.url == 'https://example.com' - assert isinstance(result, types.RichTextUrl) - - -def test_json_richtextemailaddress(): - json_dict = json.loads(r'{"type": "email_address", "text": "test@example.com", "email_address": "test@example.com"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextEmailAddress.de_json(data) - assert result.text == 'test@example.com' - assert result.email_address == 'test@example.com' - assert isinstance(result, types.RichTextEmailAddress) - - -def test_json_richtextphonenumber(): - json_dict = json.loads(r'{"type": "phone_number", "text": "+123****7890", "phone_number": "+123****7890"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextPhoneNumber.de_json(data) - assert result.text == '+123****7890' - assert result.phone_number == '+123****7890' - assert isinstance(result, types.RichTextPhoneNumber) - - -def test_json_richtextbankcardnumber(): - json_dict = json.loads(r'{"type": "bank_card_number", "text": "1234 5678 9012 3456", "bank_card_number": "1234 5678 9012 3456"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichTextBankCardNumber.de_json(data) - assert result.text == '1234 5678 9012 3456' - assert result.bank_card_number == '1234 5678 9012 3456' - assert isinstance(result, types.RichTextBankCardNumber) - - -def test_json_richblockparagraph(): - json_dict = json.loads(r'{"type": "paragraph", "text": "Test"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichBlockParagraph.de_json(data) - assert result.text == 'Test' - assert isinstance(result, types.RichBlockParagraph) - - -def test_json_richblockpreformatted(): - json_dict = json.loads(r'{"type": "preformatted", "text": "Code", "language": "python"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichBlockPreformatted.de_json(data) - assert result.text == 'Code' - assert result.language == 'python' - assert isinstance(result, types.RichBlockPreformatted) - - -def test_json_richblockfooter(): - json_dict = json.loads(r'{"type": "footer", "text": "Footer"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichBlockFooter.de_json(data) - assert result.text == 'Footer' - assert isinstance(result, types.RichBlockFooter) - - -def test_json_richblockcaption(): - json_dict = json.loads(r'{"type": "caption", "text": "Caption", "credit": "Author"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichBlockCaption.de_json(data) - assert result.text == 'Caption' - assert result.credit == 'Author' - assert isinstance(result, types.RichBlockCaption) - - -def test_json_richblockanimation(): - json_dict = json.loads(r'{"type": "animation", "animation": {"file_id": "anim_id", "file_unique_id": "anim_uid", "width": 100, "height": 100, "duration": 10}, "caption": {"type": "bold", "text": "anim caption"}, "has_spoiler": true}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichBlockAnimation.de_json(data) - assert isinstance(result.animation, types.Animation) - assert result.has_spoiler == True - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockAnimation) - - -def test_json_richblockdetails(): - json_dict = json.loads(r'{"type": "details", "summary": {"text": "summary text"}, "blocks": [{"text": "detail"}], "is_open": false}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichBlockDetails.de_json(data) - assert isinstance(result.summary, dict) or result.summary is None - assert isinstance(result.blocks, list) - assert result.is_open == False - assert isinstance(result, types.RichBlockDetails) - - -def test_json_richblocklistitem(): - json_dict = json.loads(r'{"label": {"text": "label text"}, "blocks": [{"text": "item block"}], "has_checkbox": true, "is_checked": true, "value": "item value"}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichBlockListItem.de_json(data) - assert isinstance(result.label, dict) - assert isinstance(result.blocks, list) - assert result.has_checkbox == True - assert result.is_checked == True - assert result.value == 'item value' - assert result.type is None - assert isinstance(result, types.RichBlockListItem) - - -def test_json_richblockvoicenote(): - json_dict = json.loads(r'{"type": "voice_note", "voice_note": {"file_id": "voice_id", "file_unique_id": "voice_uid", "duration": 30}, "caption": {"type": "bold", "text": "voice caption"}}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichBlockVoiceNote.de_json(data) - assert isinstance(result.voice_note, types.Voice) - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockVoiceNote) - - -def test_json_chatadministratorrights(): - json_dict = json.loads(r'{"is_anonymous": true, "can_manage_chat": true, "can_delete_messages": true, "can_manage_video_chats": true, "can_restrict_members": true, "can_promote_members": true, "can_change_info": true, "can_invite_users": true, "can_post_messages": true, "can_edit_messages": true, "can_pin_messages": true, "can_manage_topics": true, "can_post_stories": true, "can_edit_stories": true, "can_delete_stories": true, "can_manage_direct_messages": true, "can_manage_tags": true}') - result = types.ChatAdministratorRights.de_json(json_dict) - assert result.is_anonymous == True - assert result.can_manage_chat == True - assert result.can_delete_messages == True - assert result.can_manage_video_chats == True - assert result.can_restrict_members == True - assert result.can_promote_members == True - assert result.can_change_info == True - assert result.can_invite_users == True - assert result.can_post_messages == True - assert result.can_edit_messages == True - assert result.can_pin_messages == True - assert result.can_manage_topics == True - assert result.can_post_stories == True - assert result.can_edit_stories == True - assert result.can_delete_stories == True - assert result.can_manage_direct_messages == True - assert result.can_manage_tags == True - assert isinstance(result, types.ChatAdministratorRights) - - -def test_json_chatpermissions(): - json_dict = json.loads(r'{"can_send_messages": true, "can_send_audios": true, "can_send_documents": true, "can_send_photos": true, "can_send_videos": true, "can_send_video_notes": true, "can_send_voice_notes": true, "can_send_polls": true, "can_send_other_messages": true, "can_add_web_page_previews": true, "can_change_info": true, "can_invite_users": true, "can_pin_messages": true, "can_manage_topics": true, "can_edit_tag": true, "can_react_to_messages": true}') - result = types.ChatPermissions.de_json(json_dict) - assert result.can_send_messages == True - assert result.can_send_audios == True - assert result.can_send_documents == True - assert result.can_send_photos == True - assert result.can_send_videos == True - assert result.can_send_video_notes == True - assert result.can_send_voice_notes == True - assert result.can_send_polls == True - assert result.can_send_other_messages == True - assert result.can_add_web_page_previews == True - assert result.can_change_info == True - assert result.can_invite_users == True - assert result.can_pin_messages == True - assert result.can_manage_topics == True - assert result.can_edit_tag == True - assert result.can_react_to_messages == True - assert isinstance(result, types.ChatPermissions) - - -def test_json_chatmemberowner(): - json_dict = json.loads(r'{"status": "creator", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "is_anonymous": false}') - result = types.ChatMemberOwner.de_json(json_dict) - assert isinstance(result.user, types.User) - assert result.status == 'creator' - assert result.is_anonymous == False - assert isinstance(result, types.ChatMemberOwner) - - -def test_json_chatmemberadministrator(): - json_dict = json.loads(r'{"status": "administrator", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "is_anonymous": true, "can_be_edited": true, "can_manage_chat": true, "can_delete_messages": true, "can_manage_video_chats": true, "can_restrict_members": true, "can_promote_members": true, "can_change_info": true, "can_invite_users": true, "can_post_stories": true, "can_edit_stories": true, "can_delete_stories": true, "can_post_messages": true, "can_edit_messages": true, "can_pin_messages": true, "can_manage_topics": true, "can_manage_direct_messages": true, "can_manage_tags": true, "custom_title": "mod"}') - result = types.ChatMemberAdministrator.de_json(json_dict) - assert isinstance(result.user, types.User) - assert result.status == 'administrator' - assert result.can_be_edited == True - assert result.is_anonymous == True - assert result.can_manage_chat == True - assert result.can_delete_messages == True - assert result.can_manage_video_chats == True - assert result.can_restrict_members == True - assert result.can_promote_members == True - assert result.can_change_info == True - assert result.can_invite_users == True - assert result.can_post_stories == True - assert result.can_edit_stories == True - assert result.can_delete_stories == True - assert result.can_post_messages == True - assert result.can_edit_messages == True - assert result.can_pin_messages == True - assert result.can_manage_topics == True - assert result.custom_title == "mod" - assert result.can_manage_direct_messages == True - assert result.can_manage_tags == True - assert isinstance(result, types.ChatMemberAdministrator) - - -def test_json_chatmemberrestricted(): - json_dict = json.loads(r'{"status": "restricted", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "is_member": true, "can_send_messages": true, "can_send_audios": true, "can_send_documents": true, "can_send_photos": true, "can_send_videos": true, "can_send_video_notes": true, "can_send_voice_notes": true, "can_send_polls": true, "can_send_other_messages": true, "can_add_web_page_previews": true, "can_change_info": false, "can_invite_users": false, "can_pin_messages": false, "can_manage_topics": false, "until_date": 1682189507, "tag": "test_tag", "can_edit_tag": true, "can_react_to_messages": true}') - result = types.ChatMemberRestricted.de_json(json_dict) - assert isinstance(result.user, types.User) - assert result.status == 'restricted' - assert result.is_member == True - assert result.can_send_messages == True - assert result.can_send_audios == True - assert result.can_send_documents == True - assert result.can_send_photos == True - assert result.can_send_videos == True - assert result.can_send_video_notes == True - assert result.can_send_voice_notes == True - assert result.can_send_polls == True - assert result.can_send_other_messages == True - assert result.can_add_web_page_previews == True - assert result.can_change_info == False - assert result.can_invite_users == False - assert result.can_pin_messages == False - assert result.can_manage_topics == False - assert result.until_date == 1682189507 - assert result.tag == 'test_tag' - assert result.can_edit_tag == True - assert result.can_react_to_messages == True - assert isinstance(result, types.ChatMemberRestricted) - - -def test_json_chatmemberleft(): - json_dict = json.loads(r'{"status": "left", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}}') - result = types.ChatMemberLeft.de_json(json_dict) - assert isinstance(result.user, types.User) - assert result.status == 'left' - assert isinstance(result, types.ChatMemberLeft) - - -def test_json_chatmemberbanned(): - json_dict = json.loads(r'{"status": "kicked", "user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "until_date": 1682189507}') - result = types.ChatMemberBanned.de_json(json_dict) - assert isinstance(result.user, types.User) - assert result.status == 'kicked' - assert result.until_date == 1682189507 - assert isinstance(result, types.ChatMemberBanned) - - -def test_json_botcommand(): - json_dict = json.loads(r'{"command": "/start", "description": "Start command"}') - result = types.BotCommand.de_json(json_dict) - assert result.command == '/start' - assert result.description == 'Start command' - assert isinstance(result, types.BotCommand) - - -def test_json_botdescription(): - json_dict = json.loads(r'{"language_code": "en", "description": "Bot description"}') - result = types.BotDescription.de_json(json_dict) - assert result.description == 'Bot description' - assert isinstance(result, types.BotDescription) - - -def test_json_botname(): - json_dict = json.loads(r'{"language_code": "en", "name": "Bot Name"}') - result = types.BotName.de_json(json_dict) - assert result.name == 'Bot Name' - assert isinstance(result, types.BotName) - - -def test_json_botshortdescription(): - json_dict = json.loads(r'{"language_code": "en", "short_description": "Short"}') - result = types.BotShortDescription.de_json(json_dict) - assert result.short_description == 'Short' - assert isinstance(result, types.BotShortDescription) - - -def test_json_inlinekeyboardbutton(): - json_dict = json.loads(r'{"text": "Button", "url": "https://example.com", "callback_data": "data", "web_app": {"url": "https://example.com"}, "switch_inline_query": "query", "switch_inline_query_current_chat": "query", "switch_inline_query_chosen_chat": {"query": "q", "allow_user_chats": true, "allow_bot_chats": true, "allow_group_chats": true, "allow_channel_chats": true}, "pay": true, "login_url": {"url": "https://example.com", "forward_text": "Forward", "bot_username": "bot", "request_write_access": true}, "icon_custom_emoji_id": "emoji123", "style": "primary"}') - result = types.InlineKeyboardButton.de_json(json_dict) - assert result.text == 'Button' - assert result.url == 'https://example.com' - assert result.callback_data == 'data' - assert isinstance(result.web_app, types.WebAppInfo) - assert result.switch_inline_query == 'query' - assert result.switch_inline_query_current_chat == 'query' - assert isinstance(result.switch_inline_query_chosen_chat, types.SwitchInlineQueryChosenChat) - assert result.pay == True - assert isinstance(result.login_url, types.LoginUrl) - assert result.icon_custom_emoji_id == 'emoji123' - assert result.style == 'primary' - assert isinstance(result, types.InlineKeyboardButton) - - -def test_json_menubuttoncommands(): - json_dict = json.loads(r'{"type": "commands", "default_width": 100}') - result = types.MenuButtonCommands.de_json(json_dict) - assert result.type == 'commands' - assert isinstance(result, types.MenuButtonCommands) - - -def test_json_menubuttondefault(): - json_dict = json.loads(r'{"type": "default"}') - result = types.MenuButtonDefault.de_json(json_dict) - assert result.type == 'default' - assert isinstance(result, types.MenuButtonDefault) - - -def test_json_menubuttonwebapp(): - json_dict = json.loads(r'{"type": "web_app", "text": "Open App", "web_app": {"url": "https://example.com"}}') - result = types.MenuButtonWebApp.de_json(json_dict) - assert result.type == 'web_app' - assert result.text == 'Open App' - assert isinstance(result.web_app, dict) - assert isinstance(result, types.MenuButtonWebApp) - - -def test_json_pollanswer(): - json_dict = json.loads(r'{"poll_id": "poll_id", "option_ids": [0], "option_persistent_ids": [0], "user": {"id": 12345, "is_bot": false, "first_name": "Test"}, "voter_chat": {"id": 67890, "type": "channel", "title": "Channel"}}') - result = types.PollAnswer.de_json(json_dict) - assert result.poll_id == 'poll_id' - assert isinstance(result.option_ids, list) - assert isinstance(result.option_persistent_ids, list) - assert isinstance(result.user, types.User) - assert isinstance(result.voter_chat, types.Chat) - assert isinstance(result, types.PollAnswer) - - -def test_json_reactiontype(): - json_dict = json.loads(r'{"type": "emoji", "emoji": "\u2764\uFE0F"}') - result = types.ReactionType.de_json(json_dict) - assert result.type == 'emoji' - assert isinstance(result, types.ReactionType) - - -def test_reactiontypeemoji_to_dict(): - obj = types.ReactionTypeEmoji(emoji="😀") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_keyboardbutton_to_dict(): - obj = types.KeyboardButton(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_loginurl_to_dict(): - obj = types.LoginUrl(url="https://example.com") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_webappinfo_to_dict(): - obj = types.WebAppInfo(url="https://example.com") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_richtextbold_to_dict(): - obj = types.RichTextBold(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_richtextitalic_to_dict(): - obj = types.RichTextItalic(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_richtextunderline_to_dict(): - obj = types.RichTextUnderline(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_richtextstrikethrough_to_dict(): - obj = types.RichTextStrikethrough(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_richtextspoiler_to_dict(): - obj = types.RichTextSpoiler(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_richtextsubscript_to_dict(): - obj = types.RichTextSubscript(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_richtextsuperscript_to_dict(): - obj = types.RichTextSuperscript(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_richtextmarked_to_dict(): - obj = types.RichTextMarked(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_richtextcode_to_dict(): - obj = types.RichTextCode(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_richtextmathematicalexpression_to_dict(): - obj = types.RichTextMathematicalExpression(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_reactiontypecustomemoji_to_dict(): - obj = types.ReactionTypeCustomEmoji(custom_emoji_id="ce1") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_chatpermissions_to_dict(): - obj = types.ChatPermissions() - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inlinekeyboardbutton_to_dict(): - obj = types.InlineKeyboardButton(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_menubuttoncommands_to_dict(): - obj = types.MenuButtonCommands(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_menubuttondefault_to_dict(): - obj = types.MenuButtonDefault(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_richblockcaption_to_dict(): - obj = types.RichBlockCaption(text="caption") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_replyparameters_to_dict(): - obj = types.ReplyParameters(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_copypasswordbutton_to_dict(): - obj = types.CopyTextButton(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_linkpreviewoptionsto_dict(): - obj = types.LinkPreviewOptions(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_sentwebappmessageto_dict(): - obj = types.SentWebAppMessage(message_id=1) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_switchinlinequerychosenchat_to_dict(): - obj = types.SwitchInlineQueryChosenChat() - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_richtext_to_dict(): - obj = types.RichText(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_reactiontype_to_dict(): - obj = types.ReactionType(type="emoji") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_json_reactiontypepaid(): - json_dict = json.loads(r'{"type": "paid"}') - result = types.ReactionTypePaid.de_json(json_dict) - assert isinstance(result, types.ReactionTypePaid) - - -def test_json_businessbotrights(): - result = types.BusinessBotRights.de_json({}) - assert result.can_reply is None - assert result.can_read_messages is None - assert result.can_delete_outgoing_messages is None - assert result.can_delete_all_messages is None - assert result.can_edit_name is None - assert result.can_edit_bio is None - assert result.can_edit_profile_photo is None - assert result.can_edit_username is None - assert result.can_change_gift_settings is None - assert result.can_view_gifts_and_stars is None - assert result.can_convert_gifts_to_stars is None - assert result.can_transfer_and_upgrade_gifts is None - assert result.can_transfer_stars is None - assert result.can_manage_stories is None - assert isinstance(result, types.BusinessBotRights) - - -def test_json_businessintro(): - result = types.BusinessIntro.de_json({}) - assert isinstance(result, types.BusinessIntro) or result is None - - -def test_json_chatownerleft(): - result = types.ChatOwnerLeft.de_json({}) - assert isinstance(result, types.ChatOwnerLeft) or result is None - assert result.new_owner is None - - -def test_json_checklisttasksdone(): - result = types.ChecklistTasksDone.de_json({}) - assert isinstance(result, types.ChecklistTasksDone) or result is None - assert hasattr(result, 'marked_as_not_done_task_ids') - assert hasattr(result, 'marked_as_done_task_ids') - assert hasattr(result, 'checklist_message') - - -def test_json_communitychatadded(): - result = types.CommunityChatAdded.de_json({}) - assert isinstance(result, types.CommunityChatAdded) or result is None - assert result.community is None - - -def test_json_communitychatremoved(): - result = types.CommunityChatRemoved.de_json({}) - assert isinstance(result, types.CommunityChatRemoved) or result is None - - -def test_json_forumtopicclosed(): - result = types.ForumTopicClosed.de_json({}) - assert isinstance(result, types.ForumTopicClosed) or result is None - - -def test_json_forumtopicedited(): - result = types.ForumTopicEdited.de_json({}) - assert isinstance(result, types.ForumTopicEdited) or result is None - assert hasattr(result, 'icon_custom_emoji_id') - assert hasattr(result, 'name') - - -def test_json_forumtopicreopened(): - result = types.ForumTopicReopened.de_json({}) - assert isinstance(result, types.ForumTopicReopened) or result is None - - -def test_json_generalforumtopichidden(): - result = types.GeneralForumTopicHidden.de_json({}) - assert isinstance(result, types.GeneralForumTopicHidden) or result is None - - -def test_json_generalforumtopicunhidden(): - result = types.GeneralForumTopicUnhidden.de_json({}) - assert isinstance(result, types.GeneralForumTopicUnhidden) or result is None - - -def test_json_giveawaycreated(): - result = types.GiveawayCreated.de_json({}) - assert isinstance(result, types.GiveawayCreated) or result is None - assert hasattr(result, 'prize_star_count') - - -def test_json_linkpreviewoptions(): - result = types.LinkPreviewOptions.de_json({}) - assert result.is_disabled is None - assert result.url is None - assert result.prefer_small_media is None - assert result.prefer_large_media is None - assert result.show_above_text is None - assert isinstance(result, types.LinkPreviewOptions) - - -def test_json_orderinfo(): - json_dict = {'name': 'John', 'phone_number': '+1234567890', 'email': 'john@example.com', 'shipping_address': {'country_code': 'US', 'city': 'New York', 'street_line1': '123 Main St', 'street_line2': 'Apt 4B', 'postal_code': '10001', 'state': 'NY', 'post_code': '10001'}} - result = types.OrderInfo.de_json(json_dict) - assert result.name == 'John' - assert result.phone_number == '+1234567890' - assert result.email == 'john@example.com' - assert isinstance(result.shipping_address, types.ShippingAddress) - assert isinstance(result, types.OrderInfo) or result is None - assert hasattr(result, 'name') - assert hasattr(result, 'phone_number') - assert hasattr(result, 'email') - - -def test_json_pollmedia(): - json_dict = json.loads(r'{"animation": {"file_id": "a", "file_unique_id": "au", "width": 100, "height": 100, "duration": 10}, "audio": {"file_id": "au1", "file_unique_id": "au1u", "duration": 30}, "document": {"file_id": "d", "file_unique_id": "du", "file_name": "test.pdf"}, "live_photo": {"file_id": "lp", "file_unique_id": "lpu", "width": 100, "height": 100, "duration": 5}, "location": {"latitude": 50.45, "longitude": 30.52}, "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}], "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "venue": {"location": {"latitude": 50.45, "longitude": 30.52}, "title": "Place", "address": "Addr"}, "video": {"file_id": "v", "file_unique_id": "vu", "width": 640, "height": 480, "duration": 30}, "link": {"url": "https://example.com", "shows_above_caption": true, "enhanced_smileys": true, "prefer_large_media": true}}') - result = types.PollMedia.de_json(json_dict) - assert isinstance(result.animation, types.Animation) - assert isinstance(result.audio, types.Audio) - assert isinstance(result.document, types.Document) - assert isinstance(result.live_photo, types.LivePhoto) - assert isinstance(result.location, types.Location) - assert isinstance(result.photo, list) - assert isinstance(result.sticker, types.Sticker) - assert isinstance(result.venue, types.Venue) - assert isinstance(result.video, types.Video) - assert isinstance(result.link, types.Link) - assert isinstance(result, types.PollMedia) - - -def test_json_richblock(): - result = types.RichBlock.de_json({}) - assert isinstance(result, types.RichBlock) or result is None - - -def test_json_richblockdivider(): - result = types.RichBlockDivider.de_json({}) - assert isinstance(result, types.RichBlockDivider) or result is None - - -def test_json_richtext(): - result = types.RichText.de_json({}) - assert isinstance(result, types.RichText) or result is None - - -def test_json_sentwebappmessage(): - result = types.SentWebAppMessage.de_json({}) - assert isinstance(result, types.SentWebAppMessage) or result is None - assert hasattr(result, 'inline_message_id') - - -def test_json_suggestedpostdeclined(): - result = types.SuggestedPostDeclined.de_json({}) - assert isinstance(result, types.SuggestedPostDeclined) or result is None - assert hasattr(result, 'suggested_post_message') - - -def test_json_switchinlinequerychosenchat(): - json_dict = json.loads(r'{"query": "test", "allow_user_chats": true, "allow_bot_chats": true, "allow_group_chats": true, "allow_channel_chats": true}') - result = types.SwitchInlineQueryChosenChat.de_json(json_dict) - assert result.query == 'test' - assert result.allow_user_chats == True - assert result.allow_bot_chats == True - assert result.allow_group_chats == True - assert result.allow_channel_chats == True - assert isinstance(result, types.SwitchInlineQueryChosenChat) - - -def test_json_transactionpartnertelegramads(): - result = types.TransactionPartnerTelegramAds.de_json(None) - assert isinstance(result, types.TransactionPartnerTelegramAds) or result is None - - -def test_json_videochatstarted(): - result = types.VideoChatStarted.de_json({}) - assert isinstance(result, types.VideoChatStarted) or result is None - - -def test_json_voicechatstarted(): - result = types.VoiceChatStarted.de_json({}) - assert isinstance(result, types.VoiceChatStarted) or result is None - - -def test_json_writeaccessallowed(): - result = types.WriteAccessAllowed.de_json({}) - assert isinstance(result, types.WriteAccessAllowed) or result is None - assert hasattr(result, 'from_attachment_menu') - assert hasattr(result, 'web_app_name') - assert hasattr(result, 'from_request') - - -def test_acceptedgifttypes_to_dict(): - obj = types.AcceptedGiftTypes(unlimited_gifts=True, limited_gifts=True, unique_gifts=True, premium_subscription=True, gifts_from_channels=True) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_botcommand_to_dict(): - obj = types.BotCommand(command="/start", description="desc") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_chatadministratorrights_to_dict(): - obj = types.ChatAdministratorRights(is_anonymous=True, can_manage_chat=True, can_delete_messages=True, can_manage_video_chats=True, can_restrict_members=True, can_promote_members=True, can_change_info=True, can_invite_users=True) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_copytextbutton_to_dict(): - obj = types.CopyTextButton(text="copy") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_dice_to_dict(): - obj = types.Dice(emoji="🎯", value=6) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputcontactmessagecontent_to_dict(): - obj = types.InputContactMessageContent(phone_number="+123", first_name="Test") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputlocationmessagecontent_to_dict(): - obj = types.InputLocationMessageContent(latitude=50.0, longitude=30.0) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputmedialink_to_dict(): - obj = types.InputMediaLink(url="https://example.com") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputmedialocation_to_dict(): - obj = types.InputMediaLocation(latitude=50.0, longitude=30.0) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputmediasticker_to_dict(): - obj = types.InputMediaSticker(media="m") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputmediavenue_to_dict(): - obj = types.InputMediaVenue(latitude=50.0, longitude=30.0, title="T", address="A") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputpaidmedia_to_dict(): - obj = types.InputPaidMedia(type="photo", media="m") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputpaidmedialivephoto_to_dict(): - obj = types.InputPaidMediaLivePhoto(media="m", photo="p") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputpaidmediaphoto_to_dict(): - obj = types.InputPaidMediaPhoto(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputpaidmediavideo_to_dict(): - obj = types.InputPaidMediaVideo(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputprofilephotoanimated_to_dict(): - obj = types.InputProfilePhotoAnimated(animation="a") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputprofilephotostatic_to_dict(): - obj = types.InputProfilePhotoStatic(photo="p") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputrichblock_to_dict(): - obj = types.InputRichBlock(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputrichblockanchor_to_dict(): - obj = types.InputRichBlockAnchor(name="n") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputrichblockdivider_to_dict(): - obj = types.InputRichBlockDivider() - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputrichblockfooter_to_dict(): - obj = types.InputRichBlockFooter(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputrichblockmathematicalexpression_to_dict(): - obj = types.InputRichBlockMathematicalExpression(expression="x") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputrichblockparagraph_to_dict(): - obj = types.InputRichBlockParagraph(text="text") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputrichblockpreformatted_to_dict(): - obj = types.InputRichBlockPreformatted(text="text") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputrichblockpullquotation_to_dict(): - obj = types.InputRichBlockPullQuotation(text="text") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputrichblocksectionheading_to_dict(): - obj = types.InputRichBlockSectionHeading(text="T", size="large") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputrichblockthinking_to_dict(): - obj = types.InputRichBlockThinking(text="text") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputstorycontentphoto_to_dict(): - obj = types.InputStoryContentPhoto(photo="p") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputstorycontentvideo_to_dict(): - obj = types.InputStoryContentVideo(video="v") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputvenuemessagecontent_to_dict(): - obj = types.InputVenueMessageContent(latitude=50.0, longitude=30.0, title="T", address="A") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_keyboardbuttonpolltype_to_dict(): - obj = types.KeyboardButtonPollType() - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_keyboardbuttonrequestmanagedbot_to_dict(): - obj = types.KeyboardButtonRequestManagedBot(request_id=1) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_keyboardbuttonrequestuser_to_dict(): - obj = types.KeyboardButtonRequestUser(request_id=1) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_keyboardbuttonrequestusers_to_dict(): - obj = types.KeyboardButtonRequestUsers(request_id=1) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_labeledprice_to_dict(): - obj = types.LabeledPrice(label="L", amount=100) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_linkpreviewoptions_to_dict(): - obj = types.LinkPreviewOptions() - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_location_to_dict(): - obj = types.Location(latitude=50.0, longitude=30.0) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_locationaddress_to_dict(): - obj = types.LocationAddress(country_code="US") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_maskposition_to_dict(): - obj = types.MaskPosition(point="forehead", x_shift=0.0, y_shift=0.0, scale=0.5) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_pollanswer_to_dict(): - obj = types.PollAnswer(poll_id="p", option_ids=[0], option_persistent_ids=[0]) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_reactiontypepaid_to_dict(): - obj = types.ReactionTypePaid() - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_richblocktablecell_to_dict(): - obj = types.RichBlockTableCell(align="left", valign="top", text="cell") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_richtextanchor_to_dict(): - obj = types.RichTextAnchor(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_richtextanchorlink_to_dict(): - obj = types.RichTextAnchorLink(text="link", anchor_name="n") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_richtextbankcardnumber_to_dict(): - obj = types.RichTextBankCardNumber(text="1234", bank_card_number="1234") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_richtextbotcommand_to_dict(): - obj = types.RichTextBotCommand(text="/cmd", bot_command="/cmd") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_richtextcashtag_to_dict(): - obj = types.RichTextCashtag(text="#CASH", cashtag="#CASH") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_richtextcustomemoji_to_dict(): - obj = types.RichTextCustomEmoji(text="emoji", custom_emoji_id="ce1", alternative_text="alt") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_richtextdatetime_to_dict(): - obj = types.RichTextDateTime(text="2024-01-01", unix_time=1704067200, date_time_format="YYYY-MM-DD") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_richtextemailaddress_to_dict(): - obj = types.RichTextEmailAddress(text="t@e.com", email_address="t@e.com") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_richtexthashtag_to_dict(): - obj = types.RichTextHashtag(text="#test", hashtag="#test") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_richtextmention_to_dict(): - obj = types.RichTextMention(text="@u", username="u") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_richtextphonenumber_to_dict(): - obj = types.RichTextPhoneNumber(text="+123", phone_number="+123") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_richtextreference_to_dict(): - obj = types.RichTextReference(text="ref", name="n") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_richtextreferencelink_to_dict(): - obj = types.RichTextReferenceLink(text="ref", reference_name="n") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_richtexturl_to_dict(): - obj = types.RichTextUrl(text="url", url="https://example.com") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_sentwebappmessage_to_dict(): - obj = types.SentWebAppMessage(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_storyareaposition_to_dict(): - obj = types.StoryAreaPosition(x_percentage=0, y_percentage=0, width_percentage=0, height_percentage=0, rotation_angle=0, corner_radius_percentage=0) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_storyareatypelink_to_dict(): - obj = types.StoryAreaTypeLink(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_storyareatypeuniquegift_to_dict(): - obj = types.StoryAreaTypeUniqueGift(...) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_storyareatypeweather_to_dict(): - obj = types.StoryAreaTypeWeather(temperature="20", emoji="☀️", background_color="FFFFFF") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_suggestedpostprice_to_dict(): - obj = types.SuggestedPostPrice(currency="USD", amount=100) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_webappdata_to_dict(): - obj = types.WebAppData(data="test", button_text="Btn") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_json_acceptedgifttypes(): - json_dict = json.loads(r'{"unlimited_gifts": "test", "limited_gifts": "test", "unique_gifts": "test", "premium_subscription": "test", "gifts_from_channels": "test"}') - result = types.AcceptedGiftTypes.de_json(json_dict) - assert result.unlimited_gifts == 'test' - assert result.limited_gifts == 'test' - assert result.unique_gifts == 'test' - assert result.premium_subscription == 'test' - assert result.gifts_from_channels == 'test' - assert isinstance(result, types.AcceptedGiftTypes) - - -def test_json_copytextbutton(): - json_dict = json.loads(r'{"text": "Test"}') - result = types.CopyTextButton.de_json(json_dict) - assert result.text == 'Test' - assert isinstance(result, types.CopyTextButton) - - -def test_json_dice(): - json_dict = json.loads(r'{"value": "test", "emoji": "😀"}') - result = types.Dice.de_json(json_dict) - assert result.value == 'test' - assert result.emoji == '😀' - assert isinstance(result, types.Dice) - - -def test_json_richblocktablecell(): - json_dict = json.loads(r'{"align": "test", "valign": "test", "text": "Test", "is_header": true, "colspan": "test", "rowspan": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockTableCell.de_json(data) - assert result.align == 'test' - assert result.valign == 'test' - assert result.text == 'Test' - assert result.is_header == True - assert result.colspan == 'test' - assert result.rowspan == 'test' - assert isinstance(result, types.RichBlockTableCell) - - -def test_json_richtextbotcommand(): - json_dict = json.loads(r'{"type": "bot_command", "text": "Test", "bot_command": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichTextBotCommand.de_json(data) - assert result.text == 'Test' - assert result.bot_command == 'test' - assert isinstance(result, types.RichTextBotCommand) - - -def test_json_richtextcashtag(): - json_dict = json.loads(r'{"type": "cashtag", "text": "Test", "cashtag": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichTextCashtag.de_json(data) - assert result.text == 'Test' - assert result.cashtag == 'test' - assert isinstance(result, types.RichTextCashtag) - - -def test_json_richtextcustomemoji(): - json_dict = json.loads(r'{"type": "custom_emoji", "custom_emoji_id": "test", "alternative_text": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichTextCustomEmoji.de_json(data) - assert result.custom_emoji_id == 'test' - assert result.alternative_text == 'test' - assert isinstance(result, types.RichTextCustomEmoji) - - -def test_json_richtexthashtag(): - json_dict = json.loads(r'{"type": "hashtag", "text": "Test", "hashtag": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichTextHashtag.de_json(data) - assert result.text == 'Test' - assert result.hashtag == 'test' - assert isinstance(result, types.RichTextHashtag) - - -def test_json_richtextmathematicalexpression(): - json_dict = json.loads(r'{"type": "mathematical_expression", "expression": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichTextMathematicalExpression.de_json(data) - assert result.expression == 'test' - assert isinstance(result, types.RichTextMathematicalExpression) - - -def test_json_richtextmention(): - json_dict = json.loads(r'{"type": "mention", "text": "Test", "username": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichTextMention.de_json(data) - assert result.text == 'Test' - assert result.username == 'test' - assert isinstance(result, types.RichTextMention) - - -def test_json_richtextreference(): - json_dict = json.loads(r'{"type": "reference", "text": "Test", "name": "Test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichTextReference.de_json(data) - assert result.text == 'Test' - assert result.name == 'Test' - assert isinstance(result, types.RichTextReference) - - -def test_json_richtextreferencelink(): - json_dict = json.loads(r'{"type": "reference_link", "text": "Test", "reference_name": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichTextReferenceLink.de_json(data) - assert result.text == 'Test' - assert result.reference_name == 'test' - assert isinstance(result, types.RichTextReferenceLink) - - -def test_json_suggestedpostprice(): - json_dict = json.loads(r'{"currency": "en", "amount": 1}') - result = types.SuggestedPostPrice.de_json(json_dict) - assert result.currency == 'en' - assert result.amount == 1 - assert isinstance(result, types.SuggestedPostPrice) - - -def test_chat_location_to_dict(): - obj = types.ChatLocation(location=types.Location(latitude=50.0, longitude=30.0), address="Test") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputmedia_to_dict(): - obj = types.InputMediaPhoto(media="m") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputmediaanimation_to_dict(): - obj = types.InputMediaAnimation(media="m") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputmediaaudio_to_dict(): - obj = types.InputMediaAudio(media="m") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputmediadocument_to_dict(): - obj = types.InputMediaDocument(media="m") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputmedialivephoto_to_dict(): - obj = types.InputMediaLivePhoto(media="m", photo="p") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputmediaphoto_to_dict(): - obj = types.InputMediaPhoto(media="m") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputmediavideo_to_dict(): - obj = types.InputMediaVideo(media="m") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputmediavoicenote_to_dict(): - obj = types.InputMediaVoiceNote(media="m") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputsticker_to_dict(): - obj = types.InputSticker(sticker="s", emoji_list="test", format="static") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputtextmessagecontent_to_dict(): - obj = types.InputTextMessageContent(message_text="Test") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_messageentity_to_dict(): - obj = types.MessageEntity(type="bold", offset=0, length=5) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_richtexttextmention_to_dict(): - obj = types.RichTextTextMention(text="Test", user=types.User(id=1, is_bot=False, first_name="Test")) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_storyareatypesuggestedreaction_to_dict(): - obj = types.StoryAreaTypeSuggestedReaction(reaction_type=types.ReactionTypeEmoji(type="emoji", emoji="\U0001f600")) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_chatinvitelink_to_dict(): - obj = types.ChatInviteLink(invite_link="https://t.me/test", creator=types.User(id=1, is_bot=False, first_name="Test"), creates_join_request="test", is_primary=True, is_revoked=True, name="Test", expire_date=None, member_limit=None, pending_join_request_count=None) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_dictionaryable_to_dict(): - # Dictionaryable is an abstract base class, skip direct instantiation - pass - - -def test_inlinekeyboardmarkup_to_dict(): - obj = types.InlineKeyboardMarkup(keyboard=[[types.KeyboardButton(text="Test")]], row_width=3) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inlinequeryresultarticle_to_dict(): - obj = types.InlineQueryResultArticle(id=1, title="Test", input_message_content=types.InputTextMessageContent(message_text="Test"), reply_markup=types.InlineKeyboardMarkup(keyboard=[[types.InlineKeyboardButton(text="Test", callback_data="data")]]), url="https://example.com", hide_url="test", description="Test", thumbnail_url="test", thumbnail_width="test", thumbnail_height="test") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inlinequeryresultaudio_to_dict(): - obj = types.InlineQueryResultAudio(id=1, audio_url="test", title="Test", caption=types.RichTextBold(text="caption"), caption_entities="test", parse_mode=None, performer="test", audio_duration="test", reply_markup=types.InlineKeyboardMarkup(keyboard=[[types.InlineKeyboardButton(text="Test", callback_data="data")]]), input_message_content=types.InputTextMessageContent(message_text="Test")) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inlinequeryresultbase_to_dict(): - obj = types.InlineQueryResultBase(type="default", id=1, title="Test", caption=types.RichTextBold(text="caption"), input_message_content=types.InputTextMessageContent(message_text="Test"), reply_markup=types.InlineKeyboardMarkup(keyboard=[[types.InlineKeyboardButton(text="Test", callback_data="data")]]), caption_entities="test", parse_mode=None) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inlinequeryresultcontact_to_dict(): - obj = types.InlineQueryResultContact(id=1, phone_number="+1234567890", first_name="test", last_name="test", vcard="test", reply_markup=types.InlineKeyboardMarkup(keyboard=[[types.InlineKeyboardButton(text="Test", callback_data="data")]]), input_message_content=types.InputTextMessageContent(message_text="Test"), thumbnail_url="test", thumbnail_width="test", thumbnail_height="test") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inlinequeryresultdocument_to_dict(): - obj = types.InlineQueryResultDocument(id=1, title="Test", document_url="test", mime_type="application/pdf", caption=types.RichTextBold(text="caption"), caption_entities="test", parse_mode=None, description="Test", reply_markup=types.InlineKeyboardMarkup(keyboard=[[types.InlineKeyboardButton(text="Test", callback_data="data")]]), input_message_content=types.InputTextMessageContent(message_text="Test"), thumbnail_url="test", thumbnail_width="test", thumbnail_height="test") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inlinequeryresultgame_to_dict(): - obj = types.InlineQueryResultGame(id=1, game_short_name="test", reply_markup=types.InlineKeyboardMarkup(keyboard=[[types.InlineKeyboardButton(text="Test", callback_data="data")]])) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inlinequeryresultgif_to_dict(): - obj = types.InlineQueryResultGif(id=1, gif_url="test", thumbnail_url="test", gif_width="test", gif_height="test", title="Test", caption=types.RichTextBold(text="caption"), caption_entities="test", reply_markup=types.InlineKeyboardMarkup(keyboard=[[types.InlineKeyboardButton(text="Test", callback_data="data")]]), input_message_content=types.InputTextMessageContent(message_text="Test"), gif_duration="test", parse_mode=None, thumbnail_mime_type="test", show_caption_above_media="test") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inlinequeryresultlocation_to_dict(): - obj = types.InlineQueryResultLocation(id=1, title="Test", latitude=50.0, longitude=50.0, horizontal_accuracy="test", live_period="test", reply_markup=types.InlineKeyboardMarkup(keyboard=[[types.InlineKeyboardButton(text="Test", callback_data="data")]]), input_message_content=types.InputTextMessageContent(message_text="Test"), thumbnail_url="test", thumbnail_width="test", thumbnail_height="test", heading="test", proximity_alert_radius="test") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inlinequeryresultmpeg4gif_to_dict(): - obj = types.InlineQueryResultMpeg4Gif(id=1, mpeg4_url="test", thumbnail_url="test", mpeg4_width="test", mpeg4_height="test", title="Test", caption=types.RichTextBold(text="caption"), caption_entities="test", parse_mode=None, reply_markup=types.InlineKeyboardMarkup(keyboard=[[types.InlineKeyboardButton(text="Test", callback_data="data")]]), input_message_content=types.InputTextMessageContent(message_text="Test"), mpeg4_duration="test", thumbnail_mime_type="test", show_caption_above_media="test") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inlinequeryresultphoto_to_dict(): - obj = types.InlineQueryResultPhoto(id=1, photo_url=None, thumbnail_url="test", photo_width=None, photo_height=None, title="Test", description="Test", caption=types.RichTextBold(text="caption"), caption_entities="test", parse_mode=None, reply_markup=types.InlineKeyboardMarkup(keyboard=[[types.InlineKeyboardButton(text="Test", callback_data="data")]]), input_message_content=types.InputTextMessageContent(message_text="Test"), show_caption_above_media="test") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inlinequeryresultvenue_to_dict(): - obj = types.InlineQueryResultVenue(id=1, title="Test", latitude=50.0, longitude=50.0, address="Test St", foursquare_id="test", foursquare_type="test", google_place_id="test", google_place_type="test", reply_markup=types.InlineKeyboardMarkup(keyboard=[[types.InlineKeyboardButton(text="Test", callback_data="data")]]), input_message_content=types.InputTextMessageContent(message_text="Test"), thumbnail_url="test", thumbnail_width="test", thumbnail_height="test") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inlinequeryresultvideo_to_dict(): - obj = types.InlineQueryResultVideo(id=1, video_url="test", mime_type="application/pdf", thumbnail_url="test", title="Test", caption=types.RichTextBold(text="caption"), caption_entities="test", parse_mode=None, video_width="test", video_height="test", video_duration="test", description="Test", reply_markup=types.InlineKeyboardMarkup(keyboard=[[types.InlineKeyboardButton(text="Test", callback_data="data")]]), input_message_content=types.InputTextMessageContent(message_text="Test"), show_caption_above_media="test") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inlinequeryresultvoice_to_dict(): - obj = types.InlineQueryResultVoice(id=1, voice_url="test", title="Test", caption=types.RichTextBold(text="caption"), caption_entities="test", parse_mode=None, voice_duration="test", reply_markup=types.InlineKeyboardMarkup(keyboard=[[types.InlineKeyboardButton(text="Test", callback_data="data")]]), input_message_content=types.InputTextMessageContent(message_text="Test")) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inlinequeryresultsbutton_to_dict(): - obj = types.InlineQueryResultsButton(text="Test", web_app=types.WebAppInfo(url="https://example.com"), start_parameter="s") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputchecklist_to_dict(): - obj = types.InputChecklist(title="Test", tasks=[types.InputChecklistTask(id=1, text="Test")], parse_mode=None, title_entities=None, others_can_add_tasks=None, others_can_mark_tasks_as_done=None) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputchecklisttask_to_dict(): - obj = types.InputChecklistTask(id=1, text="Test", parse_mode=None, text_entities=None) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputinvoicemessagecontent_to_dict(): - obj = types.InputInvoiceMessageContent(title="Test", description="Test", payload="test", provider_token="pt", currency="en", prices=[types.LabeledPrice(label="L", amount=100)], max_tip_amount=None, suggested_tip_amounts=None, provider_data=None, photo_url=None, photo_size=types.PhotoSize(file_id="p", file_unique_id="pu", width=100, height=100), photo_width=None, photo_height=None, need_name=False, need_phone_number=False, need_email=False, need_shipping_address=False, send_phone_number_to_provider=False, send_email_to_provider=False, is_flexible=True) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputpolloption_to_dict(): - obj = types.InputPollOption(text="Test") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputrichblockanimation_to_dict(): - obj = types.InputRichBlockAnimation(animation=types.InputMediaAnimation(media="m")) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputrichblockaudio_to_dict(): - obj = types.InputRichBlockAudio(audio=types.InputMediaAudio(media="m")) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputrichblockblockquotation_to_dict(): - obj = types.InputRichBlockBlockQuotation(blocks=[types.InputRichBlockParagraph(text="Test")]) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputrichblockcollage_to_dict(): - obj = types.InputRichBlockCollage(blocks=[types.InputRichBlockParagraph(text="Test")]) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputrichblockdetails_to_dict(): - obj = types.InputRichBlockDetails(summary=types.RichTextBold(text="summary"), blocks=[types.InputRichBlockParagraph(text="Test")]) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputrichblocklist_to_dict(): - obj = types.InputRichBlockList(items=[types.InputRichBlockListItem(blocks=[types.InputRichBlockParagraph(text="Test")])]) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputrichblocklistitem_to_dict(): - obj = types.InputRichBlockListItem(blocks=[types.InputRichBlockParagraph(text="Test")]) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputrichblockmap_to_dict(): - obj = types.InputRichBlockMap(location=types.Location(latitude=50.0, longitude=30.0), zoom=1.0, width=100, height=100, caption=types.RichTextBold(text="caption")) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputrichblockphoto_to_dict(): - obj = types.InputRichBlockPhoto(photo=types.InputMediaPhoto(media="m")) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputrichblockslideshow_to_dict(): - obj = types.InputRichBlockSlideshow(blocks=[types.InputRichBlockParagraph(text="Test")]) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputrichblocktable_to_dict(): - obj = types.InputRichBlockTable(cells=[[types.RichBlockTableCell(align="left", valign="top", text="cell")]]) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputrichblockvideo_to_dict(): - obj = types.InputRichBlockVideo(video=types.InputMediaVideo(media="m")) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputrichblockvoicenote_to_dict(): - obj = types.InputRichBlockVoiceNote(voice_note=types.InputMediaVoiceNote(media="m")) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputrichmessage_to_dict(): - obj = types.InputRichMessage(html="Test") - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputrichmessagecontent_to_dict(): - obj = types.InputRichMessageContent(rich_message=types.InputRichMessage(html="Test")) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_inputrichmessagemedia_to_dict(): - obj = types.InputRichMessageMedia(id="m1", media=types.InputRichBlockPhoto(photo=types.InputMediaPhoto(media="m"))) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_keyboardbuttonrequestchat_to_dict(): - obj = types.KeyboardButtonRequestChat(request_id=1, chat_is_channel=False, chat_is_forum=False, chat_has_username=False, chat_is_created=False, user_administrator_rights=None, bot_administrator_rights=None, bot_is_member=False, request_title=None, request_photo=False, request_username=False) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_menubutton_to_dict(): - # MenuButton is an abstract base class, skip direct instantiation - pass - - -def test_menubuttonwebapp_to_dict(): - obj = types.MenuButtonWebApp(type="default", text="Test", web_app=types.WebAppInfo(url="https://example.com")) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_storyarea_to_dict(): - obj = types.StoryArea(position=types.StoryAreaPosition(x_percentage=0, y_percentage=0, width_percentage=0, height_percentage=0, rotation_angle=0, corner_radius_percentage=0), type=types.StoryAreaTypeLink(url="https://example.com")) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_storyareatypelocation_to_dict(): - obj = types.StoryAreaTypeLocation(latitude=50.0, longitude=50.0) - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_suggestedpostparameters_to_dict(): - obj = types.SuggestedPostParameters() - d = obj.to_dict() - assert isinstance(d, dict) - - -def test_json_affiliateinfo(): - json_dict = json.loads(r'{"commission_per_mille": 1000, "amount": 100, "affiliate_user": {"id": 1, "is_bot": false, "first_name": "User"}, "affiliate_chat": {"id": -1001234567890, "type": "channel", "title": "Channel"}, "nanostar_amount": 10000000}') - result = types.AffiliateInfo.de_json(json_dict) - assert result.commission_per_mille == 1000 - assert result.amount == 100 - assert isinstance(result.affiliate_user, types.User) - assert isinstance(result.affiliate_chat, types.Chat) - assert result.nanostar_amount == 10000000 - assert isinstance(result, types.AffiliateInfo) - - -def test_json_backgroundfill(): - # BackgroundFill is abstract - test BackgroundFillSolid directly - json_dict = json.loads(r'{"type": "solid", "color": 123456}') - result = types.BackgroundFillSolid.de_json(json_dict) - assert isinstance(result, types.BackgroundFillSolid) - - -def test_json_backgroundfillfreeformgradient(): - json_dict = json.loads(r'{"type": "freeform_gradient", "colors": [123456, 654321, 111222]}') - result = types.BackgroundFillFreeformGradient.de_json(json_dict) - assert result.type == 'freeform_gradient' - assert isinstance(result.colors, list) - assert isinstance(result, types.BackgroundFillFreeformGradient) - - -def test_json_backgroundfillgradient(): - json_dict = json.loads(r'{"type": "gradient", "top_color": 123456, "bottom_color": 654321, "rotation_angle": 180}') - result = types.BackgroundFillGradient.de_json(json_dict) - assert result.type == 'gradient' - assert result.top_color == 123456 - assert result.bottom_color == 654321 - assert result.rotation_angle == 180 - assert isinstance(result, types.BackgroundFillGradient) - - -def test_json_backgroundfillsolid(): - json_dict = json.loads(r'{"type": "solid", "color": 123456}') - result = types.BackgroundFillSolid.de_json(json_dict) - assert result.type == 'solid' - assert result.color == 123456 - assert isinstance(result, types.BackgroundFillSolid) - - -def test_json_backgroundtype(): - # BackgroundType is abstract - test BackgroundTypeFill directly - json_dict = json.loads(r'{"type": "fill", "fill": {"type": "solid", "color": 123456}, "dark_theme_dimming": 0}') - result = types.BackgroundTypeFill.de_json(json_dict) - assert isinstance(result, types.BackgroundTypeFill) - - -def test_json_backgroundtypechattheme(): - json_dict = json.loads(r'{"type": "fill", "theme_name": "test"}') - result = types.BackgroundTypeChatTheme.de_json(json_dict) - assert result.type == 'fill' - assert result.theme_name == 'test' - assert isinstance(result, types.BackgroundTypeChatTheme) - - -def test_json_backgroundtypefill(): - json_dict = json.loads(r'{"type": "solid", "fill": {"type": "solid", "color": 123456}, "dark_theme_dimming": 0}') - result = types.BackgroundTypeFill.de_json(json_dict) - assert result.type == 'solid' - assert isinstance(result.fill, types.BackgroundFill) - assert result.dark_theme_dimming == 0 - assert isinstance(result, types.BackgroundTypeFill) - - -def test_json_backgroundtypepattern(): - json_dict = json.loads(r'{"type": "pattern", "document": {"file_id": "doc", "file_unique_id": "docu", "mime_type": "application/pdf", "file_name": "test.pdf"}, "fill": {"type": "solid", "color": 123456}, "intensity": 0, "is_inverted": true, "is_moving": true}') - result = types.BackgroundTypePattern.de_json(json_dict) - assert result.type == 'pattern' - assert isinstance(result.document, types.Document) - assert isinstance(result.fill, dict) or result.fill is None - assert result.intensity == 0 - assert result.is_inverted == True - assert result.is_moving == True - assert isinstance(result, types.BackgroundTypePattern) - - -def test_json_backgroundtypewallpaper(): - json_dict = json.loads(r'{"type": "wallpaper", "document": {"file_id": "doc", "file_unique_id": "docu", "mime_type": "application/pdf", "file_name": "test.pdf"}, "dark_theme_dimming": 0, "is_blurred": true, "is_moving": true}') - result = types.BackgroundTypeWallpaper.de_json(json_dict) - assert result.type == 'wallpaper' - assert isinstance(result.document, types.Document) - assert result.dark_theme_dimming == 0 - assert result.is_blurred == True - assert result.is_moving == True - assert isinstance(result, types.BackgroundTypeWallpaper) - - -def test_json_birthdate(): - json_dict = json.loads(r'{"day": "test", "month": "test", "year": 1990}') - result = types.Birthdate.de_json(json_dict) - assert result.day == 'test' - assert result.month == 'test' - assert result.year == 1990 - assert isinstance(result, types.Birthdate) - - -def test_json_botaccesssettings(): - json_dict = json.loads(r'{"is_access_restricted": false}') - result = types.BotAccessSettings.de_json(json_dict) - assert result.is_access_restricted == False - assert isinstance(result, types.BotAccessSettings) - - -def test_json_botsubscriptionupdated(): - json_dict = json.loads(r'{"user": {"id": 1, "is_bot": false, "first_name": "Test"}, "invoice_payload": "test_payload", "state": "default"}') - result = types.BotSubscriptionUpdated.de_json(json_dict) - assert isinstance(result.user, types.User) - assert result.invoice_payload == 'test_payload' - assert result.state == 'default' - assert isinstance(result, types.BotSubscriptionUpdated) - - -def test_json_businessconnection(): - json_dict = json.loads(r'{"id": 1, "user": {"id": 1, "is_bot": false, "first_name": "Test"}, "user_chat_id": 1, "date": 1682189507, "is_enabled": false}') - result = types.BusinessConnection.de_json(json_dict) - assert result.id == 1 - assert isinstance(result.user, types.User) - assert result.user_chat_id == 1 - assert result.date == 1682189507 - assert result.is_enabled == False - assert isinstance(result, types.BusinessConnection) - - -def test_json_businesslocation(): - json_dict = json.loads(r'{"address": "test"}') - result = types.BusinessLocation.de_json(json_dict) - assert result.address == 'test' - assert isinstance(result, types.BusinessLocation) - - -def test_json_businessmessagesdeleted(): - json_dict = json.loads(r'{"business_connection_id": 1, "chat": {"id": 1, "type": "private", "title": "Test"}, "message_ids": "test"}') - result = types.BusinessMessagesDeleted.de_json(json_dict) - assert result.business_connection_id == 1 - assert isinstance(result.chat, types.Chat) - assert result.message_ids == 'test' - assert isinstance(result, types.BusinessMessagesDeleted) - - -def test_json_businessopeninghours(): - json_dict = json.loads(r'{"time_zone_name": "test", "opening_hours": [{"opening_minute": 0, "closing_minute": 60}]}') - result = types.BusinessOpeningHours.de_json(json_dict) - assert result.time_zone_name == 'test' - assert isinstance(result.opening_hours, list) - assert isinstance(result, types.BusinessOpeningHours) - - -def test_json_businessopeninghoursinterval(): - json_dict = json.loads(r'{"opening_minute": 0, "closing_minute": 60}') - result = types.BusinessOpeningHoursInterval.de_json(json_dict) - assert result.opening_minute == 0 - assert result.closing_minute == 60 - assert isinstance(result, types.BusinessOpeningHoursInterval) - - -def test_json_callbackquery(): - json_dict = json.loads(r'{"id": "cq1", "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "data": "test", "chat_instance": "ci1", "message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}, "text": "Hello"}, "inline_message_id": "im1", "game_short_name": "game"}') - result = types.CallbackQuery.de_json(json_dict) - assert result.id == 'cq1' - assert isinstance(result.from_user, types.User) - assert result.data == 'test' - assert result.chat_instance == 'ci1' - assert isinstance(result.message, types.Message) - assert result.inline_message_id == 'im1' - assert result.game_short_name == 'game' - assert isinstance(result, types.CallbackQuery) - - -def test_json_chatbackground(): - json_dict = json.loads(r'{"type": {"type": "fill", "fill": {"type": "solid", "color": 123456}, "dark_theme_dimming": 0}}') - result = types.ChatBackground.de_json(json_dict) - assert isinstance(result.type, types.BackgroundTypeFill) or isinstance(result.type, dict) - assert isinstance(result, types.ChatBackground) - assert hasattr(result, 'type') - - -def test_json_chatboostadded(): - json_dict = json.loads(r'{"boost_count": "test"}') - result = types.ChatBoostAdded.de_json(json_dict) - assert result.boost_count == 'test' - assert isinstance(result, types.ChatBoostAdded) - - -def test_json_chatboostremoved(): - json_dict = json.loads(r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "boost_id": 1, "remove_date": 1682189507, "source": {"source": "premium", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}}') - result = types.ChatBoostRemoved.de_json(json_dict) - assert isinstance(result.chat, types.Chat) - assert result.boost_id == 1 - assert result.remove_date == 1682189507 - assert isinstance(result.source, types.ChatBoostSource) - assert isinstance(result, types.ChatBoostRemoved) - - -def test_json_chatboostsource(): - # ChatBoostSource is abstract - test ChatBoostSourcePremium directly - json_dict = json.loads(r'{"source": "premium", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}') - result = types.ChatBoostSourcePremium.de_json(json_dict) - assert isinstance(result, types.ChatBoostSourcePremium) - - -def test_json_chatboostsourcegiftcode(): - json_dict = json.loads(r'{"source": "gift_code", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}') - result = types.ChatBoostSourceGiftCode.de_json(json_dict) - assert result.source == 'gift_code' - assert isinstance(result.user, types.User) - assert isinstance(result, types.ChatBoostSourceGiftCode) - - -def test_json_chatboostsourcegiveaway(): - json_dict = json.loads(r'{"source": "giveaway", "giveaway_message_id": 1, "user": {"id": 1, "is_bot": false, "first_name": "Test"}, "is_unclaimed": false, "prize_star_count": 100}') - result = types.ChatBoostSourceGiveaway.de_json(json_dict) - assert result.source == 'giveaway' - assert result.giveaway_message_id == 1 - assert isinstance(result.user, types.User) - assert result.is_unclaimed == False - assert result.prize_star_count == 100 - assert isinstance(result, types.ChatBoostSourceGiveaway) - - -def test_json_chatboostsourcepremium(): - json_dict = json.loads(r'{"source": "premium", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}') - result = types.ChatBoostSourcePremium.de_json(json_dict) - assert result.source == 'premium' - assert isinstance(result.user, types.User) - assert isinstance(result, types.ChatBoostSourcePremium) - - -def test_json_chatboostupdated(): - json_dict = json.loads(r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "boost": {"boost_item_id": "b1", "add_date": 1682189507, "expiration_date": 1682275907}}') - result = types.ChatBoostUpdated.de_json(json_dict) - assert isinstance(result.chat, types.Chat) - assert isinstance(result.boost, types.ChatBoost) - assert isinstance(result.boost.boost_id, str) or result.boost.boost_id is None - assert isinstance(result.boost.add_date, int) - assert isinstance(result.boost.expiration_date, int) - assert isinstance(result, types.ChatBoostUpdated) - - -def test_json_chatjoinrequest(): - json_dict = json.loads(r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "user_chat_id": 1, "date": 1682189507, "bio": "Hello", "invite_link": {"invite_link": "https://t.me/joinchat/ABC", "creator": {"id": 1, "is_bot": false, "first_name": "Test"}, "is_primary": true, "is_revoked": false, "creates_join_request": false}, "query_id": "query123"}') - result = types.ChatJoinRequest.de_json(json_dict) - assert isinstance(result.chat, types.Chat) - assert result.user_chat_id == 1 - assert result.date == 1682189507 - assert result.bio == 'Hello' - assert isinstance(result.invite_link, types.ChatInviteLink) - assert result.query_id == 'query123' - assert isinstance(result, types.ChatJoinRequest) - - -def test_json_chatfullinfo(): - json_dict = json.loads(r'{"id": 1, "type": "private", "title": "Test Chat", "username": "testchat", "first_name": "John", "last_name": "Doe", "photo": {"small_file_id": "s", "small_file_unique_id": "su", "big_file_id": "b", "big_file_unique_id": "bu"}, "bio": "bio text", "has_private_forwards": true, "description": "desc", "pinned_message": {"message_id": 1, "date": 1682189507, "chat": {"id": 1, "type": "private"}, "from": {"id": 1, "is_bot": false, "first_name": "User"}}, "permissions": {"can_send_messages": true, "can_send_audios": true, "can_send_documents": true, "can_send_photos": true, "can_send_videos": true, "can_send_video_notes": true, "can_send_voice_notes": true, "can_send_polls": true, "can_send_other_messages": true, "can_add_web_page_previews": true, "can_change_info": true, "can_invite_users": true, "can_pin_messages": true, "can_manage_topics": true}, "slow_mode_delay": 30, "message_auto_delete_time": 86400, "has_protected_content": true, "sticker_set_name": "sticker_set", "can_set_sticker_set": false, "linked_chat_id": 2, "location": {"chat": {"id": 1, "type": "supergroup", "title": "Loc"}, "location": {"latitude": 50.45, "longitude": 30.52}, "address": "Main St"}, "join_to_send_messages": false, "join_by_request": true, "has_restricted_voice_and_video_messages": false, "is_forum": true, "max_reaction_count": 10, "active_usernames": ["test"], "emoji_status_custom_emoji_id": "custom_emoji", "has_hidden_members": false, "has_aggressive_anti_spam_enabled": false, "emoji_status_expiration_date": 1682275907, "available_reactions": ["emoji", "custom_emoji"], "accent_color_id": 1, "background_custom_emoji_id": "bg_emoji", "profile_accent_color_id": 2, "profile_background_custom_emoji_id": "profile_bg", "has_visible_history": true, "unrestrict_boost_count": 5, "custom_emoji_sticker_set_name": "custom_stickers", "personal_chat": {"id": 3, "type": "private", "title": "Personal"}, "birthdate": {"day": "15", "month": "6"}, "can_send_paid_media": true, "is_direct_messages": true, "parent_chat": {"id": 4, "type": "supergroup", "title": "Parent"}, "rating": {"level": "test", "rating": "test", "current_level_rating": "test"}, "paid_message_star_count": 5, "invite_link": "https://t.me/joinchat/ABC", "business_intro": {"title": "B", "description": "D"}, "business_location": {"address": "NY", "has_active_address": true}, "business_opening_hours": {"time_zone_name": "UTC", "opening_hours": [{"opening_minute": 540, "closing_minute": 1020, "day_of_week": 1, "is_recurring": true}]}, "accepted_gift_types": {"unlimited_gifts": false, "limited_gifts": false, "unique_gifts": true, "premium_subscription": false, "gifts_from_channels": false}, "first_profile_audio": {"file_id": "fa1", "file_unique_id": "fa1u", "duration": 30, "mime_type": "audio/ogg"}}') - result = types.ChatFullInfo.de_json(json_dict) - assert result.id == 1 - assert result.type == 'private' - assert result.title == 'Test Chat' - assert result.username == 'testchat' - assert result.first_name == 'John' - assert result.last_name == 'Doe' - assert isinstance(result.photo, types.ChatPhoto) - assert result.bio == 'bio text' - assert result.has_private_forwards == True - assert result.description == 'desc' - assert result.invite_link == "https://t.me/joinchat/ABC" - assert isinstance(result.pinned_message, types.Message) - assert isinstance(result.permissions, types.ChatPermissions) - assert result.slow_mode_delay == 30 - assert result.message_auto_delete_time == 86400 - assert result.has_protected_content == True - assert result.sticker_set_name == 'sticker_set' - assert result.can_set_sticker_set == False - assert result.linked_chat_id == 2 - assert isinstance(result.location, types.ChatLocation) - assert result.join_to_send_messages == False - assert result.join_by_request == True - assert result.has_restricted_voice_and_video_messages == False - assert result.is_forum == True - assert result.max_reaction_count == 10 - assert result.active_usernames == ['test'] - assert result.emoji_status_custom_emoji_id == 'custom_emoji' - assert result.has_hidden_members == False - assert result.has_aggressive_anti_spam_enabled == False - assert result.emoji_status_expiration_date == 1682275907 - assert isinstance(result.available_reactions, list) - assert result.accent_color_id == 1 - assert result.background_custom_emoji_id == 'bg_emoji' - assert result.profile_accent_color_id == 2 - assert result.profile_background_custom_emoji_id == 'profile_bg' - assert result.has_visible_history == True - assert result.unrestrict_boost_count == 5 - assert result.custom_emoji_sticker_set_name == 'custom_stickers' - assert isinstance(result.business_intro, types.BusinessIntro) - assert isinstance(result.business_location, types.BusinessLocation) - assert isinstance(result.business_opening_hours, types.BusinessOpeningHours) - assert isinstance(result.personal_chat, types.Chat) - assert isinstance(result.birthdate, types.Birthdate) - assert result.can_send_paid_media == True - assert isinstance(result.accepted_gift_types, types.AcceptedGiftTypes) - assert result.is_direct_messages == True - assert isinstance(result.parent_chat, types.Chat) - assert isinstance(result.rating, types.UserRating) - assert result.paid_message_star_count == 5 - assert isinstance(result.first_profile_audio, types.Audio) - assert isinstance(result, types.ChatFullInfo) - - -def test_json_chatmember(): - # ChatMember is abstract - test ChatMemberMember directly - json_dict = json.loads(r'{"status": "member", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}') - result = types.ChatMemberMember.de_json(json_dict) - assert isinstance(result.user, types.User) - assert result.status == 'member' - assert isinstance(result, types.ChatMemberMember) - - -def test_json_chatmemberupdated(): - json_dict = json.loads(r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "date": 1682189507, "old_chat_member": {"user": {"id": 1, "is_bot": false, "first_name": "Test"}, "status": "member"}, "new_chat_member": {"user": {"id": 1, "is_bot": false, "first_name": "Test"}, "status": "member"}, "via_join_request": true, "via_chat_folder_invite_link": true}') - result = types.ChatMemberUpdated.de_json(json_dict) - assert isinstance(result.chat, types.Chat) - assert isinstance(result.from_user, types.User) - assert result.date == 1682189507 - assert isinstance(result.old_chat_member, types.ChatMember) - assert isinstance(result.new_chat_member, types.ChatMember) - assert result.via_join_request == True - assert result.via_chat_folder_invite_link == True - assert isinstance(result, types.ChatMemberUpdated) - - -def test_json_chatownerchanged(): - json_dict = json.loads(r'{"new_owner": {"id": 1, "is_bot": false, "first_name": "Test"}}') - result = types.ChatOwnerChanged.de_json(json_dict) - assert isinstance(result.new_owner, types.User) - assert isinstance(result, types.ChatOwnerChanged) - - -def test_json_chatphoto(): - json_dict = json.loads(r'{"small_file_id": 1, "small_file_unique_id": 1, "big_file_id": 1, "big_file_unique_id": 1}') - result = types.ChatPhoto.de_json(json_dict) - assert result.small_file_id == 1 - assert result.small_file_unique_id == 1 - assert result.big_file_id == 1 - assert result.big_file_unique_id == 1 - assert isinstance(result, types.ChatPhoto) - - -def test_json_checklist(): - json_dict = json.loads(r'{"title": "test", "tasks": [{"id": 1, "text": "test", "is_checked": false}], "others_can_add_tasks": true, "others_can_mark_tasks_as_done": true, "title_entities": [{"type": "bold", "offset": 0, "length": 4}]}') - result = types.Checklist.de_json(json_dict) - assert result.title == 'test' - assert isinstance(result.tasks, list) - assert isinstance(result.title_entities, list) - assert result.others_can_add_tasks == True - assert result.others_can_mark_tasks_as_done == True - assert isinstance(result, types.Checklist) - - -def test_json_checklisttask(): - json_dict = json.loads(r'{"id": 1, "text": {"type": "bold", "text": "Task text"}, "text_entities": [{"type": "bold", "offset": 0, "length": 9}], "completed_by_user": {"id": 1, "is_bot": false, "first_name": "User"}, "completed_by_chat": {"id": 1, "type": "private"}, "completion_date": 1682189507}') - result = types.ChecklistTask.de_json(json_dict) - assert result.id == 1 - assert result.text == {"type": "bold", "text": "Task text"} - assert isinstance(result.text_entities, list) - assert isinstance(result.completed_by_user, types.User) - assert isinstance(result.completed_by_chat, types.Chat) - assert result.completion_date == 1682189507 - assert isinstance(result, types.ChecklistTask) - - -def test_json_checklisttasksadded(): - json_dict = json.loads(r'{"tasks": [{"id": 1, "text": "task"}]}') - result = types.ChecklistTasksAdded.de_json(json_dict) - assert isinstance(result, types.ChecklistTasksAdded) - assert hasattr(result, 'checklist_message') - assert hasattr(result, 'tasks') - - -def test_json_choseninlineresult(): - json_dict = json.loads(r'{"result_id": 1, "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "query": "test"}') - result = types.ChosenInlineResult.de_json(json_dict) - assert isinstance(result, types.ChosenInlineResult) - assert hasattr(result, 'inline_message_id') - assert result.location is None - assert hasattr(result, 'query') - assert isinstance(result.from_user, types.User) - assert hasattr(result, 'result_id') - - -def test_json_community(): - json_dict = json.loads(r'{"id": 1, "name": "test"}') - result = types.Community.de_json(json_dict) - assert result.id == 1 - assert result.name == 'test' - assert isinstance(result, types.Community) - - -def test_json_directmessagepricechanged(): - json_dict = json.loads(r'{"are_direct_messages_enabled": "test"}') - result = types.DirectMessagePriceChanged.de_json(json_dict) - assert result.are_direct_messages_enabled == 'test' - assert isinstance(result, types.DirectMessagePriceChanged) - - -def test_json_directmessagestopic(): - json_dict = json.loads(r'{"topic_id": 1}') - result = types.DirectMessagesTopic.de_json(json_dict) - assert result.topic_id == 1 - assert isinstance(result, types.DirectMessagesTopic) - - -def test_json_externalreplyinfo(): - json_dict = json.loads(r'{"origin": {"type": "user", "date": 1682189507, "sender_user": {"id": 1, "is_bot": false, "first_name": "Test"}}, "chat": {"id": 1, "type": "private"}, "message_id": 42, "link_preview_options": {"url": "https://example.com", "shows_above_caption": true, "enhanced_smileys": true, "prefer_large_media": true}, "animation": {"file_id": "anim", "file_unique_id": "aniu", "width": 100, "height": 100, "duration": 10}, "audio": {"file_id": "au1", "file_unique_id": "au1u", "duration": 30}, "document": {"file_id": "doc1", "file_unique_id": "doc1u", "file_name": "test.pdf"}, "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}], "sticker": {"file_id": "st1", "file_unique_id": "st1u", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "story": {"chat": {"id": 1, "type": "private"}, "id": 1}, "video": {"file_id": "v1", "file_unique_id": "v1u", "width": 640, "height": 480, "duration": 30}, "video_note": {"file_id": "vn1", "file_unique_id": "vn1u", "duration": 10, "length": 512}, "voice": {"file_id": "vo1", "file_unique_id": "vo1u", "duration": 10}, "has_media_spoiler": true, "contact": {"phone_number": "+123", "first_name": "John"}, "dice": {"emoji": "🎲", "value": 5}, "game": {"id": "g1", "title": "Game", "description": "Test", "text": "Play", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}, "giveaway": {"chats": [{"id": 1, "type": "private"}], "winners_selection_date": 1682189507, "winner_count": 1, "only_new_members": false, "has_public_winners": false, "prize_description": "Prize", "premium_subscription_month_count": 0, "prize_star_count": 0}, "giveaway_winners": {"chat": {"id": 1, "type": "private"}, "giveaway_message_id": 1, "winners_selection_date": 1682189507, "winner_count": 1, "winners": [{"id": 1, "is_bot": false, "first_name": "Test"}], "additional_chat_count": 0, "premium_subscription_month_count": 0, "unclaimed_prize_count": 0, "only_new_members": false, "was_refunded": false, "prize_description": "", "prize_star_count": 0}, "invoice": {"title": "Test", "description": "Desc", "start_parameter": "sp", "currency": "USD", "total_amount": 100, "invoice_payload": "payload", "shipping_option_id": "opt", "order_info": {"user_name": "User", "user_phone": "+123", "shipping_address": {"country_code": "US", "state": "CA", "city": "SJ", "street_line1": "123", "street_line2": "", "post_code": "95113"}}, "telegram_payment_charge_id": "chg1", "provider_payment_charge_id": "chg2"}, "location": {"latitude": 50.45, "longitude": 30.52}, "venue": {"location": {"latitude": 50.45, "longitude": 30.52}, "title": "Place", "address": "Addr"}, "paid_media": {"star_count": 10, "paid_media": [{"type": "photo", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}]}, "live_photo": {"file_id": "lp1", "file_unique_id": "lp1u", "width": 100, "height": 100, "duration": 5}, "checklist": {"title": "Check", "tasks": [{"id": "t1", "text": "Task1", "status": "pending"}]}}') - result = types.ExternalReplyInfo.de_json(json_dict) - assert isinstance(result.origin, types.MessageOrigin) - assert isinstance(result.chat, types.Chat) - assert result.message_id == 42 - assert isinstance(result.link_preview_options, types.LinkPreviewOptions) - assert isinstance(result.animation, types.Animation) - assert isinstance(result.audio, types.Audio) - assert isinstance(result.document, types.Document) - assert isinstance(result.photo, list) - assert isinstance(result.sticker, types.Sticker) - assert isinstance(result.story, types.Story) - assert isinstance(result.video, types.Video) - assert isinstance(result.video_note, types.VideoNote) - assert isinstance(result.voice, types.Voice) - assert result.has_media_spoiler == True - assert isinstance(result.contact, types.Contact) - assert isinstance(result.dice, types.Dice) - assert isinstance(result.game, types.Game) - assert isinstance(result.giveaway, types.Giveaway) - assert isinstance(result.giveaway.chats, list) - assert result.giveaway.winner_count == 1 - assert isinstance(result.giveaway_winners, types.GiveawayWinners) - assert isinstance(result.invoice, types.Invoice) - assert isinstance(result.location, types.Location) - assert isinstance(result.venue, types.Venue) - assert isinstance(result.paid_media, types.PaidMediaInfo) - assert isinstance(result.live_photo, types.LivePhoto) - assert isinstance(result.checklist, types.Checklist) - assert isinstance(result, types.ExternalReplyInfo) - - -def test_json_file(): - json_dict = json.loads(r'{"file_id": "test_file_id", "file_unique_id": "test_unique_id", "file_size": 1024, "file_path": "docs/test.pdf"}') - result = types.File.de_json(json_dict) - assert result.file_id == 'test_file_id' - assert result.file_unique_id == 'test_unique_id' - assert result.file_size == 1024 - assert result.file_path == 'docs/test.pdf' - assert isinstance(result, types.File) - - -def test_json_forumtopiccreated(): - json_dict = json.loads(r'{"name": "test", "icon_color": 4294967295}') - result = types.ForumTopicCreated.de_json(json_dict) - assert result.name == 'test' - assert result.icon_color == 4294967295 - assert isinstance(result, types.ForumTopicCreated) - - -def test_json_game(): - json_dict = json.loads(r'{"id": "1", "title": "test", "description": "test", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}], "text": "game text", "animation": {"file_id": "anim", "file_unique_id": "aniu", "width": 100, "height": 100, "duration": 10}, "text_entities": [{"type": "bold", "offset": 0, "length": 4}]}') - result = types.Game.de_json(json_dict) - assert result.title == 'test' - assert result.description == 'test' - assert isinstance(result.photo, list) - assert result.text == 'game text' - assert isinstance(result.text_entities, list) - assert isinstance(result.animation, types.Animation) - assert isinstance(result, types.Game) - - -def test_json_gamehighscore(): - json_dict = json.loads(r'{"position": 0, "user": {"id": 1, "is_bot": false, "first_name": "Test"}, "score": 1}') - result = types.GameHighScore.de_json(json_dict) - assert isinstance(result, types.GameHighScore) - assert hasattr(result, 'score') - assert isinstance(result.user, types.User) - assert hasattr(result, 'position') - - -def test_json_giveaway(): - json_dict = json.loads(r'{"chats": [{"id": 1, "type": "private", "title": "Test"}], "winners_selection_date": 1682189507, "winner_count": 1, "only_new_members": true, "has_public_winners": false, "prize_description": "Prize", "country_codes": ["US", "GB"], "premium_subscription_month_count": 3, "prize_star_count": 100}') - result = types.Giveaway.de_json(json_dict) - assert isinstance(result.chats, list) - assert result.winners_selection_date == 1682189507 - assert result.winner_count == 1 - assert result.only_new_members == True - assert result.has_public_winners == False - assert result.prize_description == 'Prize' - assert isinstance(result.country_codes, list) - assert result.premium_subscription_month_count == 3 - assert result.prize_star_count == 100 - assert isinstance(result, types.Giveaway) - - -def test_json_giveawaycompleted(): - json_dict = json.loads(r'{"winner_count": 1}') - result = types.GiveawayCompleted.de_json(json_dict) - assert result.winner_count == 1 - assert isinstance(result, types.GiveawayCompleted) - - -def test_json_giveawaywinners(): - json_dict = json.loads(r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "giveaway_message_id": 1, "winners_selection_date": 1682189507, "winner_count": 1, "winners": [{"id": 1, "is_bot": false, "first_name": "Test"}], "additional_chat_count": 5, "premium_subscription_month_count": 3, "unclaimed_prize_count": 10, "only_new_members": true, "was_refunded": false, "prize_description": "Prize desc", "prize_star_count": 100}') - result = types.GiveawayWinners.de_json(json_dict) - assert isinstance(result.chat, types.Chat) - assert result.giveaway_message_id == 1 - assert result.winners_selection_date == 1682189507 - assert result.winner_count == 1 - assert isinstance(result.winners, list) - assert result.additional_chat_count == 5 - assert result.premium_subscription_month_count == 3 - assert result.unclaimed_prize_count == 10 - assert result.only_new_members == True - assert result.was_refunded == False - assert result.prize_description == 'Prize desc' - assert result.prize_star_count == 100 - assert isinstance(result, types.GiveawayWinners) - - -def test_json_groupchat(): - json_dict = json.loads(r'{"id": 1, "title": "test"}') - result = types.GroupChat.de_json(json_dict) - assert isinstance(result, types.GroupChat) - assert hasattr(result, 'title') - assert hasattr(result, 'id') - - -def test_json_inaccessiblemessage(): - json_dict = json.loads(r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "message_id": 1, "date": 1682189507}') - result = types.InaccessibleMessage.de_json(json_dict) - assert isinstance(result.chat, types.Chat) - assert result.message_id == 1 - assert result.date == 1682189507 - assert isinstance(result, types.InaccessibleMessage) - - -def test_json_inlinequery(): - json_dict = json.loads(r'{"id": "iq1", "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "query": "test", "offset": "off1", "chat_type": "private", "location": {"latitude": 50.45, "longitude": 30.52, "horizontal_accuracy": 1.5, "live_period": 3600}}') - result = types.InlineQuery.de_json(json_dict) - assert result.id == 'iq1' - assert isinstance(result.from_user, types.User) - assert result.query == 'test' - assert result.offset == 'off1' - assert result.chat_type == 'private' - assert isinstance(result.location, types.Location) - assert isinstance(result, types.InlineQuery) - - -def test_json_invoice(): - json_dict = json.loads(r'{"title": "test", "description": "test", "start_parameter": "test_sp", "currency": "test", "total_amount": 1}') - result = types.Invoice.de_json(json_dict) - assert result.title == 'test' - assert result.description == 'test' - assert result.start_parameter == 'test_sp' - assert result.currency == 'test' - assert result.total_amount == 1 - assert isinstance(result, types.Invoice) - - -def test_json_jsondeserializable(): - # JsonDeserializable is abstract base class, skip - pass - - -def test_json_link(): - json_dict = json.loads(r'{"url": "https://example.com"}') - result = types.Link.de_json(json_dict) - assert result.url == 'https://example.com' - assert isinstance(result, types.Link) - - -def test_json_livephoto(): - json_dict = json.loads(r'{"file_id": "test_file_id", "file_unique_id": "test_unique_id", "width": 100, "height": 100, "duration": 30, "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}], "mime_type": "image/jpeg", "file_size": 20480}') - result = types.LivePhoto.de_json(json_dict) - assert result.file_id == 'test_file_id' - assert result.file_unique_id == 'test_unique_id' - assert result.width == 100 - assert result.height == 100 - assert result.duration == 30 - assert isinstance(result.photo, list) - assert result.mime_type == 'image/jpeg' - assert result.file_size == 20480 - assert isinstance(result, types.LivePhoto) - - -def test_json_managedbotcreated(): - json_dict = json.loads(r'{"bot": {"id": 1, "is_bot": true, "first_name": "Bot"}}') - result = types.ManagedBotCreated.de_json(json_dict) - assert isinstance(result, types.ManagedBotCreated) - assert hasattr(result, 'bot') - - -def test_json_managedbotupdated(): - json_dict = json.loads(r'{"user": {"id": 1, "is_bot": false, "first_name": "Test"}, "bot": {"id": 1, "is_bot": true, "first_name": "Bot"}}') - result = types.ManagedBotUpdated.de_json(json_dict) - assert isinstance(result, types.ManagedBotUpdated) - assert hasattr(result, 'bot') - assert isinstance(result.user, types.User) - - -def test_json_menubutton(): - # MenuButton dispatches on type - test concrete subclass - json_dict = json.loads(r'{"type": "default"}') - result = types.MenuButtonDefault.de_json(json_dict) - assert isinstance(result, types.MenuButtonDefault) - - -def test_json_messageautodeletetimerchanged(): - json_dict = json.loads(r'{"message_auto_delete_time": 60}') - result = types.MessageAutoDeleteTimerChanged.de_json(json_dict) - assert result.message_auto_delete_time == 60 - assert isinstance(result, types.MessageAutoDeleteTimerChanged) - - -def test_json_messageid(): - json_dict = json.loads(r'{"message_id": 1}') - result = types.MessageID.de_json(json_dict) - assert isinstance(result, types.MessageID) - - -def test_json_messageorigin(): - # MessageOrigin is abstract - test MessageOriginUser directly - json_dict = json.loads(r'{"type": "user", "date": 1682189507, "sender_user": {"id": 1, "is_bot": false, "first_name": "Test"}}') - result = types.MessageOriginUser.de_json(json_dict) - assert result.type == 'user' - assert result.date == 1682189507 - assert isinstance(result, types.MessageOriginUser) - - -def test_json_messagereactioncountupdated(): - json_dict = json.loads(r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "message_id": 1, "date": 1682189507, "reactions": [{"type": {"type": "emoji", "emoji": "\u2764\ufe0f"}, "total_count": 5}]}') - result = types.MessageReactionCountUpdated.de_json(json_dict) - assert isinstance(result.chat, types.Chat) - assert result.message_id == 1 - assert result.date == 1682189507 - assert isinstance(result.reactions, list) - assert isinstance(result, types.MessageReactionCountUpdated) - - -def test_json_messagereactionupdated(): - json_dict = json.loads(r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "message_id": 1, "date": 1682189507, "old_reaction": [{"type": "emoji", "emoji": "\u0001f600"}], "new_reaction": [{"type": "emoji", "emoji": "\u0001f600"}]}') - result = types.MessageReactionUpdated.de_json(json_dict) - assert isinstance(result.chat, types.Chat) - assert result.message_id == 1 - assert result.date == 1682189507 - assert isinstance(result.old_reaction, list) - assert isinstance(result.new_reaction, list) - assert isinstance(result, types.MessageReactionUpdated) - - -def test_json_ownedgift(): - # OwnedGift is abstract - test OwnedGiftRegular directly - json_dict = json.loads(r'{"type": "regular", "gift": {"id": 1, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100}}') - result = types.OwnedGiftRegular.de_json(json_dict) - assert result.type == 'regular' - assert isinstance(result, types.OwnedGiftRegular) - - -def test_json_ownedgiftregular(): - json_dict = json.loads(r'{"type": "regular", "gift": {"id": 1, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100}, "owned_gift_id": "og_123", "sender_user": {"id": 1, "is_bot": false, "first_name": "Sender"}, "send_date": 1682189507, "text": {"type": "bold", "text": "Gift text"}, "entities": [{"type": "bold", "offset": 0, "length": 4}], "is_private": false, "is_saved": false, "can_be_upgraded": true, "was_refunded": false, "convert_star_count": 50, "prepaid_upgrade_star_count": 100, "is_upgrade_separate": false, "unique_gift_number": 42}') - result = types.OwnedGiftRegular.de_json(json_dict) - assert result.type == 'regular' - assert isinstance(result.gift, types.Gift) - assert result.owned_gift_id == 'og_123' - assert isinstance(result.sender_user, types.User) - assert result.send_date == 1682189507 - assert isinstance(result.text, dict) - assert isinstance(result.entities, list) - assert result.is_private == False - assert result.is_saved == False - assert result.can_be_upgraded == True - assert result.was_refunded == False - assert result.convert_star_count == 50 - assert result.prepaid_upgrade_star_count == 100 - assert result.is_upgrade_separate == False - assert result.unique_gift_number == 42 - assert isinstance(result, types.OwnedGiftRegular) - - -def test_json_ownedgiftunique(): - json_dict = json.loads(r'{"type": "unique", "gift": {"base_name": "test", "name": "test", "number": 1, "model": {"name": "m", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "symbol": {"name": "s", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "backdrop": {"name": "b", "colors": {"center_color": 123456, "edge_color": 654321, "symbol_color": 111111, "text_color": 222222}, "rarity_per_mille": 1000}, "gift_id": 1}, "gift_id": 1, "owned_gift_id": "og_456", "sender_user": {"id": 2, "is_bot": false, "first_name": "Sender"}, "send_date": 1682189507, "is_saved": false, "can_be_transferred": true, "transfer_star_count": 50, "next_transfer_date": 1704067200}') - result = types.OwnedGiftUnique.de_json(json_dict) - assert result.type == 'unique' - assert isinstance(result.gift, types.UniqueGift) - assert result.owned_gift_id == 'og_456' - assert isinstance(result.sender_user, types.User) - assert result.send_date == 1682189507 - assert result.is_saved == False - assert result.can_be_transferred == True - assert result.transfer_star_count == 50 - assert result.next_transfer_date == 1704067200 - assert isinstance(result, types.OwnedGiftUnique) - - -def test_json_ownedgifts(): - json_dict = json.loads(r'{"total_count": 1, "gifts": [{"type": "regular", "gift": {"id": 1, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100}}]}') - result = types.OwnedGifts.de_json(json_dict) - assert result.total_count == 1 - assert isinstance(result.gifts, list) - assert isinstance(result, types.OwnedGifts) - - -def test_json_paidmedia(): - # PaidMedia is abstract - test PaidMediaPhoto directly - json_dict = json.loads(r'{"type": "photo", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}') - result = types.PaidMediaPhoto.de_json(json_dict) - assert isinstance(result, types.PaidMediaPhoto) - - -def test_json_paidmediainfo(): - json_dict = json.loads(r'{"star_count": 100, "paid_media": [{"type": "photo", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}]}') - result = types.PaidMediaInfo.de_json(json_dict) - assert result.star_count == 100 - assert isinstance(result.paid_media, list) - assert isinstance(result, types.PaidMediaInfo) - - -def test_json_paidmedialivephoto(): - json_dict = json.loads(r'{"type": "live_photo", "live_photo": {"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100, "duration": 10}}') - result = types.PaidMediaLivePhoto.de_json(json_dict) - assert result.type == 'live_photo' - assert isinstance(result.live_photo, types.LivePhoto) - assert isinstance(result, types.PaidMediaLivePhoto) - - -def test_json_paidmediaphoto(): - json_dict = json.loads(r'{"type": "photo", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}') - result = types.PaidMediaPhoto.de_json(json_dict) - assert result.type == 'photo' - assert isinstance(result.photo, list) - assert isinstance(result, types.PaidMediaPhoto) - - -def test_json_paidmediapreview(): - json_dict = json.loads(r'{"type": "default"}') - result = types.PaidMediaPreview.de_json(json_dict) - assert result.type == 'default' - assert isinstance(result, types.PaidMediaPreview) - - -def test_json_paidmediapurchased(): - json_dict = json.loads(r'{"from_user": {"id": 1, "is_bot": false, "first_name": "Test"}, "paid_media_payload": "test"}') - result = types.PaidMediaPurchased.de_json(json_dict) - assert isinstance(result.from_user, types.User) - assert result.paid_media_payload == 'test' - assert isinstance(result, types.PaidMediaPurchased) - - -def test_json_paidmediavideo(): - json_dict = json.loads(r'{"type": "video", "video": {"file_id": "v", "file_unique_id": "vu", "width": 640, "height": 480, "duration": 30}}') - result = types.PaidMediaVideo.de_json(json_dict) - assert result.type == 'video' - assert isinstance(result.video, types.Video) - assert isinstance(result, types.PaidMediaVideo) - - -def test_json_paidmessagepricechanged(): - json_dict = json.loads(r'{"paid_message_star_count": 1}') - result = types.PaidMessagePriceChanged.de_json(json_dict) - assert isinstance(result, types.PaidMessagePriceChanged) - assert hasattr(result, 'paid_message_star_count') - - -def test_json_poll(): - json_dict = json.loads(r'{"id": "poll1", "question": "test question", "options": [{"text": "Opt1", "persistent_id": "opt1"}], "total_voter_count": 10, "is_closed": false, "is_anonymous": true, "type": "quiz", "allows_multiple_answers": false, "explanation": "explanation text", "explanation_entities": [{"type": "bold", "offset": 0, "length": 4}], "open_period": 3600, "close_date": 1682193107, "question_entities": [{"type": "bold", "offset": 0, "length": 5}], "correct_option_ids": [0], "allows_revoting": true, "description": "poll desc", "description_entities": [{"type": "italic", "offset": 0, "length": 9}], "members_only": true, "country_codes": ["US", "GB"], "explanation_media": {"file_id": "em1", "file_unique_id": "emu1", "mime_type": "image/jpeg", "file_name": "media.jpg"}}') - result = types.Poll.de_json(json_dict) - assert result.question == 'test question' - assert isinstance(result.options, list) - assert result.total_voter_count == 10 - assert result.is_closed == False - assert result.is_anonymous == True - assert result.type == 'quiz' - assert result.allows_multiple_answers == False - assert result.explanation == 'explanation text' - assert isinstance(result.explanation_entities, list) - assert result.open_period == 3600 - assert result.close_date == 1682193107 - assert isinstance(result.question_entities, list) - assert isinstance(result.correct_option_ids, list) - assert result.allows_revoting == True - assert result.description == 'poll desc' - assert isinstance(result.description_entities, list) - assert result.members_only == True - assert isinstance(result.country_codes, list) - assert isinstance(result.explanation_media, types.PollMedia) - assert result.id == 'poll1' - assert isinstance(result, types.Poll) - - -def test_json_polloption(): - json_dict = json.loads(r'{"text": "test", "persistent_id": 1, "voter_count": 5, "text_entities": [{"type": "bold", "offset": 0, "length": 4}], "added_by_user": {"id": 12345, "is_bot": false, "first_name": "Test"}}') - result = types.PollOption.de_json(json_dict) - assert result.text == 'test' - assert result.persistent_id == 1 - assert result.voter_count == 5 - assert isinstance(result.text_entities, list) - assert isinstance(result.added_by_user, types.User) - assert result.added_by_user.id == 12345 - assert result.media is None - assert isinstance(result, types.PollOption) - - -def test_json_polloptionadded(): - json_dict = json.loads(r'{"option_persistent_id": 1, "option_text": "test"}') - result = types.PollOptionAdded.de_json(json_dict) - assert result.option_persistent_id == 1 - assert result.option_text == 'test' - assert isinstance(result, types.PollOptionAdded) - - -def test_json_polloptiondeleted(): - json_dict = json.loads(r'{"option_persistent_id": 1, "option_text": "test"}') - result = types.PollOptionDeleted.de_json(json_dict) - assert result.option_persistent_id == 1 - assert result.option_text == 'test' - assert isinstance(result, types.PollOptionDeleted) - - -def test_json_precheckoutquery(): - json_dict = json.loads(r'{"id": 1, "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "currency": "USD", "total_amount": 1234, "invoice_payload": "test_payload", "shipping_option_id": "opt1", "order_info": {"user_name": "Buyer", "user_phone": "+123", "shipping_address": {"country_code": "US", "state": "CA", "city": "San Jose", "street_line1": "123 Main St", "street_line2": "", "post_code": "95113"}}}') - result = types.PreCheckoutQuery.de_json(json_dict) - assert result.id == 1 - assert isinstance(result.from_user, types.User) - assert result.currency == 'USD' - assert result.total_amount == 1234 - assert result.invoice_payload == 'test_payload' - assert result.shipping_option_id == 'opt1' - assert isinstance(result.order_info, types.OrderInfo) - assert isinstance(result, types.PreCheckoutQuery) - - -def test_json_preparedinlinemessage(): - json_dict = json.loads(r'{"id": 1, "expiration_date": 1682189507}') - result = types.PreparedInlineMessage.de_json(json_dict) - assert isinstance(result, types.PreparedInlineMessage) - assert hasattr(result, 'expiration_date') - assert hasattr(result, 'id') - - -def test_json_preparedkeyboardbutton(): - json_dict = json.loads(r'{"id": 1}') - result = types.PreparedKeyboardButton.de_json(json_dict) - assert result.id == 1 - assert isinstance(result, types.PreparedKeyboardButton) - - -def test_json_proximityalerttriggered(): - json_dict = json.loads(r'{"traveler": {"id": 1, "is_bot": false, "first_name": "Test"}, "watcher": {"id": 1, "is_bot": false, "first_name": "Test"}, "distance": "test"}') - result = types.ProximityAlertTriggered.de_json(json_dict) - assert isinstance(result.traveler, dict) - assert isinstance(result.watcher, dict) - assert result.distance == 'test' - assert isinstance(result, types.ProximityAlertTriggered) - - -def test_json_refundedpayment(): - json_dict = json.loads(r'{"currency": "USD", "total_amount": 100, "invoice_payload": "test_payload", "telegram_payment_charge_id": "chg1", "provider_payment_charge_id": "chg2"}') - result = types.RefundedPayment.de_json(json_dict) - assert result.currency == 'USD' - assert result.total_amount == 100 - assert result.invoice_payload == 'test_payload' - assert result.telegram_payment_charge_id == 'chg1' - assert result.provider_payment_charge_id == 'chg2' - assert isinstance(result, types.RefundedPayment) - - -def test_json_revenuewithdrawalstate(): - # RevenueWithdrawalState is abstract - test RevenueWithdrawalStatePending directly - json_dict = json.loads(r'{"type": "pending"}') - result = types.RevenueWithdrawalStatePending.de_json(json_dict) - assert isinstance(result, types.RevenueWithdrawalStatePending) - - -def test_json_revenuewithdrawalstatefailed(): - json_dict = json.loads(r'{"type": "failed"}') - result = types.RevenueWithdrawalStateFailed.de_json(json_dict) - assert result.type == 'failed' - assert isinstance(result, types.RevenueWithdrawalStateFailed) - - -def test_json_revenuewithdrawalstatepending(): - json_dict = json.loads(r'{"type": "pending"}') - result = types.RevenueWithdrawalStatePending.de_json(json_dict) - assert result.type == 'pending' - assert isinstance(result, types.RevenueWithdrawalStatePending) - - -def test_json_revenuewithdrawalstatesucceeded(): - json_dict = json.loads(r'{"type": "succeeded", "date": 1682189507, "url": "https://example.com"}') - result = types.RevenueWithdrawalStateSucceeded.de_json(json_dict) - assert result.type == 'succeeded' - assert result.date == 1682189507 - assert result.url == 'https://example.com' - assert isinstance(result, types.RevenueWithdrawalStateSucceeded) - - -def test_json_richblockanchor(): - json_dict = json.loads(r'{"name": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockAnchor.de_json(data) - assert result.name == 'test' - assert isinstance(result, types.RichBlockAnchor) - - -def test_json_richblockaudio(): - json_dict = json.loads(r'{"audio": {"file_id": "a", "file_unique_id": "au", "duration": 30}, "caption": {"type": "bold", "text": "audio caption"}}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockAudio.de_json(data) - assert isinstance(result.audio, types.Audio) - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockAudio) - - -def test_json_richblockblockquotation(): - json_dict = json.loads(r'{"blocks": [{"text": "Test"}]}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockBlockQuotation.de_json(data) - assert isinstance(result.blocks, list) - assert isinstance(result, types.RichBlockBlockQuotation) - assert hasattr(result, 'credit') - assert hasattr(result, 'blocks') - - -def test_json_richblockcollage(): - json_dict = json.loads(r'{"blocks": [{"text": "Test"}]}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockCollage.de_json(data) - assert isinstance(result.blocks, list) - assert isinstance(result, types.RichBlockCollage) - assert hasattr(result, 'caption') - assert hasattr(result, 'blocks') - - -def test_json_richblocklist(): - json_dict = json.loads(r'{"items": [{"type": "list_item", "label": {"text": "label"}, "blocks": [{"text": "Test"}]}]}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockList.de_json(data) - assert isinstance(result.items, list) - assert isinstance(result, types.RichBlockList) - assert hasattr(result, 'items') - - -def test_json_richblockmap(): - json_dict = json.loads(r'{"location": {"latitude": 50.0, "longitude": 30.0}, "zoom": 1.0, "width": 100, "height": 100}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichBlockMap.de_json(data) - assert isinstance(result.location, types.Location) - assert result.zoom == 1.0 - assert result.width == 100 - assert result.height == 100 - assert isinstance(result, types.RichBlockMap) - - -def test_json_richblockmathematicalexpression(): - json_dict = json.loads(r'{"expression": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockMathematicalExpression.de_json(data) - assert result.expression == 'test' - assert isinstance(result, types.RichBlockMathematicalExpression) - - -def test_json_richblockphoto(): - json_dict = json.loads(r'{"photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}], "has_spoiler": true}') - data = {k: v for k, v in json_dict.items() if k != "type"} - result = types.RichBlockPhoto.de_json(data) - assert isinstance(result.photo, list) - assert result.has_spoiler == True - assert isinstance(result, types.RichBlockPhoto) - - -def test_json_richblockpullquotation(): - json_dict = json.loads(r'{"text": "test quote", "credit": "Author Name"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockPullQuotation.de_json(data) - assert result.text == 'test quote' - assert result.credit == 'Author Name' - assert isinstance(result, types.RichBlockPullQuotation) - - -def test_json_richblocksectionheading(): - json_dict = json.loads(r'{"text": "test", "size": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockSectionHeading.de_json(data) - assert result.text == 'test' - assert result.size == 'test' - assert isinstance(result, types.RichBlockSectionHeading) - - -def test_json_richblockslideshow(): - json_dict = json.loads(r'{"blocks": [{"text": "Test"}], "caption": {"type": "bold", "text": "slide caption"}}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockSlideshow.de_json(data) - assert isinstance(result.blocks, list) - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockSlideshow) - assert hasattr(result, 'caption') - assert hasattr(result, 'blocks') - - -def test_json_richblocktable(): - json_dict = json.loads(r'{"cells": [[{"align": "left", "valign": "top", "text": "cell", "is_header": false, "colspan": 1, "rowspan": 1}]], "is_bordered": true, "is_striped": true, "caption": {"type": "bold", "text": "table caption"}}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockTable.de_json(data) - assert isinstance(result.cells, list) - assert result.is_bordered == True - assert result.is_striped == True - assert isinstance(result.caption, types.RichText) - assert isinstance(result, types.RichBlockTable) - assert hasattr(result, 'is_striped') - assert hasattr(result, 'is_bordered') - assert hasattr(result, 'cells') - - -def test_json_richblockthinking(): - json_dict = json.loads(r'{"text": "test"}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockThinking.de_json(data) - assert result.text == 'test' - assert isinstance(result, types.RichBlockThinking) - - -def test_json_richblockvideo(): - json_dict = json.loads(r'{"video": {"file_id": "v", "file_unique_id": "vu", "width": 640, "height": 480, "duration": 30}, "has_spoiler": true, "caption": {"type": "bold", "text": "video caption"}}') - data = {k: v for k, v in json_dict.items() if k != 'type'} - result = types.RichBlockVideo.de_json(data) - assert isinstance(result.video, types.Video) - assert result.has_spoiler == True - assert isinstance(result.caption, types.RichBlockCaption) - assert isinstance(result, types.RichBlockVideo) - assert hasattr(result, 'has_spoiler') - - -def test_json_richmessage(): - json_dict = json.loads(r'{"blocks": [{"text": "Test"}]}') - result = types.RichMessage.de_json(json_dict) - assert isinstance(result, types.RichMessage) - assert hasattr(result, 'blocks') - - -def test_json_sentguestmessage(): - json_dict = json.loads(r'{"inline_message_id": 1}') - result = types.SentGuestMessage.de_json(json_dict) - assert result.inline_message_id == 1 - assert isinstance(result, types.SentGuestMessage) - - -def test_json_shippingaddress(): - json_dict = json.loads(r'{"country_code": "US", "state": "CA", "city": "San Jose", "street_line1": "123 Main St", "street_line2": "Apt 4", "post_code": "95113"}') - result = types.ShippingAddress.de_json(json_dict) - assert result.country_code == 'US' - assert result.state == 'CA' - assert result.city == 'San Jose' - assert result.street_line1 == '123 Main St' - assert result.street_line2 == 'Apt 4' - assert result.post_code == '95113' - assert isinstance(result, types.ShippingAddress) - - -def test_json_shippingquery(): - json_dict = json.loads(r'{"id": "1", "from": {"id": 1, "is_bot": false, "first_name": "Test"}, "invoice_payload": "test_payload", "shipping_address": {"country_code": "US", "state": "CA", "city": "Test", "street_line1": "Test St", "street_line2": "", "post_code": "12345"}}') - result = types.ShippingQuery.de_json(json_dict) - assert isinstance(result, types.ShippingQuery) - assert hasattr(result, 'invoice_payload') - assert isinstance(result.from_user, types.User) - assert hasattr(result, 'id') - - -def test_json_staramount(): - json_dict = json.loads(r'{"amount": 1}') - result = types.StarAmount.de_json(json_dict) - assert isinstance(result, types.StarAmount) - assert hasattr(result, 'amount') - - -def test_json_startransaction(): - json_dict = json.loads(r'{"id": 1, "amount": 100, "date": 1682189507, "source": {"type": "fragment"}, "receiver": {"type": "telegram_ads"}, "nanostar_amount": 10000000}') - result = types.StarTransaction.de_json(json_dict) - assert result.id == 1 - assert result.amount == 100 - assert result.date == 1682189507 - assert isinstance(result.source, types.TransactionPartnerFragment) - assert isinstance(result.receiver, dict) - assert result.receiver['type'] == 'telegram_ads' - assert result.nanostar_amount == 10000000 - assert isinstance(result, types.StarTransaction) - - -def test_json_startransactions(): - json_dict = json.loads(r'{"transactions": [{"id": "tx1", "amount": 100, "date": 1682189507}]}') - result = types.StarTransactions.de_json(json_dict) - assert isinstance(result, types.StarTransactions) - assert hasattr(result, 'transactions') - - -def test_json_story(): - json_dict = json.loads(r'{"chat": {"id": 1, "type": "private", "title": "Test"}, "id": 1}') - result = types.Story.de_json(json_dict) - assert isinstance(result.chat, types.Chat) - assert result.id == 1 - assert isinstance(result, types.Story) - - -def test_json_successfulpayment(): - json_dict = json.loads(r'{"currency": "USD", "total_amount": 1234, "invoice_payload": "test_payload", "shipping_option_id": "opt1", "order_info": {"user_name": "Buyer", "user_phone": "+123", "shipping_address": {"country_code": "US", "state": "CA", "city": "San Jose", "street_line1": "123 Main St", "street_line2": "", "post_code": "95113"}}, "telegram_payment_charge_id": "chg1", "provider_payment_charge_id": "chg2", "subscription_expiration_date": 1704067200, "is_recurring": true, "is_first_recurring": true}') - result = types.SuccessfulPayment.de_json(json_dict) - assert result.currency == 'USD' - assert result.total_amount == 1234 - assert result.invoice_payload == 'test_payload' - assert result.shipping_option_id == 'opt1' - assert isinstance(result.order_info, types.OrderInfo) - assert result.telegram_payment_charge_id == 'chg1' - assert result.provider_payment_charge_id == 'chg2' - assert result.subscription_expiration_date == 1704067200 - assert result.is_recurring == True - assert result.is_first_recurring == True - assert isinstance(result, types.SuccessfulPayment) - - -def test_json_suggestedpostapprovalfailed(): - json_dict = json.loads(r'{"price": {"currency": "USD", "amount": 100}}') - result = types.SuggestedPostApprovalFailed.de_json(json_dict) - assert isinstance(result.price, types.SuggestedPostPrice) - assert isinstance(result, types.SuggestedPostApprovalFailed) - assert hasattr(result, 'price') - - -def test_json_suggestedpostapproved(): - json_dict = json.loads(r'{"send_date": 1682189507}') - result = types.SuggestedPostApproved.de_json(json_dict) - assert result.send_date == 1682189507 - assert isinstance(result, types.SuggestedPostApproved) - - -def test_json_suggestedpostinfo(): - json_dict = json.loads(r'{"state": "default"}') - result = types.SuggestedPostInfo.de_json(json_dict) - assert result.state == 'default' - assert isinstance(result, types.SuggestedPostInfo) - - -def test_json_suggestedpostpaid(): - json_dict = json.loads(r'{"currency": "test"}') - result = types.SuggestedPostPaid.de_json(json_dict) - assert result.currency == 'test' - assert isinstance(result, types.SuggestedPostPaid) - - -def test_json_suggestedpostrefunded(): - json_dict = json.loads(r'{"reason": "test"}') - result = types.SuggestedPostRefunded.de_json(json_dict) - assert result.reason == 'test' - assert isinstance(result, types.SuggestedPostRefunded) - - -def test_json_textquote(): - json_dict = json.loads(r'{"text": "test", "position": 0}') - result = types.TextQuote.de_json(json_dict) - assert result.text == 'test' - assert result.position == 0 - assert isinstance(result, types.TextQuote) - - -def test_json_transactionpartner(): - # TransactionPartner is abstract - test TransactionPartnerUser directly - json_dict = json.loads(r'{"type": "user", "user": {"id": 1, "is_bot": false, "first_name": "Test"}}') - result = types.TransactionPartnerUser.de_json(json_dict) - assert isinstance(result, types.TransactionPartnerUser) - - -def test_json_transactionpartneraffiliateprogram(): - json_dict = json.loads(r'{"type": "affiliate_program", "commission_per_mille": 1000}') - result = types.TransactionPartnerAffiliateProgram.de_json(json_dict) - assert result.type == 'affiliate_program' - assert result.commission_per_mille == 1000 - assert isinstance(result, types.TransactionPartnerAffiliateProgram) - - -def test_json_transactionpartnerchat(): - json_dict = json.loads(r'{"type": "default", "chat": {"id": 1, "type": "private", "title": "Test"}}') - result = types.TransactionPartnerChat.de_json(json_dict) - assert result.type == 'default' - assert isinstance(result.chat, types.Chat) - assert isinstance(result, types.TransactionPartnerChat) - - -def test_json_transactionpartnerfragment(): - json_dict = json.loads(r'{"type": "fragment"}') - result = types.TransactionPartnerFragment.de_json(json_dict) - assert result.type == 'fragment' - assert isinstance(result, types.TransactionPartnerFragment) - - -def test_json_transactionpartnerother(): - json_dict = json.loads(r'{"type": "other"}') - result = types.TransactionPartnerOther.de_json(json_dict) - assert result.type == 'other' - assert isinstance(result, types.TransactionPartnerOther) - - -def test_json_transactionpartnertelegramapi(): - json_dict = json.loads(r'{"type": "default", "request_count": 10}') - result = types.TransactionPartnerTelegramApi.de_json(json_dict) - assert result.type == 'default' - assert result.request_count == 10 - assert isinstance(result, types.TransactionPartnerTelegramApi) - - -def test_json_transactionpartneruser(): - json_dict = json.loads(r'{"type": "default", "user": {"id": 1, "is_bot": false, "first_name": "Test"}, "affiliate": {"commission_per_mille": 5500, "amount": 100, "affiliate_user": {"id": 1, "is_bot": false, "first_name": "User"}, "affiliate_chat": {"id": 1, "type": "private"}, "nanostar_amount": 1000000}, "invoice_payload": "payload", "paid_media": [{"type": "photo", "photo": [{"file_id": "p", "file_unique_id": "pu", "width": 100, "height": 100}]}], "subscription_period": 30, "gift": {"id": 1, "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "star_count": 100, "total_count": 1000, "remaining_count": 999, "upgrade_star_count": 50, "personal_total_count": 5, "personal_remaining_count": 3, "is_premium": true, "has_colors": false, "publisher_chat": {"id": 1, "type": "channel", "title": "Pub"}, "unique_gift_variant_count": 10}, "premium_subscription_duration": 12, "transaction_type": "purchase"}') - result = types.TransactionPartnerUser.de_json(json_dict) - assert result.type == 'default' - assert isinstance(result.user, types.User) - assert isinstance(result.affiliate, types.AffiliateInfo) - assert result.invoice_payload == 'payload' - assert isinstance(result.paid_media, list) - assert result.subscription_period == 30 - assert isinstance(result.gift, types.Gift) - assert result.premium_subscription_duration == 12 - assert result.transaction_type == 'purchase' - assert isinstance(result, types.TransactionPartnerUser) - - -def test_json_uniquegift(): - json_dict = json.loads(r'{"base_name": "test", "name": "test", "number": 1, "model": {"name": "model_name", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "symbol": {"name": "symbol_name", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "backdrop": {"name": "backdrop_name", "colors": {"center_color": 123456, "edge_color": 654321, "symbol_color": 111111, "text_color": 222222}, "rarity_per_mille": 1000}, "gift_id": 1, "publisher_chat": {"id": -1001234567890, "type": "channel", "title": "Channel"}, "is_from_blockchain": true, "is_premium": false, "colors": {"model_custom_emoji_id": 1, "symbol_custom_emoji_id": 1, "light_theme_main_color": 333333, "light_theme_other_colors": [444444], "dark_theme_main_color": 555555, "dark_theme_other_colors": [666666]}, "is_burned": false}') - result = types.UniqueGift.de_json(json_dict) - assert result.base_name == 'test' - assert result.name == 'test' - assert result.number == 1 - assert isinstance(result.model, types.UniqueGiftModel) - assert isinstance(result.symbol, types.UniqueGiftSymbol) - assert isinstance(result.backdrop, types.UniqueGiftBackdrop) - assert result.gift_id == 1 - assert isinstance(result.publisher_chat, types.Chat) - assert result.is_from_blockchain == True - assert result.is_premium == False - assert isinstance(result.colors, types.UniqueGiftColors) - assert result.is_burned == False - assert isinstance(result, types.UniqueGift) - - -def test_json_uniquegiftbackdrop(): - json_dict = json.loads(r'{"name": "test", "colors": {"center_color": 123456, "edge_color": 654321, "symbol_color": 111111, "text_color": 222222}, "rarity_per_mille": 1000}') - result = types.UniqueGiftBackdrop.de_json(json_dict) - assert result.name == 'test' - assert isinstance(result.colors, types.UniqueGiftBackdropColors) - assert result.rarity_per_mille == 1000 - assert isinstance(result, types.UniqueGiftBackdrop) - - -def test_json_uniquegiftbackdropcolors(): - json_dict = json.loads(r'{"center_color": 123456, "edge_color": 654321, "symbol_color": 111111, "text_color": 222222}') - result = types.UniqueGiftBackdropColors.de_json(json_dict) - assert result.center_color == 123456 - assert result.edge_color == 654321 - assert result.symbol_color == 111111 - assert result.text_color == 222222 - assert isinstance(result, types.UniqueGiftBackdropColors) - - -def test_json_uniquegiftcolors(): - json_dict = json.loads(r'{"model_custom_emoji_id": 1, "symbol_custom_emoji_id": 1, "light_theme_main_color": 333333, "light_theme_other_colors": [444444], "dark_theme_main_color": 555555, "dark_theme_other_colors": [666666]}') - result = types.UniqueGiftColors.de_json(json_dict) - assert result.model_custom_emoji_id == 1 - assert result.symbol_custom_emoji_id == 1 - assert result.light_theme_main_color == 333333 - assert isinstance(result.light_theme_other_colors, list) - assert result.dark_theme_main_color == 555555 - assert isinstance(result.dark_theme_other_colors, list) - assert isinstance(result, types.UniqueGiftColors) - - -def test_json_uniquegiftinfo(): - json_dict = json.loads(r'{"gift": {"base_name": "b", "name": "n", "number": 1, "model": {"name": "m", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "symbol": {"name": "s", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}, "backdrop": {"name": "b", "colors": {"center_color": 123456, "edge_color": 654321, "symbol_color": 111111, "text_color": 222222}, "rarity_per_mille": 1000}, "gift_id": 1}, "origin": "test", "owned_gift_id": "og123", "transfer_star_count": 100, "next_transfer_date": 1682189507, "last_resale_currency": "USD", "last_resale_amount": 500}') - result = types.UniqueGiftInfo.de_json(json_dict) - assert isinstance(result.gift, types.UniqueGift) - assert result.origin == 'test' - assert result.owned_gift_id == 'og123' - assert result.transfer_star_count == 100 - assert result.next_transfer_date == 1682189507 - assert result.last_resale_currency == 'USD' - assert result.last_resale_amount == 500 - assert isinstance(result, types.UniqueGiftInfo) - - -def test_json_uniquegiftmodel(): - json_dict = json.loads(r'{"name": "test", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}') - result = types.UniqueGiftModel.de_json(json_dict) - assert result.name == 'test' - assert isinstance(result.sticker, types.Sticker) - assert result.rarity_per_mille == 1000 - assert isinstance(result, types.UniqueGiftModel) - - -def test_json_uniquegiftsymbol(): - json_dict = json.loads(r'{"name": "test", "sticker": {"file_id": "s", "file_unique_id": "su", "type": "regular", "width": 512, "height": 512, "is_animated": false, "is_video": false}, "rarity_per_mille": 1000}') - result = types.UniqueGiftSymbol.de_json(json_dict) - assert result.name == 'test' - assert isinstance(result.sticker, types.Sticker) - assert result.rarity_per_mille == 1000 - assert isinstance(result, types.UniqueGiftSymbol) - - -# NOTE: Update is an abstract/registry class that dispatches to specific -# update types (message_update, callback_query_update, etc.). Its __init__ -# only contains 'update_id' in practice; other 'update_type' fields are -# handled by subclasses. Full field coverage is intentionally not required. -def test_json_update(): - json_dict = json.loads(r'{"update_id": 1}') - result = types.Update.de_json(json_dict) - assert result.update_id == 1 - assert isinstance(result, types.Update) - - -def test_json_userchatboosts(): - json_dict = json.loads(r'{"boosts": [{"boost_item_id": "b1", "add_date": 1682189507, "expiration_date": 1682275907}]}') - result = types.UserChatBoosts.de_json(json_dict) - assert isinstance(result.boosts, list) - assert isinstance(result, types.UserChatBoosts) - assert hasattr(result, 'boosts') - - -def test_json_userprofileaudios(): - json_dict = json.loads(r'{"total_count": 1, "audios": [{"file_id": "a1", "file_unique_id": "au1", "duration": 180, "title": "Test", "performer": "Perf", "type": "song"}]}') - result = types.UserProfileAudios.de_json(json_dict) - assert result.total_count == 1 - assert isinstance(result.audios, list) - assert isinstance(result, types.UserProfileAudios) - - -def test_json_userprofilephotos(): - json_dict = json.loads(r'{"total_count": 1}') - result = types.UserProfilePhotos.de_json(json_dict) - assert result.total_count == 1 - assert isinstance(result, types.UserProfilePhotos) - - -def test_json_userrating(): - json_dict = json.loads(r'{"level": "test", "rating": "test", "current_level_rating": "test"}') - result = types.UserRating.de_json(json_dict) - assert result.level == 'test' - assert result.rating == 'test' - assert result.current_level_rating == 'test' - assert isinstance(result, types.UserRating) - - -def test_json_videochatended(): - json_dict = json.loads(r'{"duration": 30}') - result = types.VideoChatEnded.de_json(json_dict) - assert result.duration == 30 - assert isinstance(result, types.VideoChatEnded) - - -def test_json_videochatscheduled(): - json_dict = json.loads(r'{"start_date": 1682189507}') - result = types.VideoChatScheduled.de_json(json_dict) - assert result.start_date == 1682189507 - assert isinstance(result, types.VideoChatScheduled) - - -def test_json_videonote(): - json_dict = json.loads(r'{"file_id": "test_file_id", "file_unique_id": "test_unique_id", "length": 100, "duration": 30}') - result = types.VideoNote.de_json(json_dict) - assert result.file_id == 'test_file_id' - assert result.file_unique_id == 'test_unique_id' - assert result.length == 100 - assert result.duration == 30 - assert isinstance(result, types.VideoNote) - - -def test_json_videoquality(): - json_dict = json.loads(r'{"file_id": "test_file_id", "file_unique_id": "test_unique_id", "width": 100, "height": 100, "codec": "h264"}') - result = types.VideoQuality.de_json(json_dict) - assert result.file_id == 'test_file_id' - assert result.file_unique_id == 'test_unique_id' - assert result.width == 100 - assert result.height == 100 - assert result.codec == 'h264' - assert isinstance(result, types.VideoQuality) - - -def test_json_webhookinfo(): - json_dict = json.loads(r'{"url": "https://example.com", "has_custom_certificate": false, "pending_update_count": 1}') - result = types.WebhookInfo.de_json(json_dict) - assert result.url == 'https://example.com' - assert result.has_custom_certificate == False - assert result.pending_update_count == 1 - assert isinstance(result, types.WebhookInfo) \ No newline at end of file