def test_ImageNSAttachment_create_file_name(raw_name, expected):
    note = Note()
    attachment_id = '1234'
    image_attachment = sn_attachment.ImageNSAttachment(note, attachment_id)

    image_attachment._name = raw_name
    image_attachment.create_file_name()

    assert image_attachment.file_name == Path(expected)
def test_ImageNSAttachment_create_html_link():
    note = Note()
    attachment_id = '1234'
    image_attachment = sn_attachment.ImageNSAttachment(note, attachment_id)

    image_attachment._file_name = Path('my_file.png')
    image_attachment.create_html_link()

    assert image_attachment.html_link == f'<img src="my_file.png" >'
def test_test_change_file_name_image_attachment_no_extension_on_file_name_and_not_recognised(mocker):
    note = Note()
    attachment_id = '1234'
    image_attachment = sn_attachment.ImageNSAttachment(note, attachment_id)

    image_attachment._name = 'ns_attach_image_my_file'
    mocker.patch('zip_file_reader.read_binary_file', return_value=b'1234')
    mocker.patch('helper_functions.file_extension_from_bytes', return_value=None)
    image_attachment.create_file_name()

    assert image_attachment.file_name == Path('my_file')
def test_change_file_name_image_attachment_if_already_exists(tmp_path):
    note = Note()
    attachment_id = '1234'
    image_attachment = sn_attachment.ImageNSAttachment(note, attachment_id)

    image_attachment._full_path = Path(tmp_path, 'my_file.png')

    image_attachment._full_path.write_text('hello world')

    image_attachment.change_file_name_if_already_exists()

    assert len(str(image_attachment.full_path)) == len(
        str(Path(tmp_path, 'my_file.png'))) + 5  # 4 random chars and a dash
def test_change_file_name_image_attachment_file_does_not_already_exist(tmp_path):
    note = Note()
    attachment_id = '1234'
    image_attachment = sn_attachment.ImageNSAttachment(note, attachment_id)

    image_attachment._full_path = Path(tmp_path, 'my_file.png')

    image_attachment.change_file_name_if_already_exists()

    assert len(str(image_attachment.full_path)) == len(
        str(Path(tmp_path, 'my_file.png')))

    assert image_attachment.full_path == Path(tmp_path, 'my_file.png')
    def create_attachments(self):
        if self._attachments_json is None:
            self.logger.warning(
                f'Note - {self._title} - Has Null set for attachments. '
                f'There may be a sync issues between desktop and web version of Note Station.'
            )
            return 0, 0

        for attachment_id in self._attachments_json:
            if self._attachments_json[attachment_id]['type'].startswith('image') \
                    and \
                    self._attachments_json[attachment_id].get('ref'):
                self._attachments[
                    attachment_id] = sn_attachment.ImageNSAttachment(
                        self, attachment_id)
                self._image_count += 1
            else:
                self._attachments[
                    attachment_id] = sn_attachment.FileNSAttachment(
                        self, attachment_id)
                self._attachment_count += 1

        return self._image_count, self._attachment_count
def test_notebook_folder_name():
    note = Note()
    attachment_id = '1234'
    image_attachment = sn_attachment.ImageNSAttachment(note, attachment_id)

    assert image_attachment.notebook_folder_name == 'notebook_folder'
def test_ImageNSAttachment_image_ref():
    note = Note()
    attachment_id = '1234'
    image_attachment = sn_attachment.ImageNSAttachment(note, attachment_id)

    assert image_attachment.image_ref == '54321'