From b745088a05c2da005830080aef0f567aa29c641b Mon Sep 17 00:00:00 2001 From: eternnoir Date: Sat, 1 Aug 2015 09:55:17 +0800 Subject: [PATCH] Let thumb option in Sticker. Api chamged. --- telebot/types.py | 4 +++- tests/test_types.py | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/telebot/types.py b/telebot/types.py index 0157901..0650236 100644 --- a/telebot/types.py +++ b/telebot/types.py @@ -265,7 +265,9 @@ class Sticker(JsonDeserializable): file_id = obj['file_id'] width = obj['width'] height = obj['height'] - thumb = PhotoSize.de_json(obj['thumb']) + thumb = None + if 'thumb' in obj: + thumb = PhotoSize.de_json(obj['thumb']) file_size = None if 'file_size' in obj: file_size = obj['file_size'] diff --git a/tests/test_types.py b/tests/test_types.py index a3082f3..c239000 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -52,6 +52,12 @@ def test_json_Message_Sticker(): assert msg.sticker.thumb.height == 60 assert msg.content_type == 'sticker' +def test_json_Message_Sticker_without_thumb(): + json_string = r'{"message_id":98,"from":{"id":10734,"first_name":"Fd","last_name":"Wd","username":"dd"},"chat":{"id":10734,"first_name":"Fd","last_name":"Wd","username":"dd"},"date":1435479551,"sticker":{"width":550,"height":368,"file_id":"BQADBQADNAIAAsYifgYdGJOa6bGAsQI","file_size":30320}}' + msg = types.Message.de_json(json_string) + assert msg.sticker.height == 368 + assert msg.sticker.thumb == None + assert msg.content_type == 'sticker' def test_json_Message_Document(): json_string = r'{"message_id":97,"from":{"id":10734,"first_name":"Fd","last_name":"Wd","username":"dd"},"chat":{"id":10,"first_name":"Fd","last_name":"Wd","username":"dd"},"date":1435478744,"document":{"file_name":"Text File","thumb":{},"file_id":"BQADBQADMwIAAsYifgZ_CEh0u682xwI","file_size":446}}' @@ -95,3 +101,4 @@ def test_json_contact(): contact = types.Contact.de_json(json_string) assert contact.first_name == 'dd' assert contact.last_name == 'ddl' +