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')))
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))
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')))
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))
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))
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))
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)
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)
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))
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')
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')
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'])
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))
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)
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)
def test_content_pdf(self): note = Note(_path('womp.pdf')) self.assertEqual(note.content, 'I\'m a PDF')
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))
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')
def test_plaintext_markdown(self): note = Note(_path('my note.md')) self.assertEqual(note.plaintext, 'HEY HI\nfoo bar qua')