def test_formatter_get_chat(self): """ Ensures that the BaseFormatter is able to fetch the expected entities when using a date parameter. """ chat = types.Chat( id=123, title='Some title', photo=types.ChatPhotoEmpty(), participants_count=7, date=datetime.now(), version=1 ) dumper = Dumper(self.dumper_config) fmt = BaseFormatter(dumper.conn) for month in range(1, 13): await dumper.dump_chat(chat, None, timestamp=int(datetime( year=2010, month=month, day=1 ).timestamp())) dumper.commit() cid = tl_utils.get_peer_id(chat) # Default should get the most recent version date = fmt.get_chat(cid).date_updated assert date == datetime(year=2010, month=12, day=1) # Expected behaviour is to get the previous available date target = datetime(year=2010, month=6, day=29) date = fmt.get_chat(cid, target).date_updated assert date == datetime(year=2010, month=6, day=1) # Expected behaviour is to get the next date if previous unavailable target = datetime(year=2009, month=12, day=1) date = fmt.get_chat(cid, target).date_updated assert date == datetime(year=2010, month=1, day=1)
def test_dump_methods(self): """Test await dumper.dump_* works""" dumper = Dumper(self.dumper_config) message = types.Message( id=777, to_id=types.PeerUser(123), date=datetime.now(), message='Hello', out=True, via_bot_id=1000, fwd_from=types.MessageFwdHeader( date=datetime.now() - timedelta(days=1), from_id=321 ) ) fwd_id = await dumper.dump_forward(message.fwd_from) await dumper.dump_message(message, 123, forward_id=fwd_id, media_id=None) message = types.Message( id=778, to_id=types.PeerUser(321), date=datetime.now(), message='Hello', out=False, via_bot_id=1000, media=types.MessageMediaPhoto( caption='Hi', ttl_seconds=40, photo=types.Photo( id=2357, access_hash=-123456789, date=datetime.now(), sizes=[ types.PhotoSize( type='X', w=100, h=100, size=100 * 100, location=types.FileLocation( dc_id=2, volume_id=5, local_id=7532, secret=987654321 ) ) ] ) ) ) loc = await dumper.dump_media(message.media) await dumper.dump_message(message, 123, forward_id=None, media_id=loc) await dumper.dump_message_service(context_id=123, media_id=loc, message=types.MessageService( id=779, to_id=123, date=datetime.now(), action=types.MessageActionScreenshotTaken() )) me = types.User( id=123, is_self=True, access_hash=13515, first_name='Me', username='******', phone='1234567' ) await dumper.dump_user(photo_id=None, user_full=types.UserFull( user=me, link=types.contacts.Link( my_link=types.ContactLinkContact(), foreign_link=types.ContactLinkContact(), user=me ), notify_settings=types.PeerNotifySettings(0, 'beep'), common_chats_count=3 )) await dumper.dump_chat(photo_id=None, chat=types.Chat( id=7264, title='Chat', photo=types.ChatPhotoEmpty(), participants_count=5, date=datetime.now() - timedelta(days=10), version=1 )) channel = types.Channel( id=8247, title='Channel', photo=types.ChatPhotoEmpty(), username='******', participants_count=17, date=datetime.now() - timedelta(days=5), version=7 ) channel_full = types.ChannelFull( id=8247, about='Just a Channel', read_inbox_max_id=1051, read_outbox_max_id=8744, unread_count=1568, chat_photo=types.PhotoEmpty(id=176489), notify_settings=types.PeerNotifySettingsEmpty(), exported_invite=types.ChatInviteEmpty(), bot_info=[] ) await dumper.dump_supergroup(channel_full, channel, photo_id=None) await dumper.dump_channel(channel_full, channel, photo_id=None)