Exemplo n.º 1
0
class NoteTest(unittest.TestCase):

    def setUp(self):
        self.path = file_dir + '/tmp'
        self.ext = '.txt'
        self.editor = 'subl'
        self.note = Note(self.path, self.ext, self.editor)

    def tearDown(self):
        #if os.path.isdir(self.path): If its not there, something went wrong!
        shutil.rmtree(self.path)
        self.note = None

    def test_empty_list(self):
        """
        New Note, we don't have entries.
        """
        self.failIf(self.note.list())

    def test_new(self):
        """
        Create a new Note.
        """
        self.failUnless(self.note.new("TestNote", "LoremIpsumNote"))

    def test_edit(self):
        self.note.edit("TestNote", "LoremIpsumNote")
        self.note.edit("TestNote", "MoreLoreMore")

    def test_list(self):
        self.failIf(self.note.list())
        self.note.new("TestNote", "LoremIpsumNote")
        self.failUnless(self.note.list() == "TestNote")

    def test_exists(self):
        self.note.list()
        self.note.new("TestNote", "LoremIpsumNote")
        self.failUnless(self.note.exists("TestNote"))
        self.failIf(self.note.exists("DoesNotExist"))

    def test_get_existing(self):
        self.note.new("TestNote", "LoremIpsumNote")
        self.failUnless(self.note.get("TestNote") == "LoremIpsumNote")

    def test_get_non_existing(self):
        self.failIf(self.note.get("NoneNote"))

    def test_delete(self):
        self.note.new("TestNote", "LoremIpsumNote")
        self.failUnless(self.note.exists("TestNote"))
        self.note.delete("TestNote")
        self.failIf(self.note.exists("TestNote"))
        #It should not crap out if the note does not exist.
        self.note.delete("TestNote")
Exemplo n.º 2
0
    def del_note(self, note_id):
        _note_id = int(note_id)
        _note = Note(note_id)
        _note_context = _note.read()
        _note.delete()

        _note_info = self.__load_note_info_from_cache()
        if _note_info != None:
            if _note.note_id in _note_info['note_id_list']:
                _note_info['note_count'] -= 1
                _note_info['note_id_list'].remove(_note.note_id)
            self.__reset_note_info_to_cache(_note_info)

        User(_note_context['creator_id']).update_user_entity_note_count(
            delta=-1)
        CleanNoteMessageTask.delay(entity_id=self.entity_id, note_id=_note_id)
Exemplo n.º 3
0
    def delete_note(self, widget, note_id):
        # confirmation message to check if the note is going to be deleted
        dialog = Gtk.MessageDialog(
            transient_for=self,
            flags=0,
            message_type=Gtk.MessageType.QUESTION,
            buttons=Gtk.ButtonsType.YES_NO,
            text="Confirm delete",
            title="Confirmation required",
            secondary_text=
            "Are you sure you want to delete this note? This operation cannot be undone."
        )

        # run the dialog, taking control, then destroy it after it receives a response.
        response = dialog.run()
        dialog.destroy()
        if (response == Gtk.ResponseType.NO):
            return

        # check if the note was deleted.
        deleted = Note.delete(self.connection.get_instance(), note_id)
        if not (deleted):
            self.create_error_dialog(
                "An error has occured!", None,
                "An error has occured while trying to delete the selected note."
            )
            return

        # reload the notes widget.
        self.reload_notes()