def test_process_notebook_pages_json_null_attachments(nsx):
    config.yanom_globals.is_silent = True
    note_page_1_json = {
        'parent_id': 'note_book1',
        'title': 'Page 1 title',
        'mtime': 1619298559,
        'ctime': 1619298539,
        'content': 'content',
        'tag': ['1'],
        'attachment': None
    }
    note_page_1 = sn_note_page.NotePage(nsx, 1, note_page_1_json)
    note_page_1.notebook_folder_name = 'note_book1'
    note_page_1._file_name = 'page-1-title.md'
    note_page_1._raw_content = """<div>Below is a hyperlink to the internet</div><div><a href=\"https://github.com/kevindurston21/YANOM-Note-O-Matic\">https://github.com/kevindurston21/YANOM-Note-O-Matic</a></div>"""
    notebook_title = 'notebook1'
    with patch('zip_file_reader.read_json_data',
               autospec=True,
               return_value={'title': notebook_title}):
        notebook = sn_notebook.Notebook(nsx, 'notebook_id_abcd')
        notebook.folder_name = 'notebook_folder'
        notebook.note_pages = [note_page_1]

        with patch('sn_note_page.NotePage.process_note',
                   spec=True) as mock_process_note:
            notebook.process_notebook_pages()

        mock_process_note.assert_called()

    assert len(notebook._null_attachment_list) == 1
def test_pair_up_note_pages_and_notebooks_note_title_already_exists(nsx):
    note_jason = {
        'parent_id': 'note_book2',
        'title': 'Page 8 title',
        'mtime': 1619298559,
        'ctime': 1619298539,
        'attachment': {},
        'content': 'content',
        'tag': [9]
    }
    note_page = sn_note_page.NotePage(nsx, '1234', note_jason)
    notebook_title = 'notebook1'
    with patch('zip_file_reader.read_json_data',
               autospec=True,
               return_value={'title': notebook_title}):
        notebook = sn_notebook.Notebook(nsx, 'notebook_id_abcd')
        notebook.folder_name = Path('notebook_folder')

        notebook.note_titles = ['abcd', 'Page 8 title', 'Page 8 title-1']

        notebook.pair_up_note_pages_and_notebooks(note_page)

    assert note_page.notebook_folder_name == Path('notebook_folder')
    assert note_page.parent_notebook_id == 'notebook_id_abcd'

    assert note_page.title == 'Page 8 title-2'
    assert note_page.title in notebook.note_titles
    assert note_page in notebook.note_pages
def test_generate_note_page_filename_and_path_duplicate_titles(
        nsx, conv_setting):
    nsx_fc = nsx_file_converter.NSXFile('fake_file', conv_setting,
                                        'fake_pandoc_converter')

    note_page_1_json = {
        'parent_id': 'note_book1',
        'title': 'Page 1 title',
        'mtime': 1619298559,
        'ctime': 1619298539,
        'attachment': {},
        'content': 'content',
        'tag': [1]
    }
    note_page_1 = sn_note_page.NotePage(nsx, 1, note_page_1_json)
    note_page_1.notebook_folder_name = 'note_book1'
    note_page_1._raw_content = """<div>Below is a hyperlink to the internet</div><div><a href=\"https://github.com/kevindurston21/YANOM-Note-O-Matic\">https://github.com/kevindurston21/YANOM-Note-O-Matic</a></div>"""

    note_page_2_json = {
        'parent_id': 'note_book1',
        'title': 'Page 1 title',
        'mtime': 1619298559,
        'ctime': 1619298539,
        'attachment': {},
        'content': 'content',
        'tag': [1]
    }
    note_page_2 = sn_note_page.NotePage(nsx, 1, note_page_2_json)
    note_page_2.notebook_folder_name = 'note_book1'
    note_page_2._raw_content = """<div>Below is a hyperlink to the internet</div><div><a href=\"https://github.com/kevindurston21/YANOM-Note-O-Matic\">https://github.com/kevindurston21/YANOM-Note-O-Matic</a></div>"""

    nsx_fc._note_pages = {
        id(note_page_1): note_page_1,
        id(note_page_2): note_page_2
    }

    nsx_fc.generate_note_page_filename_and_path()

    assert nsx_fc._note_pages[id(note_page_1)]._file_name == Path(
        'Page 1 title.md')
    assert nsx_fc._note_pages[id(note_page_2)]._file_name == Path(
        'Page 1 title-1.md')
Example #4
0
def note_1(nsx):
    note_page_json = {
        'parent_id': 'note_book1',
        'title': 'Page 1 title',
        'mtime': 1619298559,
        'ctime': 1619298539,
        'content': 'content',
        'tag': ['a_tag'], 'attachment': {
            "_-m4Hhgmp34U85IwTdWfbWw": {"md5": "e79072f793f22434740e64e93cfe5926",
                                        "name": "ns_attach_image_787491613404344687.png", "size": 186875,
                                        "width": 1848,
                                        "height": 1306,
                                        "type": "image/png",
                                        "ctime": 1616084097,
                                        "ref": "MTYxMzQwNDM0NDczN25zX2F0dGFjaF9pbWFnZV83ODc0OTE2MTM0MDQzNDQ2ODcucG5n"},
            "_YOgkfaY7aeHcezS-jgGSmA": {"md5": "6c4b828f227a096d3374599cae3f94ec",
                                        "name": "Record 2021-02-15 16:00:13.webm",
                                        "size": 9627,
                                        "width": 0,
                                        "height": 0,
                                        "type": "video/webm",
                                        "ctime": 1616084097
                                        },
            "_yITQrdarvsdg3CkL-ifh4Q": {"md5": "c4ee8b831ad1188509c0f33f0c072af5",
                                        "name": "example-attachment.pdf",
                                        "size": 14481,
                                        "width": 0,
                                        "height": 0,
                                        "type": "application/pdf",
                                        "ctime": 1616084097
                                        },
            "file_dGVzdCBwYWdlLnBkZjE2MTkyOTg3MjQ2OTE=": {"md5": "27a9aadc878b718331794c8bc50a1b8c",
                                                          "name": "test page.pdf",
                                                          "size": 320357,
                                                          "width": 0,
                                                          "height": 0,
                                                          "type": "application/pdf",
                                                          "ctime": 1619295124
                                                          }
        }
    }
    note_page = sn_note_page.NotePage(nsx, 1, note_page_json)
    note_page.notebook_folder_name = 'note_book1'
    note_page._file_name = 'page-1-title.md'
    note_page._raw_content = """<div><input class=\"syno-notestation-editor-checkbox syno-notestation-editor-checkbox-checked\" src=\"webman/3rdparty/NoteStation/images/transparent.gif\" type=\"image\" />Check 1</div><div>Pie Chart</div><div></div><div><div class=\"syno-ns-chart-object\" style=\"width: 520px; height: 350px;\" chart-data=\"[[&quot;&quot;,&quot;cost&quot;,&quot;price&quot;,&quot;value&quot;,&quot;total value&quot;],[&quot;something&quot;,500,520,540,520],[&quot;something else&quot;,520,540,560,540],[&quot;another thing&quot;,540,560,580,560]]\" chart-config=\"{&quot;range&quot;:&quot;A1:E4&quot;,&quot;direction&quot;:&quot;row&quot;,&quot;rowHeaderExisted&quot;:true,&quot;columnHeaderExisted&quot;:true,&quot;title&quot;:&quot;Pie chart title&quot;,&quot;chartType&quot;:&quot;pie&quot;,&quot;xAxisTitle&quot;:&quot;x-axis title&quot;,&quot;yAxisTitle&quot;:&quot;y axis ttile&quot;}\"></div></div><div><iframe src=\"https://www.youtube.com/embed/SqdxNUMO2cg\" width=\"420\" height=\"315\" frameborder=\"0\" allowfullscreen=\"\" youtube=\"true\" anchorhref=\"https://www.youtube.com/watch?v=SqdxNUMO2cg\"> </iframe></div><div>Below is a hyperlink to the internet</div><div><a href=\"https://github.com/kevindurston21/YANOM-Note-O-Matic\">https://github.com/kevindurston21/YANOM-Note-O-Matic</a></div><div>Below is a 3x3 Table</div><div><table style=\"width: 240px; height: 90px;\"><tbody><tr><td><b>cell R1C1</b></td><td><b>cell R1C2</b></td><td><b>cell R1C3</b></td></tr><tr><td>cell R2C1</td><td>cell R1C2</td><td>cell R1C3</td></tr><tr><td>cell R3C1</td><td>cell R1C2</td><td>cell R1C3</td></tr></tbody></table></div><div>Below is an image of the design of the line chart as seen in note-station</div><div><img class=\" syno-notestation-image-object\" src=\"webman/3rdparty/NoteStation/images/transparent.gif\" border=\"0\" width=\"600\" ref=\"MTYxMzQwNDM0NDczN25zX2F0dGFjaF9pbWFnZV83ODc0OTE2MTM0MDQzNDQ2ODcucG5n\" adjust=\"true\" /></div>"""

    return note_page
Example #5
0
def all_notes(nsx):
    list_of_notes = []
    # Note with no links
    note_page_1_json = {
        'parent_id': 'note_book1',
        'title': 'Page 1 title',
        'mtime': 1619298559,
        'ctime': 1619298539,
        'content': 'content',
        'tag': ['1'],
        'attachment': {
            "_-m4Hhgmp34U85IwTdWfbWw": {
                "md5":
                "e79072f793f22434740e64e93cfe5926",
                "name":
                "ns_attach_image_787491613404344687.png",
                "size":
                186875,
                "width":
                1848,
                "height":
                1306,
                "type":
                "image/png",
                "ctime":
                1616084097,
                "ref":
                "MTYxMzQwNDM0NDczN25zX2F0dGFjaF9pbWFnZV83ODc0OTE2MTM0MDQzNDQ2ODcucG5n"
            },
            "_YOgkfaY7aeHcezS-jgGSmA": {
                "md5": "6c4b828f227a096d3374599cae3f94ec",
                "name": "Record 2021-02-15 16:00:13.webm",
                "size": 9627,
                "width": 0,
                "height": 0,
                "type": "video/webm",
                "ctime": 1616084097
            },
            "_yITQrdarvsdg3CkL-ifh4Q": {
                "md5": "c4ee8b831ad1188509c0f33f0c072af5",
                "name": "example-attachment.pdf",
                "size": 14481,
                "width": 0,
                "height": 0,
                "type": "application/pdf",
                "ctime": 1616084097
            },
            "file_dGVzdCBwYWdlLnBkZjE2MTkyOTg3MjQ2OTE=": {
                "md5": "27a9aadc878b718331794c8bc50a1b8c",
                "name": "test page.pdf",
                "size": 320357,
                "width": 0,
                "height": 0,
                "type": "application/pdf",
                "ctime": 1619295124
            }
        }
    }
    note_page_1 = sn_note_page.NotePage(nsx, 1, note_page_1_json)
    note_page_1.notebook_folder_name = 'note_book1'
    note_page_1._file_name = 'page-1-title.md'
    note_page_1._raw_content = """<div>Below is a hyperlink to the internet</div><div><a href=\"https://github.com/kevindurston21/YANOM-Note-O-Matic\">https://github.com/kevindurston21/YANOM-Note-O-Matic</a></div>"""
    list_of_notes.append(note_page_1)

    # note with link to note in different notebook
    note_page_2_json = {
        'parent_id': 'note_book1',
        'title': 'Page 2 title',
        'mtime': 1619298559,
        'ctime': 1619298539,
        'attachment': {},
        'content': 'content',
        'tag': ['2']
    }
    note_page_2 = sn_note_page.NotePage(nsx, 1, note_page_2_json)
    note_page_2.notebook_folder_name = 'note_book1'
    note_page_2._file_name = 'page-2-title.md'
    note_page_2._raw_content = """<div>Below is a hyperlink to the internet</div><div><a href=\"https://github.com/kevindurston21/YANOM-Note-O-Matic\">https://github.com/kevindurston21/YANOM-Note-O-Matic</a></div><div>Below is a link to page 8</div><div><a href=\"notestation://remote/self/1234-8\">Page 8 title</a></div>"""
    list_of_notes.append(note_page_2)

    # note with link to note in same notebook
    note_page_3_json = {
        'parent_id': 'note_book1',
        'title': 'Page 3 title',
        'mtime': 1619298559,
        'ctime': 1619298539,
        'attachment': {},
        'content': 'content',
        'tag': ['3']
    }
    note_page_3 = sn_note_page.NotePage(nsx, 1, note_page_3_json)
    note_page_3.notebook_folder_name = 'note_book1'
    note_page_3._file_name = 'pag3-3-title.md'
    note_page_3._raw_content = """<div>Below is a hyperlink to the internet</div><div><a href=\"https://github.com/kevindurston21/YANOM-Note-O-Matic\">https://github.com/kevindurston21/YANOM-Note-O-Matic</a></div><div>Below is a link page 1</div><div><a href=\"notestation://remote/self/1234-1\">Page 1 title</a></div>"""
    list_of_notes.append(note_page_3)

    # note with link to renamed link to page in same notebook when there is also another good link on another page
    note_page_4_json = {
        'parent_id': 'note_book1',
        'title': 'Page 4 title',
        'mtime': 1619298559,
        'ctime': 1619298539,
        'attachment': {},
        'content': 'content',
        'tag': ['4']
    }
    note_page_4 = sn_note_page.NotePage(nsx, 1, note_page_4_json)
    note_page_4.notebook_folder_name = 'note_book1'
    note_page_4._file_name = 'page-4-title.md'
    note_page_4._raw_content = """<div>Below is a hyperlink to the internet</div><div><a href=\"https://github.com/kevindurston21/YANOM-Note-O-Matic\">https://github.com/kevindurston21/YANOM-Note-O-Matic</a></div><div>Below is a link ranamed link to page 1</div><div><a href=\"notestation://remote/self/1234-2\">Page 1 renamed</a></div>"""
    list_of_notes.append(note_page_4)

    # note with link to renamed link to page in different notebook that is also a duplicated title
    note_page_5_json = {
        'parent_id': 'note_book1',
        'title': 'Page 5 title',
        'mtime': 1619298559,
        'ctime': 1619298539,
        'attachment': {},
        'content': 'content',
        'tag': ['5']
    }
    note_page_5 = sn_note_page.NotePage(nsx, 1, note_page_5_json)
    note_page_5.notebook_folder_name = 'note_book1'
    note_page_5._file_name = 'page-5-title.md'
    note_page_5._raw_content = """<div>Below is a hyperlink to the internet</div><div><a href=\"https://github.com/kevindurston21/YANOM-Note-O-Matic\">https://github.com/kevindurston21/YANOM-Note-O-Matic</a></div><div>Below is a renamed link to page 8</div><div><a href=\"notestation://remote/self/1234-8\">Page 8 renamed</a></div>"""
    list_of_notes.append(note_page_5)

    # note with duplicated title across 2 notebooks - first duplicate
    note_page_6_json = {
        'parent_id': 'note_book1',
        'title': 'Duplicate page title across notebooks',
        'mtime': 1619298559,
        'ctime': 1619298539,
        'attachment': {},
        'content': 'content',
        'tag': ['6']
    }
    note_page_6 = sn_note_page.NotePage(nsx, 1, note_page_6_json)
    note_page_6.notebook_folder_name = 'note_book1'
    note_page_6._file_name = 'duplicate-page-title2.md'
    note_page_6._raw_content = """<div>Below is a hyperlink to the internet</div><div><a href=\"https://github.com/kevindurston21/YANOM-Note-O-Matic\">https://github.com/kevindurston21/YANOM-Note-O-Matic</a></div><div>Below is a link to duplicated title across 2 notebooks</div><div><a href=\"notestation://remote/self/1234-7\">Page 5 title</a></div>"""
    list_of_notes.append(note_page_6)

    # note with duplicated title across 2 notebooks - second duplicate
    note_page_7_json = {
        'parent_id': 'note_book2',
        'title': 'Duplicate page title across notebooks',
        'mtime': 1619298559,
        'ctime': 1619298539,
        'attachment': {},
        'content': 'content',
        'tag': ['7']
    }
    note_page_7 = sn_note_page.NotePage(nsx, 1, note_page_7_json)
    note_page_7.notebook_folder_name = 'note_book2'
    note_page_7._file_name = 'duplicate-page-title2-1.md'
    note_page_7._raw_content = """<div>Below is a hyperlink to the internet</div><div><a href=\"https://github.com/kevindurston21/YANOM-Note-O-Matic\">https://github.com/kevindurston21/YANOM-Note-O-Matic</a></div><div>Below is a link to duplicated title across 2 notebooks</div><div><a href=\"notestation://remote/self/1234-6\">Page 5 title</a></div>"""
    list_of_notes.append(note_page_7)

    # note with duplicate title to note page in same notebook - first page
    note_page_8_json = {
        'parent_id': 'note_book2',
        'title': 'Page 8 title',
        'mtime': 1619298559,
        'ctime': 1619298539,
        'attachment': {},
        'content': 'content',
        'tag': ['8']
    }
    note_page_8 = sn_note_page.NotePage(nsx, 1, note_page_8_json)
    note_page_8.notebook_folder_name = 'note_book2'
    note_page_8._file_name = 'page-8-title.md'
    note_page_8._raw_content = """<div>Below is a hyperlink to the internet</div><div><a href=\"https://github.com/kevindurston21/YANOM-Note-O-Matic\">https://github.com/kevindurston21/YANOM-Note-O-Matic</a></div><div>Below is a link to page 2</div><div><a href=\"notestation://remote/self/1234-2\">Page 2 title</a></div>"""
    list_of_notes.append(note_page_8)

    # note with duplicate title to note page in same notebook - second page
    note_page_9_json = {
        'parent_id': 'note_book2',
        'title': 'Page 8 title',
        'mtime': 1619298559,
        'ctime': 1619298539,
        'attachment': {},
        'content': 'content',
        'tag': ['9']
    }
    note_page_9 = sn_note_page.NotePage(nsx, 1, note_page_9_json)
    note_page_9.notebook_folder_name = 'note_book2'
    note_page_9._file_name = 'page-8-title-1.md'
    note_page_9._raw_content = """<div>Below is a hyperlink to the internet</div><div><a href=\"https://github.com/kevindurston21/YANOM-Note-O-Matic\">https://github.com/kevindurston21/YANOM-Note-O-Matic</a></div><div>Below is a link to page 2</div><div><a href=\"notestation://remote/self/1234-2\">Page 2 title</a></div>"""
    list_of_notes.append(note_page_9)

    # note to be linked to from a renamed page, note this page must have no good links pointing to it - first page
    note_page_10_json = {
        'parent_id': 'note_book2',
        'title': 'Page 10 title',
        'mtime': 1619298559,
        'ctime': 1619298539,
        'attachment': {},
        'content': 'content',
        'tag': ['10']
    }
    note_page_10 = sn_note_page.NotePage(nsx, 1, note_page_10_json)
    note_page_10.notebook_folder_name = 'note_book2'
    note_page_10._file_name = 'page-10-title.md'
    note_page_10._raw_content = """<div>Below is a hyperlink to the internet</div><div><a href=\"https://github.com/kevindurston21/YANOM-Note-O-Matic\">https://github.com/kevindurston21/YANOM-Note-O-Matic</a></div><div>Below is a link to page 2</div><div><a href=\"notestation://remote/self/1234-2\">Page 2 title</a></div>"""
    list_of_notes.append(note_page_10)

    # renamed link pointing to a page that has no good links pointing to it - second page
    note_page_11_json = {
        'parent_id': 'note_book2',
        'title': 'Page 11 title',
        'mtime': 1619298559,
        'ctime': 1619298539,
        'attachment': {},
        'content': 'content',
        'tag': ['11']
    }
    note_page_11 = sn_note_page.NotePage(nsx, 1, note_page_11_json)
    note_page_11.notebook_folder_name = 'note_book2'
    note_page_11._file_name = 'page-11-title.md'
    note_page_11._raw_content = """<div>Below is a hyperlink to the internet</div><div><a href=\"https://github.com/kevindurston21/YANOM-Note-O-Matic\">https://github.com/kevindurston21/YANOM-Note-O-Matic</a></div><div>Below is a renamed link to page 10</div><div><a href=\"notestation://remote/self/1234-10\">Page 10 renamed</a></div>"""
    list_of_notes.append(note_page_11)

    return list_of_notes