Esempio n. 1
0
async def test_auto_doc_just_over_size_limit(mock_client):
    title = "Example title"
    author = FAUser("A writer", "awriter")
    submission = SubmissionBuilder(file_ext="pdf",
                                   file_size=FASubmission.SIZE_LIMIT_DOCUMENT +
                                   1,
                                   title=title,
                                   author=author).build_full_submission()
    chat = MockChat(-9327622)
    message_id = 2873292

    await submission.send_message(mock_client, chat, reply_to=message_id)

    mock_client.send_message.assert_called_once()
    assert mock_client.send_message.call_args[1]['entity'] == chat
    assert mock_client.send_message.call_args[1][
        'file'] == submission.full_image_url
    assert mock_client.send_message.call_args[1]['reply_to'] == message_id
    assert mock_client.send_message.call_args[1]['parse_mode'] == 'html'
    sent_message = mock_client.send_message.call_args[1]['message']
    assert sent_message.endswith(
        f"{submission.link}\n<a href=\"{submission.download_url}\">Direct download</a>"
    )
    assert f"\"{title}\"" in sent_message
    assert author.name in sent_message
    assert author.link in sent_message
 def __init__(
         self,
         submission_id: Union[str, int],
         *,
         username: str = None,
         image_id: int = None,
         file_size: int = 14852,
         file_ext: str = "jpg",
         fav_id: str = None,
         title: str = None,
         author: FAUser = None,
         description: str = None,
         keywords: List[str] = None,
         thumbnail_url: str = None,
         download_url: str = None,
         full_image_url: str = None,
         rating: Rating = None
 ):
     # Internal variables
     if image_id is None:
         image_id = _random_image_id(int(submission_id))
     if username is None:
         username = _random_string()
     if fav_id is None:
         fav_id = str(_random_image_id(int(submission_id)))
     folder = ""
     if file_ext in FASubmission.EXTENSIONS_AUDIO:
         folder = "music/"
     if file_ext in FASubmission.EXTENSIONS_DOCUMENT:
         folder = "stories/"
     # Variables for superclass
     if thumbnail_url is None:
         thumbnail_url = f"https://t.furaffinity.net/{submission_id}@1600-{image_id}.jpg"
     if download_url is None:
         download_url = f"https://d.furaffinity.net/art/{username}/{folder}{image_id}/" \
             f"{image_id}.{username}_{_random_string()}.{file_ext}"
     if full_image_url is None:
         if file_ext in FASubmission.EXTENSIONS_PHOTO + ["gif"]:
             full_image_url = download_url
         else:
             full_image_url = download_url + ".jpg"
     if title is None:
         title = _random_string()
     if author is None:
         profile_name = _random_string()
         author = FAUser.from_submission_dict({"name": profile_name.title(), "profile_name": profile_name})
     if description is None:
         description = _random_string() * 5
     if keywords is None:
         keywords = [_random_string() for _ in range(3)]
     if rating is None:
         rating = _random_rating()
     # Super
     super().__init__(
         str(submission_id), thumbnail_url, download_url,
         full_image_url, title, author, description, keywords, rating
     )
     self.fav_id = fav_id
     self._download_file_size = file_size
     self._send_message = AsyncMock()
Esempio n. 3
0
def test_constructor():
    post_id = "1234"
    image_id = "5324543"
    link = f"https://furaffinity.net/view/{post_id}/"
    thumb_link = f"https://t.furaffinity.net/{post_id}@400-{image_id}.jpg"
    full_link = f"https://d.furaffinity.net/art/fender/{image_id}/{image_id}.fender_blah-de-blah.jpg"
    title = "Example post"
    author = FAUser.from_short_dict({"name": "John", "profile_name": "john"})
    description = "This is an example post for testing"
    keywords = ["example", "test"]
    rating = Rating.GENERAL

    submission = FASubmissionFull(post_id, thumb_link, full_link, full_link,
                                  title, author, description, keywords, rating)

    assert isinstance(submission, FASubmissionFull)
    assert submission.submission_id == post_id
    assert submission.link == link
    assert submission.thumbnail_url == thumb_link
    assert submission.full_image_url == full_link
    assert submission.download_url == full_link
    assert submission.title == title
    assert submission.author == author
    assert submission.description == description
    assert submission.keywords == keywords
    assert submission.rating == rating
Esempio n. 4
0
    def test_constructor(self):
        name = "John"
        profile_name = "john"

        author = FAUser(name, profile_name)

        assert author.name == name
        assert author.profile_name == profile_name
        assert f"/user/{profile_name}" in author.link
Esempio n. 5
0
    def test_from_submission_dict(self):
        name = "John"
        profile_name = "john"

        author = FAUser.from_submission_dict(
            {
                "name": name,
                "profile_name": profile_name
            }
        )

        assert author.name == name
        assert author.profile_name == profile_name
        assert f"/user/{profile_name}" in author.link
Esempio n. 6
0
    def test_constructor(self):
        post_id = "1234"
        image_id = "5324543"
        link = f"https://furaffinity.net/view/{post_id}/"
        thumb_link = f"https://t.furaffinity.net/{post_id}@400-{image_id}.jpg"
        title = "Example post"
        author = FAUser.from_short_dict({"name": "John", "profile_name": "john"})

        submission = FASubmissionShort(post_id, thumb_link, title, author)

        assert isinstance(submission, FASubmissionShort)
        assert submission.submission_id == post_id
        assert submission.link == link
        assert submission.thumbnail_url == thumb_link
        assert submission.title == title
        assert submission.author == author
Esempio n. 7
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.furaffinity.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)
        mock_builder = Mock(InlineBuilder)

        submission.to_inline_query_result(mock_builder)

        assert mock_builder.photo.call_args[1]['file'] == thumb_url
        assert mock_builder.photo.call_args[1]['id'] == post_id
        assert mock_builder.photo.call_args[1]['text'] == link
        assert len(mock_builder.photo.call_args[1]['buttons']) == 1
        assert mock_builder.photo.call_args[1]['buttons'][0].data == f"neaten_me:{post_id}".encode()
Esempio n. 8
0
async def test_mp3_submission(mock_client):
    title = "Example music"
    author = FAUser("A musician", "amusician")
    submission = SubmissionBuilder(file_ext="mp3",
                                   file_size=47453,
                                   title=title,
                                   author=author).build_full_submission()
    chat = MockChat(-9327622)
    message_id = 2873292

    await submission.send_message(mock_client, chat, reply_to=message_id)

    mock_client.send_message.assert_called_once()
    assert mock_client.send_message.call_args[1]['entity'] == chat
    assert mock_client.send_message.call_args[1][
        'file'] == submission.download_url
    assert mock_client.send_message.call_args[1]['reply_to'] == message_id
    sent_message = mock_client.send_message.call_args[1]['message']
    assert sent_message.endswith(submission.link)
    assert f"\"{title}\"" in sent_message
    assert author.name in sent_message
    assert author.link in sent_message
Esempio n. 9
0
        field = get_field_for_name(q.fieldname)
        return PrefixQuery(q.text, field)
    if isinstance(q, Wildcard):
        field = get_field_for_name(q.fieldname)
        regex = fnmatch.translate(q.text)
        return RegexQuery(regex, field)
    if isinstance(q, Phrase):
        field = get_field_for_name(q.fieldname)
        quote = " ".join(q.words)
        return PhraseQuery(quote, field)
    raise NotImplementedError


if __name__ == "__main__":
    sub1 = FASubmissionFull("123", "thumb1.png", "image1.png", "image1.png",
                            "First document", FAUser("uploader", "uploader"),
                            "This is the first document we've added!",
                            ["first", "document"], Rating.GENERAL)
    sub2 = FASubmissionFull("234", "thumb2.png", "image1.png", "image1.png",
                            "Second document", FAUser("uploader", "uploader"),
                            "The second one is even more interesting!",
                            ["second", "document"], Rating.GENERAL)

    print("Whoosh time:")
    query = MultifieldParser(search_fields, schema).parse("first")
    start_time = datetime.datetime.now()
    for _ in range(50):
        assert matches_subscription(sub1, query)
        assert not matches_subscription(sub2, query)
    end_time = datetime.datetime.now()
    print((end_time - start_time) / 100)
Esempio n. 10
0
 def __init__(self,
              *,
              submission_id: Union[str, int] = None,
              username: str = None,
              image_id: int = None,
              file_size: int = None,
              thumb_size: int = None,
              file_ext: str = "jpg",
              fav_id: str = None,
              title: str = None,
              author: FAUser = None,
              description: str = None,
              keywords: List[str] = None,
              rating: Rating = None):
     if submission_id is None:
         submission_id = random.randint(10_000, 100_000)
     submission_id = str(submission_id)
     # Internal variables
     if image_id is None:
         image_id = _random_image_id(int(submission_id))
     if username is None:
         if author is None:
             username = _random_string()
         else:
             username = author.profile_name
     folder = ""
     if file_ext in FASubmission.EXTENSIONS_AUDIO:
         folder = "music/"
     if file_ext in FASubmission.EXTENSIONS_DOCUMENT:
         folder = "stories/"
     if thumb_size is None:
         thumb_size = 1600
     # Variables for superclass
     thumbnail_url = f"https://t.furaffinity.net/{submission_id}@{thumb_size}-{image_id}.jpg"
     download_url = f"https://d.furaffinity.net/art/{username}/{folder}{image_id}/" \
         f"{image_id}.{username}_{_random_string()}.{file_ext}"
     if file_ext in FASubmission.EXTENSIONS_PHOTO + ["gif"]:
         full_image_url = download_url
     else:
         full_image_url = download_url + ".jpg"
     if title is None:
         title = _random_string()
     if author is None:
         author = FAUser.from_submission_dict({
             "name": username.title(),
             "profile_name": username
         })
     if description is None:
         description = _random_string() * 5
     if keywords is None:
         keywords = [_random_string() for _ in range(3)]
     if rating is None:
         rating = Rating.GENERAL
     # Set all the variables
     self.submission_id = submission_id
     self.link = f"https://furaffinity.net/view/{submission_id}/"
     self.thumbnail_url = thumbnail_url
     self.title = title
     self.author = author
     self.download_url = download_url
     self.full_image_url = full_image_url
     self.description = description
     self.rating = rating
     self.keywords = keywords
     self.fav_id = fav_id
     self._image_id = image_id
     self._file_ext = file_ext
     self._download_file_size = file_size