예제 #1
0
 def store_file(self):
     if not self.is_duplicate_file():  # skip exact duplicates
         self.change_file_name_if_already_exists()
         file_writer.store_file(self._full_path, self.get_content_to_save())
         md5 = self._json['attachment'][self._attachment_id]['md5']
         name = self._json['attachment'][self._attachment_id]['name']
         self._parent_notebook.attachment_md5_file_name_dict[md5] = name
예제 #2
0
def test_file_writer_bytes_io(tmp_path):
    content = BytesIO(b"Hello World")
    file_path = Path(tmp_path, "file1.file")
    file_writer.store_file(file_path, content)

    result = file_path.read_bytes()

    assert result == b"Hello World"
예제 #3
0
def test_file_writer_string(tmp_path):
    content = "Hello World"
    file_path = Path(tmp_path, "file1.file")
    file_writer.store_file(file_path, content)

    result = file_path.read_text()

    assert result == content
예제 #4
0
def test_file_writer_bytes(tmp_path):
    content = b'Hello World'
    file_path = Path(tmp_path, "file1.file")
    file_writer.store_file(file_path, content)

    result = file_path.read_bytes()

    assert result == content
예제 #5
0
def test_file_writer_invalid_type_content(tmp_path, caplog):
    content = 23
    file_path = Path(tmp_path, "file1.file")
    file_writer.store_file(file_path, content)

    assert len(caplog.records) > 0

    for record in caplog.records:
        assert record.levelname == "WARNING"
예제 #6
0
def test_file_writer_bytes_io_invalid_path(tmp_path, caplog):
    content = BytesIO(b"Hello World")
    file_path = Path(tmp_path, "ddsf/dsfsdf/dfsd", "file1.file")
    file_writer.store_file(file_path, content)

    assert len(caplog.records) > 0

    for record in caplog.records:
        assert record.levelname == "ERROR"
        assert 'No such file or directory' in record.message
예제 #7
0
def test_file_writer_bytes_io_existing_directory(tmp_path, caplog):
    content = BytesIO(b"Hello World")
    file_path = Path(tmp_path)
    file_writer.store_file(file_path, content)

    assert len(caplog.records) > 1
예제 #8
0
def test_file_writer_string_existing_directory(tmp_path, caplog):
    content = "Hello World"
    file_path = Path(tmp_path)
    file_writer.store_file(file_path, content)

    assert len(caplog.records) > 1
예제 #9
0
 def store_file(self):
     file_writer.store_file(self._full_path, self.get_content_to_save())
예제 #10
0
    def _store_file(note_page, bar=None):
        file_writer.store_file(note_page.full_path,
                               note_page.converted_content)

        if bar:
            bar()