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
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)
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')
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)
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)
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)
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'])
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'] }
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
def test_servicerule_most_viewed(note_model, notes, expected): service = ServiceRules(note_model) result = service.by_views(notes) assert result == expected
def test_servicerule_alphabetise(note_model, notes, expected): service = ServiceRules(note_model) result = service.alphabetise(notes) assert result == expected
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)
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
def test_servicerules_order_notes(note_model, notes, expected): service = ServiceRules(note_model) result = service.order_notes(notes) assert result == expected
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')