示例#1
0
def test_servicerule_by_count(note_model, tags, expected):
    from foolscap.meta_data import TagsModel
    tag_model = TagsModel(note_model)
    service = ServiceRules(tag_model)

    result = service.by_count(tags)
    assert result == expected
示例#2
0
def display_data():
    from foolscap.meta_data import NotesModel
    from foolscap.note_display import ServiceRules

    patch_load = 'foolscap.meta_data.models.load_meta'
    with patch(patch_load, return_value=FAKE_FOUR_NOTES_W_SUB):
        model = NotesModel()
        service_rules = ServiceRules(model)
        items = list(model)
        items = service_rules.order(items)
        items = service_rules.alphabetise(items)
        return service_rules.structure(items)
示例#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')
示例#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)
示例#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)
示例#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)
示例#7
0
def test_servicerules_order(note_model):
    service = ServiceRules(note_model)
    with patch.object(service, 'order_notes') as _call:
        service.order(['most_viewed'])
        _call.assert_called_once()
        _call.assert_called_with(['most_viewed'])

    # Setting this effects test_models.test_notemodel__init__
    # this might be a bug with pytest?
    #
    # assert _note_model.model_type == 'notes'
    # asserts false - 'tags' != 'notes'
    #
    # note_model.model_type = 'tags'

    with patch.object(note_model, 'model_type', 'tags'):
        service = ServiceRules(note_model)
        with patch.object(service, 'by_count') as _call:
            service.order(['most_viewed'])
            _call.assert_called_once()
            _call.assert_called_with(['most_viewed'])
示例#8
0
def test_servicerule_structure(note_model, notes, tags):
    service = ServiceRules(note_model)
    result = service.structure(notes)
    assert result == {
        'titles': ['most_viewed'],
        'model': note_model,
        'books': ['general'],
    }

    from foolscap.meta_data import TagsModel
    tag_model = TagsModel(note_model)
    service = ServiceRules(tag_model)
    result = service.structure(tags)
    assert result == {
        'titles': ['fake_tag'],
        'model': tag_model,
        'books': ['general']
    }
示例#9
0
def test_servicerule_last_viewed(note_model, notes, expected):
    service = ServiceRules(note_model)
    # I am only testing the last viewed appears 1st
    # can assume the same for the rest.
    result = service.last_viewed(notes)[0]
    assert result == expected
示例#10
0
def test_servicerule_most_viewed(note_model, notes, expected):
    service = ServiceRules(note_model)
    result = service.by_views(notes)
    assert result == expected
示例#11
0
def test_servicerule_alphabetise(note_model, notes, expected):
    service = ServiceRules(note_model)
    result = service.alphabetise(notes)
    assert result == expected
示例#12
0
def test_servicerules_filter_items_notfound(note_model, query):
    with patch('foolscap.meta_data.models.fuzzy_guess') as _fuzz,\
         pytest.raises(SystemExit):
        service = ServiceRules(note_model)
        result = service.filter_items(FAKE_DIFF_BOOKS.keys(), query)
示例#13
0
def test_servicerules_filter_items(note_model, query, expected):
    service = ServiceRules(note_model)
    result = service.filter_items(FAKE_DIFF_BOOKS.keys(), query)
    assert len(result) == expected
示例#14
0
def test_servicerules_order_notes(note_model, notes, expected):
    service = ServiceRules(note_model)
    result = service.order_notes(notes)
    assert result == expected
示例#15
0
def test_servicerules__init__(note_model):
    service = ServiceRules(note_model)
    assert hasattr(service, 'model')
    assert hasattr(service, 'ORDER_RULE')
    assert hasattr(service, 'TOP_N_VIEWED')