def test_add_remove(self):
        filepath = os.path.join(TESTER_NOTES_PATH, 'zen' + NOTE_EXTENSION)
        zen_note = NoteModel(filepath)

        # file doesn't exist yet
        self.assertFalse(os.path.exists(filepath))
        self.assertEqual(zen_note.content, '')
        self.assertEqual(zen_note.timestamp, -1)
        self.assertEqual(zen_note.metadata, dict())
        self.assertEqual(zen_note.history, list())
        self.assertEqual(zen_note.wordset, '')
        self.assertFalse(zen_note.recorded)
        self.assertFalse(zen_note.pinned)

        # add content
        content = NoteModel.enc_read(ZEN_TEXT_FILE)
        zen_note.content = content
        self.assertTrue(os.path.exists(filepath))
        self.assertNotEqual(zen_note.metadata, dict())
        self.assertNotEqual(zen_note.timestamp, -1)

        # remove note
        zen_note.remove()
        self.assertFalse(os.path.exists(filepath))
        self.assertEqual(zen_note.content, '')
        self.assertEqual(zen_note.timestamp, -1)
        self.assertEqual(zen_note.metadata, dict())
        self.assertEqual(zen_note.history, list())
        self.assertEqual(zen_note.wordset, '')
        self.assertFalse(zen_note.recorded)
        self.assertFalse(zen_note.pinned)
    def test_add_record(self):
        filepath = os.path.join(TESTER_NOTES_PATH, 'zen' + NOTE_EXTENSION)
        zen_note = NoteModel(filepath)

        # add content
        content = NoteModel.enc_read(ZEN_TEXT_FILE)
        zen_note.content = content

        # record
        self.assertFalse(os.path.exists(zen_note.historypath))
        self.assertEqual(zen_note.load_old_note(0), (None, None))
        zen_note.record(TESTER_NOTES_PATH)
        self.assertTrue(os.path.exists(zen_note.historypath))
        self.assertNotEqual(zen_note.history, list())
        self.assertNotEqual(zen_note.load_old_note(0), (None, None))
Exemple #3
0
    def new_note(self):
        tagged_title = self.ui.omniBar.text()
        if tagged_title == '':
            return
        if len(self.notesList.findItems(tagged_title,
                                        QtCore.Qt.MatchWildcard)) > 0:
            return

        # build new note name
        self.search.query = tagged_title

        if len(self.search.use_words) == 0:
            # no words to use in the title
            return

        title = ' '.join(self.search.use_words)
        tags = ' '.join(self.search.use_tags)

        # build the new note
        filename = clean_filename(title) + NOTE_EXTENSION
        filepath = os.path.join(self.notes_dir, filename)
        content = title + '\n'
        new_note = NoteModel(filepath)
        new_note.metadata['title'] = title
        new_note.metadata['tags'] = tags
        new_note.content = content

        # update
        new_note.save_to_file()
        self.notesList.update_list()

        self.ui.omniBar.setText('')
        self.query = ''
        try:
            item = self.notesList.findItems(tagged_title,
                                            QtCore.Qt.MatchWildcard)[0]
            self.notesList.setCurrentItem(item)
        except IndexError:
            for item in self.notesList.all_items[::-1]:
                if not item.notemodel.pinned:
                    self.notesList.setCurrentItem(item)

        # set the focus on the editor and move the cursor to the end
        self.noteEditor.setFocus()
        cursor = self.noteEditor.textCursor()
        cursor.movePosition(QtGui.QTextCursor.MoveOperation.End,
                            QtGui.QTextCursor.MoveMode.MoveAnchor)
        self.noteEditor.setTextCursor(cursor)
    def test_add_rename(self):
        filepath = os.path.join(TESTER_NOTES_PATH, 'zen' + NOTE_EXTENSION)
        zen_note = NoteModel(filepath)

        # add content
        content = NoteModel.enc_read(ZEN_TEXT_FILE)
        zen_note.content = content
        self.assertTrue(os.path.exists(filepath))
        self.assertNotEqual(zen_note.metadata, dict())
        self.assertNotEqual(zen_note.timestamp, -1)

        # rename
        filepath2 = os.path.join(TESTER_NOTES_PATH, 'zen2' + NOTE_EXTENSION)
        zen_note.notename = 'zen2'
        self.assertTrue(os.path.exists(filepath2))
        self.assertEqual(zen_note.notename, 'zen2')