Esempio n. 1
0
def test_controller__init__(note_model_init):
    with patch('foolscap.note_display.NotesModel', note_model_init):

        ctrl = Controller('notes')
        assert hasattr(ctrl, 'model')
        assert hasattr(ctrl, 'service_rules')
        assert ctrl.model.model_type == 'notes'

        ctrl = Controller('tags')
        assert hasattr(ctrl, 'model')
        assert hasattr(ctrl, 'service_rules')
        assert ctrl.model.model_type == 'tags'
Esempio n. 2
0
def action(do_action, arg, list_type='notes', book='general'):
    if sys.platform.startswith("linux"):
        # Linux specific abstract namespace domain socket
        grab_attention("foolscap_actor")

    func = FUNCTION_MAP[do_action]

    new_action = {}
    if do_action in DISPLAY_ACTIONS:
        display_ctrl = Controller(list_type)

        # Quitting from list calls exit() method.
        # arg is filter in this case
        if arg:
            if do_action == 'search':
                new_action = display_ctrl.search_output(arg)
            else:
                new_action = display_ctrl.query_output(arg)
        else:
            new_action = display_ctrl.basic_output(book)

    if new_action.get('action', False):
        new_func = new_action['action']
        note = new_action['item']
        if new_func == 'list':
            action(new_func, None, book=new_action['book'])
        else:
            action(new_func, note)
    # arg is note in this case
    elif arg:
        func(arg)
    else:
        func()
Esempio n. 3
0
def test_ctrl_with_no_tag_matches(note_model, model_type):
    with pytest.raises(SystemExit):
        ctrl = Controller(model_type)
        ctrl.model = note_model
        if model_type == 'tags':
            ctrl.model = TagsModel(note_model)
        ctrl.service_rules = ServiceRules(ctrl.model)

        ctrl.query_output('no_matching_tag')
Esempio n. 4
0
def test_ctrl_basic_out(note_model, model_type, expected):
    expected['tab_title'] = 'general'
    with patch('foolscap.note_display.display_list') as _mock:
        ctrl = Controller(model_type)
        ctrl.model = note_model
        expected['model'] = note_model
        if model_type == 'tags':
            ctrl.model = TagsModel(note_model)
            expected['model'] = ctrl.model

        ctrl.service_rules = ServiceRules(ctrl.model)
        ctrl.basic_output('general')
        _mock.assert_called_with(expected)
Esempio n. 5
0
def test_ctrl_query_out(note_model, model_type, query, expected):
    expected['tab_title'] = "tag: '{}'".format(query)
    with patch('foolscap.note_display.display_list') as _mock:
        ctrl = Controller(model_type)
        ctrl.model = note_model
        expected['model'] = note_model
        if model_type == 'tags':
            ctrl.model = TagsModel(note_model)
            expected['model'] = ctrl.model

        ctrl.service_rules = ServiceRules(ctrl.model)
        ctrl.query_output(query)
        _mock.assert_called_with(expected)
Esempio n. 6
0
def test_search_notes(note_model, model_type, query, expected):
    expected['books'] = ['general'] * 7
    expected['tab_title'] = 'search'
    with patch('foolscap.note_display.display_list') as _mock:
        ctrl = Controller(model_type)
        ctrl.model = note_model
        expected['model'] = note_model
        if model_type == 'tags':
            ctrl.model = TagsModel(note_model)
            expected['model'] = ctrl.model

        ctrl.service_rules = ServiceRules(ctrl.model)

        ctrl.search_output(query)
        _mock.assert_called_with(expected)
Esempio n. 7
0
def test_ctrl_search_no_query(note_model_init, model_type):
    with patch('foolscap.note_display.NotesModel', note_model_init):
        ctrl = Controller(model_type)
        with pytest.raises(SystemExit):
            ctrl.search_output(None)
Esempio n. 8
0
def test_ctrl_search_output_with_no_results(note_model_init, model_type):
    ctrl = Controller(model_type)
    with patch('foolscap.meta_data.models.fuzzy_guess') as _fuzz,\
            pytest.raises(SystemExit):
        ctrl.search_output('none')
        assert _fuzz.called_with('none', [])