From f06880c6e2ac8036c9e39180f669c71a64178f9b Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Tue, 27 Jun 2017 08:40:43 -0400 Subject: [PATCH] Fix history completion delete function. In order to update SqlQueryModel's rowCount after re-running the query, we must call setQuery again. --- qutebrowser/completion/models/sqlcategory.py | 3 ++- tests/helpers/stubs.py | 5 ++++- tests/unit/completion/test_models.py | 5 +++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/qutebrowser/completion/models/sqlcategory.py b/qutebrowser/completion/models/sqlcategory.py index 9edd5f96e..e20edad3c 100644 --- a/qutebrowser/completion/models/sqlcategory.py +++ b/qutebrowser/completion/models/sqlcategory.py @@ -99,5 +99,6 @@ class SqlCategory(QSqlQueryModel): for i in range(self.columnCount())] self.delete_func(data) # re-run query to reload updated table - with debug.log_time('sql', 'Running completion query'): + with debug.log_time('sql', 'Re-running completion query post-delete'): self._query.run() + self.setQuery(self._query) diff --git a/tests/helpers/stubs.py b/tests/helpers/stubs.py index a490ad5bb..6d0160f03 100644 --- a/tests/helpers/stubs.py +++ b/tests/helpers/stubs.py @@ -532,6 +532,10 @@ class WebHistoryStub(sql.SqlTable): self.completion = sql.SqlTable("CompletionHistory", ['url', 'title', 'last_atime']) + def __contains__(self, url): + q = self.contains_query('url') + return q.run(val=url).value() + def add_url(self, url, title="", *, redirect=False, atime=None): self.insert({'url': url, 'title': title, 'atime': atime, 'redirect': redirect}) @@ -540,7 +544,6 @@ class WebHistoryStub(sql.SqlTable): 'title': title, 'last_atime': atime}) - def delete_url(self, url): """Remove all history entries with the given url. diff --git a/tests/unit/completion/test_models.py b/tests/unit/completion/test_models.py index 77bb89ccf..1c1a4ce63 100644 --- a/tests/unit/completion/test_models.py +++ b/tests/unit/completion/test_models.py @@ -392,8 +392,9 @@ def test_url_completion_delete_history(qtmodeltester, config_stub, assert model.data(parent) == "History" assert model.data(idx) == 'https://python.org' + assert 'https://python.org' in web_history_stub model.delete_cur_item(idx) - assert not web_history_stub.contains('url', 'https://python.org') + assert 'https://python.org' not in web_history_stub def test_session_completion(qtmodeltester, session_manager_stub): @@ -594,7 +595,7 @@ def test_url_completion_benchmark(benchmark, config_stub, 'title': ['title{}'.format(i) for i in r] } - web_history_stub.completions.insert_batch(entries) + web_history_stub.completion.insert_batch(entries) quickmark_manager_stub.marks = collections.OrderedDict([ ('title{}'.format(i), 'example.com/{}'.format(i))