Exemplo n.º 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
Exemplo n.º 5
0
    def test_id_from_link(self):
        post_id = "12874"
        link = f"https://furaffinity.net/view/{post_id}/"

        new_id = FASubmission.id_from_link(link)

        assert new_id == post_id
Exemplo n.º 6
0
    def test_constructor(self):
        post_id = "1242"

        submission = FASubmission(post_id)

        assert submission.submission_id == post_id
        assert NeatenFunctionality.FA_SUB_LINK.search(submission.link) is not None
        assert f"view/{post_id}" in submission.link
Exemplo n.º 7
0
    def test_make_thumbnail_bigger(self):
        post_id = "1234"
        image_id = "5324543"
        thumb_link = f"https://t.facdn.net/{post_id}@400-{image_id}.jpg"
        big_thumb_link = f"https://t.facdn.net/{post_id}@1600-{image_id}.jpg"

        big_link = FASubmission.make_thumbnail_bigger(thumb_link)

        assert big_link == big_thumb_link
Exemplo n.º 8
0
    def test_create_short_dict_makes_thumb_bigger_75(self):
        builder = SubmissionBuilder(thumb_size=75)
        big_thumb_link = builder.thumbnail_url.replace("@75-", "@1600-")

        submission = FASubmission.from_short_dict(
            builder.build_search_json()
        )

        assert submission.thumbnail_url == big_thumb_link
Exemplo n.º 9
0
    def test_make_thumbnail_bigger_size_75(self):
        post_id = "1234"
        image_id = "5324543"
        # Only available size not ending 0
        thumb_link = f"https://t.facdn.net/{post_id}@75-{image_id}.jpg"
        big_thumb_link = f"https://t.facdn.net/{post_id}@1600-{image_id}.jpg"

        big_link = FASubmission.make_thumbnail_bigger(thumb_link)

        assert big_link == big_thumb_link
Exemplo n.º 10
0
    def test_get_file_size(self, r):
        url = "http://example.com/file.jpg"
        size = 7567
        r.head(
            url,
            headers={
                "content-length": str(size)
            }
        )

        file_size = FASubmission._get_file_size(url)

        assert isinstance(size, int)
        assert file_size == size
Exemplo n.º 11
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
Exemplo n.º 12
0
    def test_create_from_short_dict(self):
        builder = SubmissionBuilder()

        submission = FASubmission.from_short_dict(
            builder.build_search_json()
        )

        assert isinstance(submission, FASubmissionShort)
        assert submission.submission_id == builder.submission_id
        assert submission.link == builder.link

        assert submission.thumbnail_url == builder.thumbnail_url
        assert submission.title == builder.title
        assert submission.author.profile_name == builder.author.profile_name
        assert submission.author.name == builder.author.name
        assert submission.author.link == builder.author.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
Exemplo n.º 14
0
    def test_create_from_full_dict(self):
        builder = SubmissionBuilder()

        submission = FASubmission.from_full_dict(
            builder.build_submission_json()
        )

        assert isinstance(submission, FASubmissionFull)
        assert submission.submission_id == builder.submission_id
        assert submission.link == builder.link

        assert submission.thumbnail_url == builder.thumbnail_url
        assert submission.title == builder.title
        assert submission.author.profile_name == builder.author.profile_name
        assert submission.author.name == builder.author.name
        assert submission.author.link == builder.author.link

        assert submission.download_url == builder.download_url
        assert submission.full_image_url == builder.full_image_url
        assert submission.description == builder.description
        assert submission.keywords == builder.keywords
Exemplo n.º 15
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
Exemplo n.º 16
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