def test_result_missing_between_pages(context): username = "******" image_id = 1560331512 post_id = 232347 update = MockTelegramUpdate.with_message( text="http://d.facdn.net/art/{0}/{1}/{1}.pic_of_me.png".format(username, image_id) ) neaten = NeatenFunctionality(MockExportAPI()) neaten.api.with_user_folder(username, "gallery", [ MockSubmission(post_id + 1, image_id=image_id + 16), MockSubmission(post_id, image_id=image_id + 3) ], page=1) neaten.api.with_user_folder(username, "gallery", [ MockSubmission(post_id - 2, image_id=image_id - 27), MockSubmission(post_id - 3, image_id=image_id - 34) ], page=2) neaten.call(update, context) context.bot.send_photo.assert_not_called() context.bot.send_message.assert_called_with( chat_id=update.message.chat_id, text="Could not locate the image by {} with image id {}.".format(username, image_id), reply_to_message_id=update.message.message_id )
def test_submission_link_and_different_direct_link(context): username = "******" image_id1 = 1560331512 image_id2 = image_id1 + 300 post_id1 = 232347 post_id2 = 233447 update = MockTelegramUpdate.with_message( text="https://furaffinity.net/view/{2}/ http://d.facdn.net/art/{0}/{1}/{1}.pic_of_me.png".format( username, image_id1, post_id2 ) ) submission1 = MockSubmission(post_id1, image_id=image_id1) submission2 = MockSubmission(post_id2, image_id=image_id2) neaten = NeatenFunctionality(MockExportAPI()) neaten.api.with_user_folder(username, "gallery", [ submission2, submission1, MockSubmission(post_id1 - 1, image_id=image_id1 - 15) ]) neaten.call(update, context) context.bot.send_photo.assert_called() calls = [call( chat_id=update.message.chat_id, photo=submission.download_url, caption=submission.link, reply_to_message_id=update.message.message_id ) for submission in [submission2, submission1]] context.bot.send_photo.assert_has_calls(calls)
def test_result_first_on_page(context): username = "******" image_id = 1560331512 post_id = 232347 update = MockTelegramUpdate.with_message( text="http://d.facdn.net/art/{0}/{1}/{1}.pic_of_me.png".format(username, image_id) ) submission = MockSubmission(post_id, image_id=image_id) neaten = NeatenFunctionality(MockExportAPI()) neaten.api.with_user_folder(username, "gallery", [ MockSubmission(post_id + 3, image_id=image_id + 16), MockSubmission(post_id + 2, image_id=image_id + 8) ], page=1) neaten.api.with_user_folder(username, "gallery", [ submission, MockSubmission(post_id - 2, image_id=image_id - 2), MockSubmission(post_id - 7, image_id=image_id - 4), MockSubmission(post_id - 9, image_id=image_id - 10) ], page=2) neaten.call(update, context) context.bot.send_photo.assert_called_once() assert context.bot.send_photo.call_args[1]['chat_id'] == update.message.chat_id assert context.bot.send_photo.call_args[1]['photo'] == submission.download_url assert context.bot.send_photo.call_args[1]['caption'] == submission.link assert context.bot.send_photo.call_args[1]['reply_to_message_id'] == update.message.message_id
def test_result_in_scraps(context): username = "******" image_id = 1560331512 post_id = 232347 update = MockTelegramUpdate.with_message( text="http://d.facdn.net/art/{0}/{1}/{1}.pic_of_me.png".format(username, image_id) ) submission = MockSubmission(post_id, image_id=image_id) neaten = NeatenFunctionality(MockExportAPI()) for page in [1, 2]: neaten.api.with_user_folder(username, "gallery", [ MockSubmission(post_id + 1 + (3 - page) * 5, image_id=image_id + 16 + (3 - page) * 56), MockSubmission(post_id + (3 - page) * 5, image_id=image_id + (3 - page) * 56), MockSubmission(post_id - 2 + (3 - page) * 5, image_id=image_id - 27 + (3 - page) * 56), MockSubmission(post_id - 3 + (3 - page) * 5, image_id=image_id - 34 + (3 - page) * 56) ], page=page) neaten.api.with_user_folder(username, "gallery", [], page=3) neaten.api.with_user_folder(username, "scraps", [ MockSubmission(post_id + 1, image_id=image_id + 16), submission, MockSubmission(post_id - 2, image_id=image_id - 27), MockSubmission(post_id - 3, image_id=image_id - 34) ], page=1) neaten.call(update, context) context.bot.send_photo.assert_called_once() assert context.bot.send_photo.call_args[1]['chat_id'] == update.message.chat_id assert context.bot.send_photo.call_args[1]['photo'] == submission.download_url assert context.bot.send_photo.call_args[1]['caption'] == submission.link assert context.bot.send_photo.call_args[1]['reply_to_message_id'] == update.message.message_id
def test_direct_in_progress_message(context): username = "******" image_id = 1560331512 post_id = 232347 update = MockTelegramUpdate.with_message( text="http://d.facdn.net/art/{0}/{1}/{1}.pic_of_me.png".format(username, image_id) ) goal_submission = MockSubmission(post_id, image_id=image_id) neaten = NeatenFunctionality(MockExportAPI()) neaten.api.with_user_folder(username, "gallery", [ goal_submission, MockSubmission(post_id - 1, image_id=image_id - 15) ]) neaten.call(update, context) context.bot.send_message.assert_called_with( chat_id=update.message.chat_id, text="⏳ Neatening image link", reply_to_message_id=update.message.message_id ) context.bot.delete_message.assert_called_with( update.message.chat_id, context._sent_message_ids[0] )
def test_direct_no_match_groupchat(context): username = "******" image_id = 1560331512 post_id = 232347 update = MockTelegramUpdate.with_message( text="http://d.facdn.net/art/{0}/{1}/{1}.pic_of_me.png".format(username, image_id), chat_type=Chat.GROUP ) neaten = NeatenFunctionality(MockExportAPI()) for folder in ['gallery', 'scraps']: neaten.api.with_user_folder(username, folder, [ MockSubmission(post_id, image_id=image_id + 4), MockSubmission(post_id - 1, image_id=image_id - 15) ]) neaten.call(update, context) context.bot.send_photo.assert_not_called() context.bot.send_message.assert_called_with( chat_id=update.message.chat_id, text="⏳ Neatening image link", reply_to_message_id=update.message.message_id ) context.bot.delete_message.assert_called_with( update.message.chat_id, context._sent_message_ids[0] )
def test_unhandled_group_message(context): update = MockTelegramUpdate.with_message(text="Hey friendo, how are you?", chat_type=Chat.GROUP) unhandled = UnhandledMessageFunctionality() unhandled.call(update, context) context.bot.send_message.assert_not_called()
def test_ignore_message(context): update = MockTelegramUpdate.with_message(text="hello world") neaten = NeatenFunctionality(MockExportAPI()) neaten.call(update, context) context.bot.send_message.assert_not_called() context.bot.send_photo.assert_not_called()
def test_no_reply_in_group(context): update = MockTelegramUpdate.with_message( text=None, chat_type=Chat.GROUP).with_photo() func = ImageHashRecommendFunctionality() func.call(update, context) context.bot.send_message.assert_not_called()
def test_ignore_journal_link(context): update = MockTelegramUpdate.with_message(text="https://www.furaffinity.net/journal/9150534/") neaten = NeatenFunctionality(MockExportAPI()) neaten.call(update, context) context.bot.send_message.assert_not_called() context.bot.send_photo.assert_not_called()
def test_ignore_link(context): update = MockTelegramUpdate.with_message(text="http://example.com") neaten = NeatenFunctionality(MockExportAPI()) neaten.call(update, context) context.bot.send_message.assert_not_called() context.bot.send_photo.assert_not_called()
def test_can_create_message(self): update = MockTelegramUpdate.with_message() assert update.callback_query is None assert update.message is not None assert update.message.message_id is not None assert update.message.chat_id is not None assert isinstance(update.message.photo, list) assert len(update.message.photo) == 0
def test_unhandled_message(context): update = MockTelegramUpdate.with_message(text="Hello can I have a picture") unhandled = UnhandledMessageFunctionality() unhandled.call(update, context) context.bot.send_message.assert_called_with( chat_id=update.message.chat_id, text="Sorry, I'm not sure how to handle that message")
def test_sends_recommendation(context): update = MockTelegramUpdate.with_message(text=None).with_photo() func = ImageHashRecommendFunctionality() func.call(update, context) context.bot.send_message.assert_called() assert context.bot.send_message.call_args[1][ 'chat_id'] == update.message.chat_id message_text = context.bot.send_message.call_args[1]['text'] assert "@FindFurryPicBot" in message_text
def test_doesnt_fire_on_avatar(context): update = MockTelegramUpdate.with_message( text="https://a.facdn.net/1538326752/geordie79.gif") neaten = NeatenFunctionality(MockExportAPI()) neaten.call(update, context) context.bot.send_photo.assert_not_called() context.bot.send_document.assert_not_called() context.bot.send_message.assert_not_called() context.bot.send_audio.assert_not_called()
def test_can_create_message_with_document(self): update = MockTelegramUpdate.with_message().with_document() assert update.callback_query is None assert update.message is not None assert update.message.message_id is not None assert update.message.chat_id is not None assert isinstance(update.message.photo, list) assert len(update.message.photo) == 0 assert update.message.document is not None assert isinstance(update.message.document, _MockDocument) assert update.message.document.file_id is not None assert update.message.document.mime_type is None
def test_mp3_submission(context): post_id = 23636984 update = MockTelegramUpdate.with_message( text="https://www.furaffinity.net/view/{}/".format(post_id)) submission = MockSubmission(post_id, file_ext="mp3") neaten = NeatenFunctionality(MockExportAPI()) neaten.api.with_submission(submission) neaten.call(update, context) context.bot.send_audio.assert_called_with( chat_id=update.message.chat_id, audio=submission.download_url, caption=submission.link, reply_to_message_id=update.message.message_id)
def test_deleted_submission_group_chat(context): post_id = 23636984 update = MockTelegramUpdate.with_message( text="furaffinity.net/view/{}".format(post_id), chat_type=Chat.GROUP) neaten = NeatenFunctionality(MockExportAPI()) neaten.call(update, context) context.bot.send_photo.assert_not_called() context.bot.send_message.assert_called_with( chat_id=update.message.chat_id, text="⏳ Neatening image link", reply_to_message_id=update.message.message_id) context.bot.delete_message.assert_called_with(update.message.chat_id, context._sent_message_ids[0])
def test_deleted_submission(context): post_id = 23636984 update = MockTelegramUpdate.with_message( text="furaffinity.net/view/{}".format(post_id)) neaten = NeatenFunctionality(MockExportAPI()) neaten.call(update, context) context.bot.send_photo.assert_not_called() context.bot.send_message.assert_called_with( chat_id=update.message.chat_id, reply_to_message_id=update.message.message_id, text= f"This doesn't seem to be a valid FA submission: https://www.furaffinity.net/view/{post_id}/" )
def test_call__route_list_subscriptions(context): update = MockTelegramUpdate.with_message(chat_id=14358, text="/list_subscriptions") api = MockExportAPI() watcher = SubscriptionWatcher(api, context.bot) func = SubscriptionFunctionality(watcher) list_subs = MockMethod("Listing subscriptions") func._list_subs = list_subs.call func.call(update, context) assert list_subs.called assert list_subs.args is not None assert list_subs.args[0] == 14358 context.bot.send_message.assert_called() assert context.bot.send_message.call_args[1]['chat_id'] == update.message.chat_id assert context.bot.send_message.call_args[1]['text'] == "Listing subscriptions"
def test_call__route_add_subscription_with_username(context): update = MockTelegramUpdate.with_message(chat_id=14358, text="/add_subscription@FASearchBot test") api = MockExportAPI() watcher = SubscriptionWatcher(api, context.bot) func = SubscriptionFunctionality(watcher) add_sub = MockMethod("Added subscription test") func._add_sub = add_sub.call func.call(update, context) assert add_sub.called assert add_sub.args is not None assert add_sub.args[0] == 14358 assert add_sub.args[1] == "test" context.bot.send_message.assert_called() assert context.bot.send_message.call_args[1]['chat_id'] == update.message.chat_id assert context.bot.send_message.call_args[1]['text'] == "Added subscription test"
def test_call__route_remove_subscription(context): update = MockTelegramUpdate.with_message(chat_id=14358, text="/remove_subscription@FASearchBot example") api = MockExportAPI() watcher = SubscriptionWatcher(api, context.bot) func = SubscriptionFunctionality(watcher) delete_sub = MockMethod("Removed subscription test") func._remove_sub = delete_sub.call func.call(update, context) assert delete_sub.called assert delete_sub.args is not None assert delete_sub.args[0] == 14358 assert delete_sub.args[1] == "example" context.bot.send_message.assert_called() assert context.bot.send_message.call_args[1]['chat_id'] == update.message.chat_id assert context.bot.send_message.call_args[1]['text'] == "Removed subscription test"
def test_txt_submission(context): post_id = 23636984 update = MockTelegramUpdate.with_message( text="https://www.furaffinity.net/view/{}/".format(post_id)) submission = MockSubmission(post_id, file_ext="txt") neaten = NeatenFunctionality(MockExportAPI()) neaten.api.with_submission(submission) neaten.call(update, context) context.bot.send_photo.assert_called_with( chat_id=update.message.chat_id, photo=submission.full_image_url, caption= f"{submission.link}\n[Direct download]({submission.download_url})", reply_to_message_id=update.message.message_id, parse_mode=telegram.ParseMode.MARKDOWN)
def test_unknown_type_submission(context): post_id = 23636984 update = MockTelegramUpdate.with_message( text="https://www.furaffinity.net/view/{}/".format(post_id), chat_type=Chat.PRIVATE) submission = MockSubmission(post_id, file_ext="zzz") neaten = NeatenFunctionality(MockExportAPI()) neaten.api.with_submission(submission) neaten.call(update, context) context.bot.send_photo.assert_not_called() context.bot.send_document.assert_not_called() context.bot.send_message.assert_called_with( chat_id=update.message.chat_id, text="I'm sorry, I don't understand that file extension (zzz).", reply_to_message_id=update.message.message_id)
def test_submission_link_no_http(context): post_id = 23636984 update = MockTelegramUpdate.with_message( text="furaffinity.net/view/{}".format(post_id)) submission = MockSubmission(post_id) neaten = NeatenFunctionality(MockExportAPI()) neaten.api.with_submission(submission) neaten.call(update, context) context.bot.send_photo.assert_called_once() assert context.bot.send_photo.call_args[1][ 'chat_id'] == update.message.chat_id assert context.bot.send_photo.call_args[1][ 'photo'] == submission.download_url assert context.bot.send_photo.call_args[1]['caption'] == submission.link assert context.bot.send_photo.call_args[1][ 'reply_to_message_id'] == update.message.message_id
def test_thumbnail_link(context): post_id = 382632 update = MockTelegramUpdate.with_message( text=f"https://t.facdn.net/{post_id}@400-1562445328.jpg") submission = MockSubmission(post_id) neaten = NeatenFunctionality(MockExportAPI()) neaten.api.with_submission(submission) neaten.call(update, context) context.bot.send_photo.assert_called_once() assert context.bot.send_photo.call_args[1][ 'chat_id'] == update.message.chat_id assert context.bot.send_photo.call_args[1][ 'photo'] == submission.download_url assert context.bot.send_photo.call_args[1]['caption'] == submission.link assert context.bot.send_photo.call_args[1][ 'reply_to_message_id'] == update.message.message_id
def test_unknown_type_submission_groupchat(context): post_id = 23636984 update = MockTelegramUpdate.with_message( text="https://www.furaffinity.net/view/{}/".format(post_id), chat_type=Chat.GROUP) submission = MockSubmission(post_id, file_ext="zzz") neaten = NeatenFunctionality(MockExportAPI()) neaten.api.with_submission(submission) neaten.call(update, context) context.bot.send_photo.assert_not_called() context.bot.send_document.assert_not_called() context.bot.send_message.assert_called_with( chat_id=update.message.chat_id, text="⏳ Neatening image link", reply_to_message_id=update.message.message_id) context.bot.delete_message.assert_called_with(update.message.chat_id, context._sent_message_ids[0])
def test_pdf_submission(context): post_id = 23636984 update = MockTelegramUpdate.with_message( text="https://www.furaffinity.net/view/{}/".format(post_id)) submission = MockSubmission(post_id, file_ext="pdf") neaten = NeatenFunctionality(MockExportAPI()) neaten.api.with_submission(submission) neaten.call(update, context) context.bot.send_photo.assert_not_called() context.bot.send_document.assert_called_once() assert context.bot.send_document.call_args[1][ 'chat_id'] == update.message.chat_id assert context.bot.send_document.call_args[1][ 'document'] == submission.download_url assert context.bot.send_document.call_args[1]['caption'] == submission.link assert context.bot.send_document.call_args[1][ 'reply_to_message_id'] == update.message.message_id
def test_auto_doc_just_under_size_limit(context): post_id = 23636984 update = MockTelegramUpdate.with_message( text="Hello", text_markdown_urled="https://www.furaffinity.net/view/{}/".format( post_id)) submission = MockSubmission(post_id, file_ext="gif", file_size=FASubmission.SIZE_LIMIT_DOCUMENT - 1) neaten = NeatenFunctionality(MockExportAPI()) neaten.api.with_submission(submission) neaten.call(update, context) context.bot.send_document.assert_called_with( chat_id=update.message.chat_id, document=submission.download_url, caption=submission.link, reply_to_message_id=update.message.message_id)
def test_call__route_add_blocklisted_tag(context): update = MockTelegramUpdate.with_message(chat_id=14358, text="/add_blocklisted_tag test") api = MockExportAPI() watcher = SubscriptionWatcher(api, context.bot) func = BlocklistFunctionality(watcher) add_tag = MockMethod("Added to blocklist: test") func._add_to_blocklist = add_tag.call func.call(update, context) assert add_tag.called assert add_tag.args is not None assert add_tag.args[0] == 14358 assert add_tag.args[1] == "test" context.bot.send_message.assert_called() assert context.bot.send_message.call_args[1][ 'chat_id'] == update.message.chat_id assert context.bot.send_message.call_args[1][ 'text'] == "Added to blocklist: test"