Пример #1
0
    def test_on_deleted_directory(self):
        path = _path('some_notebook')

        shutil.rmtree(path)
        e = Event(is_directory=True, src_path=path, dest_path=None)
        self.handler.on_deleted(e)

        self.assertFalse(self.nomadic.index.note_at(_path('some_notebook/a cool note.md')))
Пример #2
0
    def test_clean_note_resources(self):
        note = Note(_path('my note.md'))
        note_resource = _path('_resources/my note/foo.jpg')

        self.assertTrue(exists(note_resource))

        note.clean_resources()

        self.assertFalse(exists(note_resource))
Пример #3
0
    def test_on_deleted_directory(self):
        path = _path('some_notebook')

        shutil.rmtree(path)
        e = Event(is_directory=True, src_path=path, dest_path=None)
        self.handler.on_deleted(e)

        self.assertFalse(
            self.nomadic.index.note_at(_path('some_notebook/a cool note.md')))
Пример #4
0
    def test_clean_note_resources(self):
        note = Note(_path('my note.md'))
        note_resource = _path('_resources/my note/foo.jpg')

        self.assertTrue(exists(note_resource))

        note.clean_resources()

        self.assertFalse(exists(note_resource))
Пример #5
0
    def test_delete_note(self):
        src = _path('my note.md')
        src_resource = _path('_resources/my note/foo.jpg')

        self.assertTrue(exists(src))
        self.assertTrue(exists(src_resource))

        note = Note(src)
        note.delete()

        self.assertFalse(exists(src))
        self.assertFalse(exists(src_resource))
Пример #6
0
    def test_delete_note(self):
        src = _path('my note.md')
        src_resource = _path('_resources/my note/foo.jpg')

        self.assertTrue(exists(src))
        self.assertTrue(exists(src_resource))

        note = Note(src)
        note.delete()

        self.assertFalse(exists(src))
        self.assertFalse(exists(src_resource))
Пример #7
0
    def test_on_moved_directory(self):
        path = _path('some_notebook')
        path_new = _path('moved_notebook')

        shutil.move(path, path_new)
        e = Event(is_directory=True, src_path=path, dest_path=path_new)
        self.handler.on_moved(e)

        old_note = Note(_path('some_notebook/a cool note.md'))
        self.assertFalse(self.nomadic.index.note_at(old_note.path.rel))

        new_note = Note(_path('moved_notebook/a cool note.md'))
        self.assertTrue(self.nomadic.index.note_at(new_note.path.rel))
Пример #8
0
    def test_on_moved_directory(self):
        path = _path('some_notebook')
        path_new = _path('moved_notebook')

        shutil.move(path, path_new)
        e = Event(is_directory=True, src_path=path, dest_path=path_new)
        self.handler.on_moved(e)

        old_note = Note(_path('some_notebook/a cool note.md'))
        self.assertFalse(self.nomadic.index.note_at(old_note.path.rel))

        new_note = Note(_path('moved_notebook/a cool note.md'))
        self.assertTrue(self.nomadic.index.note_at(new_note.path.rel))
Пример #9
0
    def test_on_moved(self):
        note = Note(_path('my note.md'))

        note_new = Note(_path('some_notebook/my moved note.md'))

        self.assertTrue(self.nomadic.index.note_at(note.path.rel))

        shutil.move(note.path.abs, note_new.path.abs)
        e = Event(is_directory=False, src_path=note.path.abs, dest_path=note_new.path.abs)
        self.handler.on_moved(e)

        self.assertFalse(self.nomadic.index.note_at(note.path.rel))
        self.assertTrue(self.nomadic.index.note_at(note_new.path.rel))
Пример #10
0
    def test_on_moved(self):
        note = Note(_path('my note.md'))

        note_new = Note(_path('some_notebook/my moved note.md'))

        self.assertTrue(self.nomadic.index.note_at(note.path.rel))

        shutil.move(note.path.abs, note_new.path.abs)
        e = Event(is_directory=False,
                  src_path=note.path.abs,
                  dest_path=note_new.path.abs)
        self.handler.on_moved(e)

        self.assertFalse(self.nomadic.index.note_at(note.path.rel))
        self.assertTrue(self.nomadic.index.note_at(note_new.path.rel))
Пример #11
0
    def test_update_index(self):
        with open(_path('new note.md'), 'w') as new_note:
            new_note.write('foobar')

        self.index.update()

        self.assertEqual(self.index.size, self.expected_notes + 1)
Пример #12
0
    def test_add_note(self):
        note = Note(_path('new note.md'))
        note.write('foobar')

        self.index.add_note(note)

        self.assertEqual(self.index.size, self.expected_notes + 1)
Пример #13
0
    def test_add_note(self):
        note = Note(_path('new note.md'))
        note.write('foobar')

        self.index.add_note(note)

        self.assertEqual(self.index.size, self.expected_notes + 1)
Пример #14
0
    def test_update_index(self):
        with open(_path('new note.md'), 'w') as new_note:
            new_note.write('foobar')

        self.index.update()

        self.assertEqual(self.index.size, self.expected_notes + 1)
Пример #15
0
    def test_on_created(self):
        note = Note(_path('a new note.md'))
        note.write('# a new note')

        e = Event(is_directory=False, src_path=note.path.abs, dest_path=None)
        self.handler.on_created(e)

        self.assertTrue(self.nomadic.index.note_at(note.path.rel))
Пример #16
0
    def test_on_created(self):
        note = Note(_path('a new note.md'))
        note.write('# a new note')

        e = Event(is_directory=False, src_path=note.path.abs, dest_path=None)
        self.handler.on_created(e)

        self.assertTrue(self.nomadic.index.note_at(note.path.rel))
Пример #17
0
    def test_update_note(self):
        note = Note(_path('my note.md'))
        note.write(u'changed note content')

        self.index.update_note(note)

        note_ = self.index.note_at(note.path.rel)
        self.assertTrue(note_)
        self.assertEqual(note_['content'], u'changed note content')
Пример #18
0
    def test_move_note(self):
        src = _path('my note.md')
        dest = _path('some_notebook/my moved note.md')

        src_resource = _path('_resources/my note/foo.jpg')
        dest_resource = _path('some_notebook/_resources/my moved note/foo.jpg')

        note = Note(src)
        note.move(dest)

        self.assertTrue(exists(dest))
        self.assertTrue(exists(dest_resource))

        self.assertFalse(exists(src))
        self.assertFalse(exists(src_resource))

        self.assertEquals(note.path.abs, dest)
        self.assertEquals(note.title, 'my moved note')
Пример #19
0
    def test_move_note(self):
        src = _path('my note.md')
        dest = _path('some_notebook/my moved note.md')

        src_resource = _path('_resources/my note/foo.jpg')
        dest_resource = _path('some_notebook/_resources/my moved note/foo.jpg')

        note = Note(src)
        note.move(dest)

        self.assertTrue(exists(dest))
        self.assertTrue(exists(dest_resource))

        self.assertFalse(exists(src))
        self.assertFalse(exists(src_resource))

        self.assertEquals(note.path.abs, dest)
        self.assertEquals(note.title, 'my moved note')
Пример #20
0
    def test_update_note(self):
        note = Note(_path('my note.md'))
        note.write(u'changed note content')

        self.index.update_note(note)

        note_ = self.index.note_at(note.path.rel)
        self.assertTrue(note_)
        self.assertEqual(note_['content'], u'changed note content')
Пример #21
0
    def test_on_modified(self):
        note = Note(_path('my note.md'))

        note.write('a changed note')

        e = Event(is_directory=False, src_path=note.path.abs, dest_path=None)
        self.handler.on_modified(e)

        note = self.nomadic.index.note_at(note.path.rel)
        self.assertEqual('a changed note', note['content'])
Пример #22
0
    def test_on_deleted(self):
        note = Note(_path('my note.md'))

        self.assertTrue(self.nomadic.index.note_at(note.path.rel))

        os.remove(note.path.abs)
        e = Event(is_directory=False, src_path=note.path.abs, dest_path=None)
        self.handler.on_deleted(e)

        self.assertFalse(self.nomadic.index.note_at(note.path.rel))
Пример #23
0
    def test_on_modified(self):
        note = Note(_path('my note.md'))

        note.write('a changed note')

        e = Event(is_directory=False, src_path=note.path.abs, dest_path=None)
        self.handler.on_modified(e)

        note = self.nomadic.index.note_at(note.path.rel)
        self.assertEqual('a changed note', note['content'])
Пример #24
0
    def test_on_deleted(self):
        note = Note(_path('my note.md'))

        self.assertTrue(self.nomadic.index.note_at(note.path.rel))

        os.remove(note.path.abs)
        e = Event(is_directory=False, src_path=note.path.abs, dest_path=None)
        self.handler.on_deleted(e)

        self.assertFalse(self.nomadic.index.note_at(note.path.rel))
Пример #25
0
    def test_update_references_html(self):
        path = _path('another note.html')

        ref = _path('some_notebook/a cool note.md')
        ref_new = _path('moved cool note.md')

        rel_link = 'some_notebook/a cool note.md'
        rel_link_ = quote('some_notebook/a cool note.html')
        rel_link_new = quote('moved cool note.md')
        rel_link_new_ = quote('moved cool note.html')

        with open(path, 'r') as note:
            note_content = note.read()
            self.assertTrue(rel_link in note_content)
            self.assertFalse(rel_link_new in note_content)

        self.handler.update_references(ref, ref_new)

        with open(path, 'r') as note:
            note_content = note.read()
            self.assertFalse(rel_link in note_content)
            self.assertTrue(rel_link_new in note_content)
Пример #26
0
    def test_update_references_html(self):
        path = _path('another note.html')

        ref = _path('some_notebook/a cool note.md')
        ref_new = _path('moved cool note.md')

        rel_link = 'some_notebook/a cool note.md'
        rel_link_ = quote('some_notebook/a cool note.html')
        rel_link_new = quote('moved cool note.md')
        rel_link_new_ = quote('moved cool note.html')

        with open(path, 'r') as note:
            note_content = note.read()
            self.assertTrue(rel_link in note_content)
            self.assertFalse(rel_link_new in note_content)

        self.handler.update_references(ref, ref_new)

        with open(path, 'r') as note:
            note_content = note.read()
            self.assertFalse(rel_link in note_content)
            self.assertTrue(rel_link_new in note_content)
Пример #27
0
    def test_update_references_markdown(self):
        path = _path('some_notebook/a cool note.md')

        ref = _path('some_notebook/nested book/empty.md')
        ref_new = _path('moved empty note.md')

        rel_link = 'nested book/empty.md'
        rel_link_ = quote('nested book/empty.html')
        rel_link_new = '../moved empty note.md'
        rel_link_new_ = quote('../moved empty note.html')

        with open(path, 'r') as note:
            note_content = note.read()
            self.assertTrue(rel_link in note_content)
            self.assertFalse(rel_link_new in note_content)

        self.handler.update_references(ref, ref_new)

        with open(path, 'r') as note:
            note_content = note.read()
            self.assertFalse(rel_link in note_content)
            self.assertTrue(rel_link_new in note_content)
Пример #28
0
    def test_update_references_markdown(self):
        path = _path('some_notebook/a cool note.md')

        ref = _path('some_notebook/nested book/empty.md')
        ref_new = _path('moved empty note.md')

        rel_link = 'nested book/empty.md'
        rel_link_ = quote('nested book/empty.html')
        rel_link_new = '../moved empty note.md'
        rel_link_new_ = quote('../moved empty note.html')

        with open(path, 'r') as note:
            note_content = note.read()
            self.assertTrue(rel_link in note_content)
            self.assertFalse(rel_link_new in note_content)

        self.handler.update_references(ref, ref_new)

        with open(path, 'r') as note:
            note_content = note.read()
            self.assertFalse(rel_link in note_content)
            self.assertTrue(rel_link_new in note_content)
Пример #29
0
 def test_content_pdf(self):
     note = Note(_path('womp.pdf'))
     self.assertEqual(note.content, 'I\'m a PDF')
Пример #30
0
    def test_delete_note(self):
        note = Note(_path('my note.md'))
        self.index.delete_note(note)
        self.assertEqual(self.index.size, self.expected_notes - 1)

        self.assertTrue(not self.index.note_at(note.path.rel))
Пример #31
0
 def test_plaintext_html(self):
     note = Note(_path('test.html'))
     self.assertEqual(note.plaintext, 'Test HTML\n\n\n\n\n    This is a test')
Пример #32
0
    def test_delete_note(self):
        note = Note(_path('my note.md'))
        self.index.delete_note(note)
        self.assertEqual(self.index.size, self.expected_notes - 1)

        self.assertTrue(not self.index.note_at(note.path.rel))
Пример #33
0
 def test_plaintext_markdown(self):
     note = Note(_path('my note.md'))
     self.assertEqual(note.plaintext, 'HEY HI\nfoo bar qua')
Пример #34
0
 def test_content_pdf(self):
     note = Note(_path('womp.pdf'))
     self.assertEqual(note.content, 'I\'m a PDF')
Пример #35
0
 def test_plaintext_markdown(self):
     note = Note(_path('my note.md'))
     self.assertEqual(note.plaintext, 'HEY HI\nfoo bar qua')
Пример #36
0
 def test_plaintext_html(self):
     note = Note(_path('test.html'))
     self.assertEqual(note.plaintext,
                      'Test HTML\n\n\n\n\n    This is a test')