nncli

NextCloud Notes Command Line Interface
git clone git://git.danielmoch.com/nncli.git
Log | Files | Refs | LICENSE

commit bae28cc30623c8e1da63e7233afd13912ce76cb7
parent 503033e6ea2a5fdd99568358d95fbb2a5d93f2a0
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Tue, 11 Sep 2018 22:25:42 -0400

Add test_cli_list_notes

Ref #8

Diffstat:
Mnncli/nncli.py | 12++++++------
Mtests/test_nncli.py | 25+++++++++++++++++++++----
2 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/nncli/nncli.py b/nncli/nncli.py @@ -130,7 +130,7 @@ def cli_note_create(self, from_stdin, title): if content: self.logger.log('New note created') self.ndb.create_note(content) - self.sync_notes() + self.ndb.sync_now() def cli_note_import(self, from_stdin): """Import a note from the command line""" @@ -145,7 +145,7 @@ def cli_note_import(self, from_stdin): note = json.loads(raw) self.logger.log('New note created') self.ndb.import_note(note) - self.sync_notes() + self.ndb.sync_now() except json.decoder.JSONDecodeError as ex: self.logger.log( '(IMPORT) Decoding JSON has failed: {}'.format(ex)) @@ -192,7 +192,7 @@ def cli_note_edit(self, key): if md5_old != md5_new: self.logger.log('Note updated') self.ndb.set_note_content(note['localkey'], content) - self.sync_notes() + self.ndb.sync_now() else: self.logger.log('Note unchanged') @@ -204,7 +204,7 @@ def cli_note_delete(self, key, delete): return self.ndb.set_note_deleted(key, delete) - self.sync_notes() + self.ndb.sync_now() def cli_note_favorite(self, key, favorite): """Favorite a note from the command line""" @@ -214,7 +214,7 @@ def cli_note_favorite(self, key, favorite): return self.ndb.set_note_favorite(key, favorite) - self.sync_notes() + self.ndb.sync_now() def cli_note_category_get(self, key): """Get a note category from the command line""" @@ -234,7 +234,7 @@ def cli_note_category_set(self, key, category): return self.ndb.set_note_category(key, category.lower()) - self.sync_notes() + self.ndb.sync_now() def cli_note_category_rm(self, key): """Remove a note category from the command line""" diff --git a/tests/test_nncli.py b/tests/test_nncli.py @@ -7,6 +7,7 @@ import nncli.nncli from nncli.notes_db import ReadError +import nncli.utils @pytest.fixture def mock_nncli(mocker): @@ -24,7 +25,6 @@ def test_init_no_local_db(mocker, mock_nncli): """test initialization when there is no local notes database""" mocker.patch('os.path.exists', new=mocker.MagicMock(return_value=False)) - mocker.patch.object(nncli.nncli.NotesDB, 'sync_now') nn_obj = nncli.nncli.Nncli(False) assert nn_obj.config.get_config.call_count == 2 nn_obj.ndb.set_update_view.assert_called_once() @@ -47,6 +47,7 @@ def test_init_notesdb_fail(mocker, mock_nncli): ) with pytest.raises(SystemExit): nn = nncli.nncli.Nncli(False) + os.path.exists.assert_called_once() def test_gui(mocker, mock_nncli): """test starting the gui""" @@ -56,9 +57,25 @@ def test_gui(mocker, mock_nncli): assert nn_obj.ndb.log == nn_obj.nncli_gui.log nn_obj.nncli_gui.run.assert_called_once() -@pytest.mark.skip -def test_cli_list_notes(): - pass +def test_cli_list_notes(mocker, mock_nncli): + """test listing notes from the command line""" + test_note = ( + [nncli.utils.KeyValueObject(key='test_key', + note='test_note')], + [], + [] + ) + mocker.patch('nncli.utils.get_note_flags', + new=mocker.Mock(return_value='flg')) + mocker.patch('nncli.utils.get_note_title', + new=mocker.Mock(return_value='test_title')) + mocker.patch('nncli.nncli.print') + nn_obj = nncli.nncli.Nncli(False) + mocker.patch.object(nn_obj.ndb, 'filter_notes', + new=mocker.Mock(return_value=test_note)) + print(nn_obj.ndb.filter_notes) + nn_obj.cli_list_notes(False, 'test_search_string') + nncli.nncli.print.assert_called_once_with('test_key [flg] test_title') @pytest.mark.skip def test_cli_note_dump():