def de_json(cls, data: Optional[JSONDict], bot: 'Bot') -> Optional['Update']: """See :meth:`telegram.TelegramObject.de_json`.""" data = cls._parse_data(data) if not data: return None data['message'] = Message.de_json(data.get('message'), bot) data['edited_message'] = Message.de_json(data.get('edited_message'), bot) data['inline_query'] = InlineQuery.de_json(data.get('inline_query'), bot) data['chosen_inline_result'] = ChosenInlineResult.de_json( data.get('chosen_inline_result'), bot) data['callback_query'] = CallbackQuery.de_json( data.get('callback_query'), bot) data['shipping_query'] = ShippingQuery.de_json( data.get('shipping_query'), bot) data['pre_checkout_query'] = PreCheckoutQuery.de_json( data.get('pre_checkout_query'), bot) data['channel_post'] = Message.de_json(data.get('channel_post'), bot) data['edited_channel_post'] = Message.de_json( data.get('edited_channel_post'), bot) data['poll'] = Poll.de_json(data.get('poll'), bot) data['poll_answer'] = PollAnswer.de_json(data.get('poll_answer'), bot) data['my_chat_member'] = ChatMemberUpdated.de_json( data.get('my_chat_member'), bot) data['chat_member'] = ChatMemberUpdated.de_json( data.get('chat_member'), bot) data['chat_join_request'] = ChatJoinRequest.de_json( data.get('chat_join_request'), bot) return cls(**data)
def test_de_json_required_args(self, bot, user, chat, old_chat_member, new_chat_member, time): json_dict = { "chat": chat.to_dict(), "from": user.to_dict(), "date": to_timestamp(time), "old_chat_member": old_chat_member.to_dict(), "new_chat_member": new_chat_member.to_dict(), } chat_member_updated = ChatMemberUpdated.de_json(json_dict, bot) assert chat_member_updated.chat == chat assert chat_member_updated.from_user == user assert abs(chat_member_updated.date - time) < datetime.timedelta(seconds=1) assert to_timestamp(chat_member_updated.date) == to_timestamp(time) assert chat_member_updated.old_chat_member == old_chat_member assert chat_member_updated.new_chat_member == new_chat_member assert chat_member_updated.invite_link is None
def test_de_json_required_args(self, bot, user, chat, old_chat_member, new_chat_member, time): json_dict = { 'chat': chat.to_dict(), 'from': user.to_dict(), 'date': to_timestamp(time), 'old_chat_member': old_chat_member.to_dict(), 'new_chat_member': new_chat_member.to_dict(), } chat_member_updated = ChatMemberUpdated.de_json(json_dict, bot) assert chat_member_updated.chat == chat assert chat_member_updated.from_user == user assert pytest.approx(chat_member_updated.date == time) assert to_timestamp(chat_member_updated.date) == to_timestamp(time) assert chat_member_updated.old_chat_member == old_chat_member assert chat_member_updated.new_chat_member == new_chat_member assert chat_member_updated.invite_link is None