Exemplo n.º 1
0
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()
Exemplo n.º 2
0
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_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()
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
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])
Exemplo n.º 6
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}/"
    )
Exemplo n.º 7
0
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)
Exemplo n.º 8
0
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_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
Exemplo n.º 10
0
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
Exemplo n.º 11
0
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])
Exemplo n.º 12
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
Exemplo n.º 13
0
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)
Exemplo n.º 14
0
 def initialise_functionalities(self):
     return [
         BeepFunctionality(),
         WelcomeFunctionality(),
         ImageHashRecommendFunctionality(),
         NeatenFunctionality(self.api),
         InlineFunctionality(self.api),
         SubscriptionFunctionality(self.subscription_watcher),
         BlocklistFunctionality(self.subscription_watcher),
         UnhandledMessageFunctionality()
     ]
Exemplo n.º 15
0
def test_duplicate_direct_link(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) * 2
    )
    submission = MockSubmission(post_id, image_id=image_id)
    neaten = NeatenFunctionality(MockExportAPI())
    neaten.api.with_user_folder(username, "gallery", [
        submission,
        MockSubmission(post_id - 1, image_id=image_id - 15)
    ])

    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
Exemplo n.º 16
0
def test_image_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_size=FASubmission.SIZE_LIMIT_IMAGE - 1)
    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
Exemplo n.º 17
0
def test_direct_link(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_photo.assert_called_with(
        chat_id=update.message.chat_id,
        photo=goal_submission.download_url,
        caption=goal_submission.link,
        reply_to_message_id=update.message.message_id
    )
Exemplo n.º 18
0
def test_two_submission_links(context):
    post_id1 = 23636984
    post_id2 = 23636996
    update = MockTelegramUpdate.with_message(
        text="furaffinity.net/view/{}\nfuraffinity.net/view/{}".format(
            post_id1, post_id2))
    submission1 = MockSubmission(post_id1)
    submission2 = MockSubmission(post_id2)
    neaten = NeatenFunctionality(MockExportAPI())
    neaten.api.with_submissions([submission1, submission2])

    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 [submission1, submission2]
    ]
    context.bot.send_photo.assert_has_calls(calls)
Exemplo n.º 19
0
def test_auto_doc_just_over_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="pdf",
                                file_size=FASubmission.SIZE_LIMIT_DOCUMENT + 1)
    neaten = NeatenFunctionality(MockExportAPI())
    neaten.api.with_submission(submission)

    neaten.call(update, context)

    context.bot.send_document.assert_not_called()
    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)
Exemplo n.º 20
0
def test_not_on_first_page_empty_second_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)
    )
    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", [
    ], 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
    )
Exemplo n.º 21
0
def test_direct_no_match(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())
    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()
    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_thumb_and_different_submission_link(context):
    post_id1 = 382632
    post_id2 = 382672
    update = MockTelegramUpdate.with_message(
        text=
        f"https://t.facdn.net/{post_id1}@1600-1562445328.jpg\nhttps://furaffinity.net/view/{post_id2}"
    )
    submission1 = MockSubmission(post_id1)
    submission2 = MockSubmission(post_id2)
    neaten = NeatenFunctionality(MockExportAPI())
    neaten.api.with_submissions([submission1, submission2])

    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 [submission1, submission2]
    ]
    context.bot.send_photo.assert_has_calls(calls)
Exemplo n.º 23
0
def test_result_missing_from_second_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)
    )
    neaten = NeatenFunctionality(MockExportAPI())
    for page in [1, 2]:
        neaten.api.with_user_folder(username, "gallery", [
            MockSubmission(post_id + 1 + (2 - page) * 6, image_id=image_id + 16 + (2 - page) * 56),
            MockSubmission(post_id + 0 + (2 - page) * 6, image_id=image_id + 3 + (2 - page) * 56),
            MockSubmission(post_id - 2 + (2 - page) * 6, image_id=image_id - 27 + (2 - page) * 56),
            MockSubmission(post_id - 3 + (2 - page) * 6, image_id=image_id - 34 + (2 - page) * 56)
        ], page=page)

    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
    )
Exemplo n.º 24
0
def test_result_on_third_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)
    )
    neaten = NeatenFunctionality(MockExportAPI())
    for page in [1, 2, 3]:
        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)
    submission = neaten.api.get_full_submission(str(post_id))

    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
Exemplo n.º 25
0
def test_image_over_document_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_size=FASubmission.SIZE_LIMIT_DOCUMENT + 1)
    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.thumbnail_url
    assert context.bot.send_photo.call_args[1]['caption'] == \
           f"{submission.link}\n[Direct download]({submission.download_url})"
    assert context.bot.send_photo.call_args[1][
        'reply_to_message_id'] == update.message.message_id
    assert context.bot.send_photo.call_args[1][
        'parse_mode'] == telegram.ParseMode.MARKDOWN