nncli

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

commit 503033e6ea2a5fdd99568358d95fbb2a5d93f2a0
parent 34392edc521e59850568293f56971c65c4188762
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Tue, 11 Sep 2018 07:01:18 -0400

Implement test_gui test method in nncli

Ref #8

Diffstat:
M.gitignore | 1+
Mnncli/nncli.py | 6+-----
Atests/test_gui.py | 129+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtests/test_nncli.py | 198++++++++++++++-----------------------------------------------------------------
4 files changed, 165 insertions(+), 169 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -6,3 +6,4 @@ MANIFEST .pytest_cache/ docs/build/ .tox +htmlcov/ diff --git a/nncli/nncli.py b/nncli/nncli.py @@ -49,13 +49,9 @@ def __init__(self, do_server_sync, verbose=False, config_file=None): self.config.state.verbose = True self.logger.log('nncli database doesn\'t exist,' ' forcing full sync...') - self.sync_notes() + self.ndb.sync_now() self.config.state.verbose = verbose - def sync_notes(self): - """Sync notes with the server""" - self.ndb.sync_now(self.config.state.do_server_sync) - def gui(self, key): """Method to initialize and display the GUI""" self.config.state.do_gui = True diff --git a/tests/test_gui.py b/tests/test_gui.py @@ -0,0 +1,129 @@ +# -*- coding: utf-8 -*- +"""tests for gui module""" +import pytest + +import nncli.gui + +@pytest.mark.skip +def test_gui_header_clear(): + pass + +@pytest.mark.skip +def test_gui_header_set(): + pass + +@pytest.mark.skip +def test_gui_header_get(): + pass + +@pytest.mark.skip +def test_gui_header_focus(): + pass + +@pytest.mark.skip +def test_gui_footer_log_clear(): + pass + +@pytest.mark.skip +def test_gui_footer_log_set(): + pass + +@pytest.mark.skip +def test_gui_footer_log_get(): + pass + +@pytest.mark.skip +def test_gui_footer_input_clear(): + pass + +@pytest.mark.skip +def test_gui_footer_input_set(): + pass + +@pytest.mark.skip +def test_gui_footer_input_get(): + pass + +@pytest.mark.skip +def test_gui_footer_focus_input(): + pass + +@pytest.mark.skip +def test_gui_body_clear(): + pass + +@pytest.mark.skip +def test_gui_body_set(): + pass + +@pytest.mark.skip +def test_gui_body_get(): + pass + +@pytest.mark.skip +def test_gui_body_focus(): + pass + +@pytest.mark.skip +def test_log_timeout(): + pass + +@pytest.mark.skip +def test_log(): + pass + +@pytest.mark.skip +def test_gui_update_view(): + pass + +@pytest.mark.skip +def test_gui_update_status_bar(): + pass + +@pytest.mark.skip +def test_gui_switch_frame_body(): + pass + +@pytest.mark.skip +def test_delete_note_callback(): + pass + +@pytest.mark.skip +def test_gui_yes_no_input(): + pass + +@pytest.mark.skip +def test_gui_search_input(): + pass + +@pytest.mark.skip +def test_gui_category_input(): + pass + +@pytest.mark.skip +def test_gui_pipe_input(): + pass + +@pytest.mark.skip +def test_gui_frame_keypress(): + pass + +@pytest.mark.skip +def test_gui_init_view(): + pass + +@pytest.mark.skip +def test_gui_clear(): + pass + +@pytest.mark.skip +def test_gui_reset(): + pass + +@pytest.mark.skip +def test_gui_stop(): + pass + +@pytest.mark.skip +def test_gui(): + pass diff --git a/tests/test_nncli.py b/tests/test_nncli.py @@ -1,174 +1,60 @@ # -*- coding: utf-8 -*- - +"""tests for nncli module""" import logging import os import pytest import shutil -from logging.handlers import RotatingFileHandler import nncli.nncli +from nncli.notes_db import ReadError @pytest.fixture def mock_nncli(mocker): - mocker.patch('logging.getLogger') + """mock the major interfaces for the Nncli class""" mocker.patch('nncli.nncli.NotesDB') mocker.patch('nncli.nncli.NncliGui') + mocker.patch('nncli.nncli.Config') + mocker.patch('nncli.nncli.Logger') mocker.patch('os.mkdir') - mocker.patch.object(RotatingFileHandler, '_open') mocker.patch('subprocess.check_output') - -def mock_get_config(mocker, return_list): - mocker.patch.object( - nncli.nncli.Config, - 'get_config', - new=mocker.MagicMock(side_effect=return_list) - ) - -def assert_initialized(): - assert logging.getLogger.call_count == 2 - RotatingFileHandler._open.assert_called_once() + mocker.patch('os.path.exists', + new=mocker.MagicMock(return_value=True)) + +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() os.mkdir.assert_called_once() + nn_obj.ndb.sync_now.assert_called_once() def test_init(mocker, mock_nncli): - mock_get_config(mocker, ['what', 'what', 'duh', 'duh', 'duh']) - nn = nncli.nncli.Nncli(False) - assert_initialized() + """test nominal initialization""" + nn_obj = nncli.nncli.Nncli(False) + nn_obj.config.get_config.assert_called_once() + nn_obj.ndb.set_update_view.assert_called_once() + assert os.mkdir.call_count == 0 def test_init_notesdb_fail(mocker, mock_nncli): - mock_get_config(mocker, ['what', 'what', 'duh', 'duh', 'duh']) + """test init when there is a notes database failure""" + mocker.patch('os.path.exists', + new=mocker.MagicMock(return_value=True)) mocker.patch('nncli.nncli.NotesDB', - new=mocker.MagicMock(side_effect=SystemExit) - ) + new=mocker.MagicMock(side_effect=ReadError) + ) with pytest.raises(SystemExit): nn = nncli.nncli.Nncli(False) -@pytest.mark.skip -def test_exec_diff_on_note(): - pass - -@pytest.mark.skip -def test_gui_header_clear(): - pass - -@pytest.mark.skip -def test_gui_header_set(): - pass - -@pytest.mark.skip -def test_gui_header_get(): - pass - -@pytest.mark.skip -def test_gui_header_focus(): - pass - -@pytest.mark.skip -def test_gui_footer_log_clear(): - pass - -@pytest.mark.skip -def test_gui_footer_log_set(): - pass - -@pytest.mark.skip -def test_gui_footer_log_get(): - pass - -@pytest.mark.skip -def test_gui_footer_input_clear(): - pass - -@pytest.mark.skip -def test_gui_footer_input_set(): - pass - -@pytest.mark.skip -def test_gui_footer_input_get(): - pass - -@pytest.mark.skip -def test_gui_footer_focus_input(): - pass - -@pytest.mark.skip -def test_gui_body_clear(): - pass - -@pytest.mark.skip -def test_gui_body_set(): - pass - -@pytest.mark.skip -def test_gui_body_get(): - pass - -@pytest.mark.skip -def test_gui_body_focus(): - pass - -@pytest.mark.skip -def test_log_timeout(): - pass - -@pytest.mark.skip -def test_log(): - pass - -@pytest.mark.skip -def test_gui_update_view(): - pass - -@pytest.mark.skip -def test_gui_update_status_bar(): - pass - -@pytest.mark.skip -def test_gui_switch_frame_body(): - pass - -@pytest.mark.skip -def test_delete_note_callback(): - pass - -@pytest.mark.skip -def test_gui_yes_no_input(): - pass - -@pytest.mark.skip -def test_gui_search_input(): - pass - -@pytest.mark.skip -def test_gui_category_input(): - pass - -@pytest.mark.skip -def test_gui_pipe_input(): - pass - -@pytest.mark.skip -def test_gui_frame_keypress(): - pass - -@pytest.mark.skip -def test_gui_init_view(): - pass - -@pytest.mark.skip -def test_gui_clear(): - pass - -@pytest.mark.skip -def test_gui_reset(): - pass - -@pytest.mark.skip -def test_gui_stop(): - pass - -@pytest.mark.skip -def test_gui(): - pass +def test_gui(mocker, mock_nncli): + """test starting the gui""" + nn_obj = nncli.nncli.Nncli(False) + nn_obj.gui(0) + assert nn_obj.config.state.do_gui == True + 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(): @@ -225,19 +111,3 @@ def test_cli_note_category_rm(): @pytest.mark.skip def test_SIGINT_handler(): pass - -@pytest.mark.skip -def test_usage(): - pass - -@pytest.mark.skip -def test_version(): - pass - -@pytest.mark.skip -def test_main(): - pass - -@pytest.mark.skip -def test_nncli_start(): - pass