Пример #1
0
def test_change_book():
    """Test that book can change."""
    mock_view = MagicMock()
    mock_ctrl = MagicMock()
    # Have to return view so that we can exit
    mock_ctrl.return_value.basic_output.side_effect = [
        {
            'action': 'list',
            'item': 'note',
            'book': 'mock_book',
        },
        {
            'action': 'view',
            'item': 'note',
        }
    ]

    mock_functions = {
        'view': mock_view,
        'list': None,
    }
    with patch.dict('foolscap.actor.FUNCTION_MAP', mock_functions),\
            patch('foolscap.actor.Controller', mock_ctrl):

        actor.action('list', None)
        mock_ctrl.has_calls(calls=[call('general'), call('mock_book')])
        mock_ctrl.return_value.basic_output.assert_called()
Пример #2
0
def main():
    args = parser.parse_args()
    command = args.command
    note_args = args.positional
    list_type = args.list_type
    book = args.book

    action(command, note_args, list_type, book)
Пример #3
0
def test_migrate_command():
    TESTED_ACTIONS.append('migrate')
    mock_action = MagicMock()
    with patch.dict('foolscap.actor.FUNCTION_MAP', {'migrate': mock_action}):
        expected = call()
        actor.action('migrate', None)
        mock_action.assert_called_once()
        assert mock_action.call_args == expected
Пример #4
0
def test_move_lines_command():
    TESTED_ACTIONS.append('move_lines')
    mock_action = MagicMock()
    with patch.dict('foolscap.actor.FUNCTION_MAP', {'move_lines': mock_action}):
        # Move Lines expects:
        expected = call('mock_note')

        actor.action('move_lines', 'mock_note')
        mock_action.assert_called_once()
        assert mock_action.call_args == expected
Пример #5
0
def test_delete_note_command():
    TESTED_ACTIONS.append('delete')
    mock_action = MagicMock()
    with patch.dict('foolscap.actor.FUNCTION_MAP', {'delete': mock_action}):
        # Delete expects:
        expected = call('mock_note')

        actor.action('delete', 'mock_note')
        mock_action.assert_called_once()
        assert mock_action.call_args == expected
Пример #6
0
def test_export_note_command():
    TESTED_ACTIONS.append('export')
    mock_action = MagicMock()
    with patch.dict('foolscap.actor.FUNCTION_MAP', {'export': mock_action}):
        # export expects the following:
        expected = call('mock_note')

        # Pass to actor:
        actor.action('export', 'mock_note')
        mock_action.assert_called_once()
        assert mock_action.call_args == expected
Пример #7
0
def test_change_list_type():
    mock_view = MagicMock()
    mock_ctrl = MagicMock()
    # Have to return view so that we can exit
    mock_ctrl.return_value.basic_output.return_value = {
        'action': 'view',
        'item': 'note',
    }
    with patch.dict('foolscap.actor.FUNCTION_MAP', {'view': mock_view}),\
            patch('foolscap.actor.Controller', mock_ctrl):

        actor.action('list', None, 'tags')
        mock_ctrl.assert_called_with('tags')
        mock_ctrl.return_value.basic_output.assert_called()
Пример #8
0
def test_list_note_command_no_tags():
    TESTED_ACTIONS.append('list')
    mock_view = MagicMock()
    mock_ctrl = MagicMock()
    # Have to return view so that we can exit
    mock_ctrl.return_value.basic_output.return_value = {
        'action': 'view',
        'item': 'mock_note',
    }
    with patch.dict('foolscap.actor.FUNCTION_MAP', {'view': mock_view}),\
            patch('foolscap.actor.Controller', mock_ctrl):

        # Pass to actor:
        actor.action('list', None)
        mock_ctrl.return_value.basic_output.assert_called()
Пример #9
0
def test_search_note(query, expected):
    TESTED_ACTIONS.append('search')
    mock_view = MagicMock()
    mock_ctrl = MagicMock()
    # Have to return view so that we can exit
    mock_ctrl.return_value.search_output.return_value = {
        'action': 'view',
        'item': 'mock_note',
    }
    with patch.dict('foolscap.actor.FUNCTION_MAP', {'view': mock_view}),\
            patch('foolscap.actor.Controller', mock_ctrl):

        # Pass to actor:
        actor.action('search', query)
        assert mock_ctrl.call_args_list == [call('notes')]
        assert mock_ctrl.return_value.search_output.call_args_list == expected
Пример #10
0
def test_list_note_command_returning_func():
    mock_view = MagicMock()
    mock_ctrl = MagicMock()
    # Have to return view so that we can exit
    mock_ctrl.return_value.query_output.return_value = {
        'action': 'view',
        'item': 'mock_note',
    }
    with patch.dict('foolscap.actor.FUNCTION_MAP', {'view': mock_view}),\
            patch('foolscap.actor.Controller', mock_ctrl):

        expected_view = call('mock_note')

        actor.action('list', 'tag')
        # If list function returns a new-action:
        # this case view
        assert mock_view.call_args == expected_view
        mock_view.assert_called_once()