Esempio n. 1
0
class Controller:

    def __init__(self, model_type):
        self.model = NotesModel()
        if model_type == 'tags':
            self.model = TagsModel(self.model)
        self.service_rules = ServiceRules(self.model)

    def __service_rules(self, items, tab_title):
        items = self.service_rules.order(items)
        structure = self.service_rules.structure(items)
        structure['tab_title'] = tab_title
        return display_list(structure)

    def basic_output(self, book):
        items = list(self.model)
        self.items = self.service_rules.filter_items(items, book)
        return self.__service_rules(self.items, book)

    def query_output(self, query):
        items = self.model.query_tags(query)
        if not items:
            exit()
        return self.__service_rules(items, "tag: '{}'".format(query))

    def search_output(self, query):
        if not query:
            print("\n\tNo Query Error\n")
            exit()
        items = self.model.query_titles(query)
        if not items:
            exit()
        structure = self.service_rules.structure(items)
        structure['tab_title'] = 'search'
        return display_list(structure)
Esempio n. 2
0
def test_tagsmodel_get(note_model, query):
    tag_model = TagsModel(note_model)

    result = tag_model.get(query)
    assert result == {
        'sub_headings': [
            ('most_viewed', 'This is a fake note'),
        ],
        'title': 'fake_tag',
        'description': '1'
    }
Esempio n. 3
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
Esempio n. 4
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. 5
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. 6
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. 7
0
def tag_data():
    from foolscap.meta_data import NotesModel
    from foolscap.meta_data import TagsModel
    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()
        model = TagsModel(model)
        service_rules = ServiceRules(model)
        items = list(model)
        items = service_rules.order(items)
        items = service_rules.alphabetise(items)
        return service_rules.structure(items)
Esempio n. 8
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. 9
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']
    }
Esempio n. 10
0
def test_tagsmodel__init__(note_model):
    tag_model = TagsModel(note_model)

    assert hasattr(tag_model, 'tags')
    assert tag_model.tags == {
        'fake_tag': {
            'sub_headings': [
                ('most_viewed', 'This is a fake note'),
            ],
            'title': 'fake_tag',
            'description': '1'
        }
    }

    assert len(tag_model) == 1

    tags = [tag for tag in tag_model]
    assert tags == ['fake_tag']
Esempio n. 11
0
def test_tagmodel_query_title_with_no_results(note_model):
    tag_model = TagsModel(note_model)

    with patch.object(tag_model, 'get') as _get:
        tag_model.query_titles('none')
        _get.assert_called_with('none')
Esempio n. 12
0
def test_tagmodel_query_title_no_query(note_model, expected):
    tag_model = TagsModel(note_model)
    with pytest.raises(expected):
        tag_model.query_titles(None)
Esempio n. 13
0
def test_tagmodel_query_title(note_model, query, expected):
    tag_model = TagsModel(note_model)

    result = tag_model.query_titles(query)
    assert result == expected
Esempio n. 14
0
def test_tagsmodel_query_tags_no_result(note_model, query):
    tag_model = TagsModel(note_model)

    with patch.object(tag_model, 'get') as _get:
        tag_model.query_tags(query)
        _get.assert_called_with(query)
Esempio n. 15
0
def test_tagsmodel_value(note_model, query, value, expected):
    tag_model = TagsModel(note_model)

    result = tag_model.get_value(query, value)
    assert result == expected
Esempio n. 16
0
 def __init__(self, model_type):
     self.model = NotesModel()
     if model_type == 'tags':
         self.model = TagsModel(self.model)
     self.service_rules = ServiceRules(self.model)