Beispiel #1
0
def test_binary_file_serializing(binary_gif_file, binary_img_file):
    with open(f"tests/files/{binary_img_file['file_name']}", "rb") as f:
        mfile = File.from_file(f)
        assert File(**binary_img_file) == mfile
        assert (mfile.media_type == binary_img_file["data"].split(
            "data:", 1)[1].split(";", 1)[0])

    with open(f"tests/files/{binary_gif_file['file_name']}", "rb") as f:
        mfile = File.from_file(f)
        assert File(**binary_gif_file) == mfile
        assert (mfile.media_type == binary_gif_file["data"].split(
            "data:", 1)[1].split(";", 1)[0])
Beispiel #2
0
def test_text_file_serializing(text_txt_file, text_json_file):
    with open(f"tests/files/{text_txt_file['file_name']}", "r") as f:
        mfile = File.from_file(f)
        assert File(**text_txt_file) == mfile
        assert (mfile.media_type == text_txt_file["data"].split("data:",
                                                                1)[1].split(
                                                                    ";", 1)[0])

    with open(f"tests/files/{text_json_file['file_name']}", "r") as f:
        mfile = File.from_file(f)
        assert File(**text_json_file) == mfile
        assert (mfile.media_type == text_json_file["data"].split(
            "data:", 1)[1].split(";", 1)[0])
Beispiel #3
0
async def my_handler(message: Message) -> None:
    with open("my_file.txt") as f:
        notification = SendingMessage(
            file=File.from_file(f), credentials=message.credentials,
        )

    await bot.send(notification)
Beispiel #4
0
def test_creating_file_from_io_with_name(
    io_cls,
    file_data,
    file_name,
    explicit_file_name,
):
    created_file = io_cls(file_data)
    if not explicit_file_name:
        created_file.name = file_name

    assert File.from_file(created_file, filename=explicit_file_name) == File(
        file_name=explicit_file_name or file_name,
        data="data:text/plain;base64,dGVzdA==",
    )
Beispiel #5
0
 def test_message_file_from_file(
         self, sending_message: SendingMessage) -> None:
     original_file = sending_message.file
     sending_message.add_file(File.from_file(original_file.file))
     assert sending_message.file == original_file