예제 #1
0
def test_search_with_spaces(context):
    search_term = "deer YCH"
    update = MockTelegramUpdate.with_inline_query(query=search_term)
    post_id1 = 213231
    post_id2 = 84331
    submission1 = MockSubmission(post_id1)
    submission2 = MockSubmission(post_id2)
    inline = InlineFunctionality(MockExportAPI())
    inline.api.with_search_results(search_term, [submission1, submission2])

    inline.call(update, context)

    context.bot.answer_inline_query.assert_called_once()
    args = context.bot.answer_inline_query.call_args[0]
    assert context.bot.answer_inline_query.call_args[1]['next_offset'] == 2
    assert args[0] == update.inline_query.id
    assert isinstance(args[1], list)
    assert len(args[1]) == 2
    for result in args[1]:
        assert isinstance(result, InlineQueryResultPhoto)
    assert args[1][0].id == str(post_id1)
    assert args[1][1].id == str(post_id2)
    assert args[1][0].photo_url == submission1.thumbnail_url
    assert args[1][1].photo_url == submission2.thumbnail_url
    assert args[1][0].thumb_url == FASubmission.make_thumbnail_smaller(
        submission1.thumbnail_url)
    assert args[1][1].thumb_url == FASubmission.make_thumbnail_smaller(
        submission2.thumbnail_url)
    assert args[1][0].caption == submission1.link
    assert args[1][1].caption == submission2.link
def test_user_favourites(context):
    post_id1 = 234563
    post_id2 = 393282
    username = "******"
    update = MockTelegramUpdate.with_inline_query(
        query=f"favourites:{username}")
    submission1 = MockSubmission(post_id1)
    submission2 = MockSubmission(post_id2)
    inline = InlineFunctionality(MockExportAPI())
    inline.api.with_user_favs(username, [submission1, submission2])

    inline.call(update, context)

    context.bot.answer_inline_query.assert_called_once()
    args = context.bot.answer_inline_query.call_args[0]
    assert context.bot.answer_inline_query.call_args[1][
        'next_offset'] == submission2.fav_id
    assert args[0] == update.inline_query.id
    assert isinstance(args[1], list)
    assert len(args[1]) == 2
    assert isinstance(args[1][0], InlineQueryResultPhoto)
    assert isinstance(args[1][1], InlineQueryResultPhoto)
    assert args[1][0].id == str(post_id1)
    assert args[1][1].id == str(post_id2)
    assert args[1][0].photo_url == submission1.thumbnail_url
    assert args[1][1].photo_url == submission2.thumbnail_url
    assert args[1][0].thumb_url == FASubmission.make_thumbnail_smaller(
        submission1.thumbnail_url)
    assert args[1][1].thumb_url == FASubmission.make_thumbnail_smaller(
        submission2.thumbnail_url)
    assert args[1][0].caption == submission1.link
    assert args[1][1].caption == submission2.link
def test_continue_from_fav_id(context):
    post_id = 234563
    fav_id = "354233"
    username = "******"
    update = MockTelegramUpdate.with_inline_query(query=f"favs:{username}",
                                                  offset=fav_id)
    submission = MockSubmission(post_id)
    inline = InlineFunctionality(MockExportAPI())
    inline.api.with_user_favs(username, [submission], next_id=fav_id)

    inline.call(update, context)

    context.bot.answer_inline_query.assert_called_once()
    args = context.bot.answer_inline_query.call_args[0]
    assert context.bot.answer_inline_query.call_args[1][
        'next_offset'] == submission.fav_id
    assert args[0] == update.inline_query.id
    assert isinstance(args[1], list)
    assert len(args[1]) == 1
    assert isinstance(args[1][0], InlineQueryResultPhoto)
    assert args[1][0].id == str(post_id)
    assert args[1][0].photo_url == submission.thumbnail_url
    assert args[1][0].thumb_url == FASubmission.make_thumbnail_smaller(
        submission.thumbnail_url)
    assert args[1][0].caption == submission.link
def test_over_48_favs(context):
    username = "******"
    post_ids = list(range(123456, 123456 + 72))
    submissions = [MockSubmission(x) for x in post_ids]
    inline = InlineFunctionality(MockExportAPI())
    inline.api.with_user_favs(username, submissions)
    update = MockTelegramUpdate.with_inline_query(query=f"favs:{username}")

    inline.call(update, context)

    context.bot.answer_inline_query.assert_called_once()
    args = context.bot.answer_inline_query.call_args[0]
    assert context.bot.answer_inline_query.call_args[1][
        'next_offset'] == submissions[47].fav_id
    assert args[0] == update.inline_query.id
    assert isinstance(args[1], list)
    assert len(args[1]) == 48
    assert isinstance(args[1][0], InlineQueryResultPhoto)
    assert isinstance(args[1][1], InlineQueryResultPhoto)
    for x in range(48):
        assert args[1][x].id == str(post_ids[x])
        assert args[1][x].photo_url == submissions[x].thumbnail_url
        assert args[1][x].thumb_url == FASubmission.make_thumbnail_smaller(
            submissions[x].thumbnail_url)
        assert args[1][x].caption == submissions[x].link
예제 #5
0
    def test_to_inline_query_result(self):
        post_id = "1234"
        image_id = "5324543"
        link = f"https://furaffinity.net/view/{post_id}/"
        thumb_url = f"https://t.facdn.net/{post_id}@1600-{image_id}.jpg"
        title = "Example post"
        author = FAUser.from_short_dict({"name": "John", "profile_name": "john"})
        submission = FASubmissionShort(post_id, thumb_url, title, author)

        query_result = submission.to_inline_query_result()

        assert query_result.id == post_id
        assert query_result.photo_url == thumb_url
        assert query_result.thumb_url == FASubmission.make_thumbnail_smaller(thumb_url)
        assert query_result.caption == link
def test_weird_characters_in_username(context):
    post_id = 234563
    username = "******"
    update = MockTelegramUpdate.with_inline_query(query=f"gallery:{username}")
    submission = MockSubmission(post_id)
    inline = InlineFunctionality(MockExportAPI())
    inline.api.with_user_folder(username, "gallery", [submission])

    inline.call(update, context)

    context.bot.answer_inline_query.assert_called_once()
    args = context.bot.answer_inline_query.call_args[0]
    assert context.bot.answer_inline_query.call_args[1]['next_offset'] == 2
    assert args[0] == update.inline_query.id
    assert isinstance(args[1], list)
    assert len(args[1]) == 1
    assert isinstance(args[1][0], InlineQueryResultPhoto)
    assert args[1][0].id == str(post_id)
    assert args[1][0].photo_url == submission.thumbnail_url
    assert args[1][0].thumb_url == FASubmission.make_thumbnail_smaller(submission.thumbnail_url)
    assert args[1][0].caption == submission.link
예제 #7
0
def test_search_with_field(context):
    search_term = "@lower citrinelle"
    update = MockTelegramUpdate.with_inline_query(query=search_term)
    post_id = 213231
    submission = MockSubmission(post_id)
    inline = InlineFunctionality(MockExportAPI())
    inline.api.with_search_results(search_term, [submission])

    inline.call(update, context)

    context.bot.answer_inline_query.assert_called_once()
    args = context.bot.answer_inline_query.call_args[0]
    assert context.bot.answer_inline_query.call_args[1]['next_offset'] == 2
    assert args[0] == update.inline_query.id
    assert isinstance(args[1], list)
    assert len(args[1]) == 1
    assert isinstance(args[1][0], InlineQueryResultPhoto)
    assert args[1][0].id == str(post_id)
    assert args[1][0].photo_url == submission.thumbnail_url
    assert args[1][0].thumb_url == FASubmission.make_thumbnail_smaller(
        submission.thumbnail_url)
    assert args[1][0].caption == submission.link
예제 #8
0
def test_simple_search(context):
    post_id = 234563
    search_term = "YCH"
    update = MockTelegramUpdate.with_inline_query(query=search_term)
    submission = MockSubmission(post_id)
    inline = InlineFunctionality(MockExportAPI())
    inline.api.with_search_results(search_term, [submission])

    inline.call(update, context)

    context.bot.answer_inline_query.assert_called_once()
    args = context.bot.answer_inline_query.call_args[0]
    assert context.bot.answer_inline_query.call_args[1]['next_offset'] == 2
    assert args[0] == update.inline_query.id
    assert isinstance(args[1], list)
    assert len(args[1]) > 0
    for result in args[1]:
        assert isinstance(result, InlineQueryResultPhoto)
        assert result.id == str(post_id)
        assert result.photo_url == submission.thumbnail_url
        assert result.thumb_url == FASubmission.make_thumbnail_smaller(
            submission.thumbnail_url)
        assert result.caption == submission.link