Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
Add test_cli_list_notes
Browse files Browse the repository at this point in the history
Ref #8
  • Loading branch information
djmoch committed Sep 12, 2018
1 parent 503033e commit bae28cc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
12 changes: 6 additions & 6 deletions nncli/nncli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand All @@ -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))
Expand Down Expand Up @@ -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')

Expand All @@ -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"""
Expand All @@ -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"""
Expand All @@ -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"""
Expand Down
25 changes: 21 additions & 4 deletions tests/test_nncli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import nncli.nncli
from nncli.notes_db import ReadError
import nncli.utils

@pytest.fixture
def mock_nncli(mocker):
Expand All @@ -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()
Expand All @@ -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"""
Expand All @@ -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():
Expand Down

0 comments on commit bae28cc

Please sign in to comment.