Beispiel #1
0
def test_set_pattern_long(hist, message_mock, caplog, pattern):
    hist.insert({'url': 'example.com/foo', 'title': 'title1', 'last_atime': 1})
    cat = histcategory.HistoryCategory()
    with caplog.at_level(logging.ERROR):
        cat.set_pattern(pattern)
    msg = message_mock.getmsg(usertypes.MessageLevel.error)
    assert msg.text.startswith("Error with SQL query:")
Beispiel #2
0
def test_set_pattern_repeated(model_validator, hist):
    """Validate multiple subsequent calls to set_pattern."""
    hist.insert({'url': 'example.com/foo', 'title': 'title1', 'last_atime': 1})
    hist.insert({'url': 'example.com/bar', 'title': 'title2', 'last_atime': 1})
    hist.insert({'url': 'example.com/baz', 'title': 'title3', 'last_atime': 1})
    cat = histcategory.HistoryCategory()
    model_validator.set_model(cat)

    cat.set_pattern('b')
    model_validator.validate([
        ('example.com/bar', 'title2'),
        ('example.com/baz', 'title3'),
    ])

    cat.set_pattern('ba')
    model_validator.validate([
        ('example.com/bar', 'title2'),
        ('example.com/baz', 'title3'),
    ])

    cat.set_pattern('ba ')
    model_validator.validate([
        ('example.com/bar', 'title2'),
        ('example.com/baz', 'title3'),
    ])

    cat.set_pattern('ba z')
    model_validator.validate([
        ('example.com/baz', 'title3'),
    ])
Beispiel #3
0
def test_skip_duplicate_set(message_mock, caplog, hist):
    cat = histcategory.HistoryCategory()
    cat.set_pattern('foo')
    cat.set_pattern('foobarbaz')
    msg = caplog.messages[-1]
    assert msg.startswith(
        "Skipping query on foobarbaz due to prefix foo returning nothing.")
def url(*, info):
    """A model which combines bookmarks, quickmarks and web history URLs.

    Used for the `open` command.
    """
    model = completionmodel.CompletionModel(column_widths=(40, 50, 10))

    quickmarks = ((url, name)
                  for (name,
                       url) in objreg.get('quickmark-manager').marks.items())
    bookmarks = objreg.get('bookmark-manager').marks.items()

    model.add_category(
        listcategory.ListCategory('Quickmarks',
                                  quickmarks,
                                  delete_func=_delete_quickmark))
    model.add_category(
        listcategory.ListCategory('Bookmarks',
                                  bookmarks,
                                  delete_func=_delete_bookmark))

    if info.config.get('completion.web_history_max_items') != 0:
        hist_cat = histcategory.HistoryCategory(delete_func=_delete_history)
        model.add_category(hist_cat)
    return model
Beispiel #5
0
def test_set_pattern(pattern, before, after, model_validator, hist):
    """Validate the filtering and sorting results of set_pattern."""
    for row in before:
        hist.insert({'url': row[0], 'title': row[1], 'last_atime': 1})
    cat = histcategory.HistoryCategory()
    model_validator.set_model(cat)
    cat.set_pattern(pattern)
    model_validator.validate(after)
Beispiel #6
0
def test_remove_rows(hist, model_validator):
    hist.insert({'url': 'foo', 'title': 'Foo', 'last_atime': 0})
    hist.insert({'url': 'bar', 'title': 'Bar', 'last_atime': 0})
    cat = histcategory.HistoryCategory()
    model_validator.set_model(cat)
    cat.set_pattern('')
    hist.delete('url', 'foo')
    cat.removeRows(0, 1)
    model_validator.validate([('bar', 'Bar')])
Beispiel #7
0
def test_timestamp_fmt(fmt, expected, model_validator, config_stub, init_sql):
    """Validate the filtering and sorting results of set_pattern."""
    config_stub.val.completion.timestamp_format = fmt
    hist = sql.SqlTable('CompletionHistory', ['url', 'title', 'last_atime'])
    atime = datetime.datetime(2018, 2, 27, 8, 30)
    hist.insert({'url': 'foo', 'title': '', 'last_atime': atime.timestamp()})
    cat = histcategory.HistoryCategory()
    model_validator.set_model(cat)
    cat.set_pattern('')
    model_validator.validate([('foo', '', expected)])
Beispiel #8
0
def test_sorting(max_items, before, after, model_validator, hist, config_stub):
    """Validate the filtering and sorting results of set_pattern."""
    config_stub.val.completion.web_history.max_items = max_items
    for url, title, atime in before:
        timestamp = datetime.datetime.strptime(atime, '%Y-%m-%d').timestamp()
        hist.insert({'url': url, 'title': title, 'last_atime': timestamp})
    cat = histcategory.HistoryCategory()
    model_validator.set_model(cat)
    cat.set_pattern('')
    model_validator.validate(after)
Beispiel #9
0
def url(*, info):
    """A model which combines various URLs.

    This combines:
    - bookmarks
    - quickmarks
    - search engines
    - web history URLs

    Used for the `open` command.
    """
    model = completionmodel.CompletionModel(column_widths=(40, 50, 10))

    quickmarks = [(url, name)
                  for (name,
                       url) in objreg.get('quickmark-manager').marks.items()]
    bookmarks = objreg.get('bookmark-manager').marks.items()
    searchengines = [(k, v)
                     for k, v in sorted(config.val.url.searchengines.items())
                     if k != 'DEFAULT']
    categories = config.val.completion.open_categories
    models: Dict[str, QAbstractItemModel] = {}

    if searchengines and 'searchengines' in categories:
        models['searchengines'] = listcategory.ListCategory('Search engines',
                                                            searchengines,
                                                            sort=False)

    if quickmarks and 'quickmarks' in categories:
        models['quickmarks'] = listcategory.ListCategory(
            'Quickmarks',
            quickmarks,
            delete_func=_delete_quickmark,
            sort=False)
    if bookmarks and 'bookmarks' in categories:
        models['bookmarks'] = listcategory.ListCategory(
            'Bookmarks', bookmarks, delete_func=_delete_bookmark, sort=False)

    history_disabled = info.config.get('completion.web_history.max_items') == 0
    if not history_disabled and 'history' in categories:
        hist_cat = histcategory.HistoryCategory(
            database=history.web_history.database, delete_func=_delete_history)
        models['history'] = hist_cat

    if 'filesystem' in categories:
        models['filesystem'] = filepathcategory.FilePathCategory(
            name='Filesystem')

    for category in categories:
        if category in models:
            model.add_category(models[category])

    return model
Beispiel #10
0
def test_remove_rows_fetch(hist):
    """removeRows should fetch enough data to make the current index valid."""
    # we cannot use model_validator as it will fetch everything up front
    hist.insert_batch({'url': [str(i) for i in range(300)]})
    cat = histcategory.HistoryCategory()
    cat.set_pattern('')

    # sanity check that we didn't fetch everything up front
    assert cat.rowCount() < 300
    cat.fetchMore()
    assert cat.rowCount() == 300

    hist.delete('url', '298')
    cat.removeRows(297, 1)
    assert cat.rowCount() == 299
Beispiel #11
0
def url(*, info):
    """A model which combines bookmarks, quickmarks, search engines and web history URLs.

    Used for the `open` command.
    """
    model = completionmodel.CompletionModel(column_widths=(40, 50, 10))

    quickmarks = [(url, name)
                  for (name,
                       url) in objreg.get('quickmark-manager').marks.items()]
    bookmarks = objreg.get('bookmark-manager').marks.items()
    # pylint: disable=bad-config-option
    searchengines = {
        k: v
        for k, v in config.val.url.searchengines.items() if k not in "DEFAULT"
    }.items()
    # pylint: enable=bad-config-option
    categories = config.val.completion.open_categories
    models = {}

    if searchengines and "searchengines" in categories:
        models["searchengines"] = listcategory.ListCategory('Search engines',
                                                            searchengines,
                                                            sort=False)

    if quickmarks and "quickmarks" in categories:
        models["quickmarks"] = listcategory.ListCategory(
            'Quickmarks',
            quickmarks,
            delete_func=_delete_quickmark,
            sort=False)
    if bookmarks and "bookmarks" in categories:
        models["bookmarks"] = listcategory.ListCategory(
            'Bookmarks', bookmarks, delete_func=_delete_bookmark, sort=False)

    if info.config.get('completion.web_history_max_items'
                       ) != 0 and "history" in categories:
        hist_cat = histcategory.HistoryCategory(delete_func=_delete_history)
        models["history"] = hist_cat

    for category in categories:
        if category in models:
            model.add_category(models[category])

    return model
Beispiel #12
0
def test_set_pattern_hypothesis(hist, pat, caplog):
    hist.insert({'url': 'example.com/foo', 'title': 'title1', 'last_atime': 1})
    cat = histcategory.HistoryCategory()
    with caplog.at_level(logging.ERROR):
        cat.set_pattern(pat)
Beispiel #13
0
def url(*, info):
    """A model which combines various URLs.

    This combines:
    - bookmarks
    - quickmarks
    - search engines
    - open tabs
    - web history URLs

    Used for the `open` command.
    """
    model = completionmodel.CompletionModel(column_widths=(40, 50, 10))

    # pylint: disable=bad-config-option
    quickmarks = [(url, name)
                  for (name,
                       url) in objreg.get('quickmark-manager').marks.items()]
    bookmarks = objreg.get('bookmark-manager').marks.items()
    searchengines = [(k, v)
                     for k, v in sorted(config.val.url.searchengines.items())
                     if k != 'DEFAULT']
    # pylint: enable=bad-config-option
    categories = config.val.completion.open_categories
    models = {}

    if searchengines and 'searchengines' in categories:
        models['searchengines'] = listcategory.ListCategory('Search engines',
                                                            searchengines,
                                                            sort=False)

    if quickmarks and 'quickmarks' in categories:
        models['quickmarks'] = listcategory.ListCategory(
            'Quickmarks',
            quickmarks,
            delete_func=_delete_quickmark,
            sort=False)
    if bookmarks and 'bookmarks' in categories:
        models['bookmarks'] = listcategory.ListCategory(
            'Bookmarks', bookmarks, delete_func=_delete_bookmark, sort=False)

    if config.val.tabs.switch_to_open_url and 'tabs' in categories:
        all_tabs = []
        for _, tabs in tabutils.all_tabs_by_window().items():
            for i, t in enumerate(tabs):
                all_tabs.append((t.url().toDisplayString(), t.title(),
                                 "{}/{}".format(t.win_id, i + 1)))

        models['tabs'] = listcategory.ListCategory(
            'Tabs', all_tabs, delete_func=tabutils.delete_tab(2), sort=False)

    history_disabled = info.config.get('completion.web_history.max_items') == 0
    if not history_disabled and 'history' in categories:
        hist_cat = histcategory.HistoryCategory(delete_func=_delete_history)
        models['history'] = hist_cat

    for category in categories:
        if category in models:
            model.add_category(models[category])

    return model