summaryrefslogtreecommitdiff
path: root/tests/end2end/features/test_history_bdd.py
diff options
context:
space:
mode:
authorRyan Roden-Corrent <ryan@rcorre.net>2017-04-04 08:27:42 -0400
committerRyan Roden-Corrent <ryan@rcorre.net>2017-06-19 07:44:11 -0400
commit8ff45331df32e35c214662056f8b5d72e789b8eb (patch)
treeb618824f9ddde0199f736c6cf61b6d2548f2449a /tests/end2end/features/test_history_bdd.py
parent80647b062a6f28002dd283c8460a4ca7baed92fd (diff)
downloadqutebrowser-8ff45331df32e35c214662056f8b5d72e789b8eb.tar.gz
qutebrowser-8ff45331df32e35c214662056f8b5d72e789b8eb.zip
Clean up sql implementation.
Now that sql is only used for history (not quickmarks/bookmarks) a number of functions are no longer needed. In addition, primary key support was removed as we actually need to support multiple entries for the same url with different access times. The completion model will have to handle this by selecting something like (url, title, max(atime)). This also fixes up a number of tests that were broken with the last few sql-related commits.
Diffstat (limited to 'tests/end2end/features/test_history_bdd.py')
-rw-r--r--tests/end2end/features/test_history_bdd.py38
1 files changed, 18 insertions, 20 deletions
diff --git a/tests/end2end/features/test_history_bdd.py b/tests/end2end/features/test_history_bdd.py
index 1fee533eb..25995e9d0 100644
--- a/tests/end2end/features/test_history_bdd.py
+++ b/tests/end2end/features/test_history_bdd.py
@@ -20,31 +20,29 @@
import os.path
import pytest_bdd as bdd
+
+from PyQt5.QtSql import QSqlDatabase, QSqlQuery
+
bdd.scenarios('history.feature')
@bdd.then(bdd.parsers.parse("the history file should contain:\n{expected}"))
def check_history(quteproc, httpbin, expected):
- history_file = os.path.join(quteproc.basedir, 'data', 'history')
- quteproc.send_cmd(':save history')
- quteproc.wait_for(message=':save saved history')
-
- expected = expected.replace('(port)', str(httpbin.port)).splitlines()
-
- with open(history_file, 'r', encoding='utf-8') as f:
- lines = []
- for line in f:
- if not line.strip():
- continue
- print('history line: ' + line)
- atime, line = line.split(' ', maxsplit=1)
- line = line.rstrip()
- if '-' in atime:
- flags = atime.split('-')[1]
- line = '{} {}'.format(flags, line)
- lines.append(line)
-
- assert lines == expected
+ path = os.path.join(quteproc.basedir, 'data', 'history.sqlite')
+ db = QSqlDatabase.addDatabase('QSQLITE')
+ db.setDatabaseName(path)
+ assert db.open(), 'Failed to open history database'
+ query = db.exec_('select * from History')
+ actual = []
+ while query.next():
+ rec = query.record()
+ url = rec.value(0)
+ title = rec.value(1)
+ redirect = rec.value(3)
+ actual.append('{} {} {}'.format('r' * redirect, url, title).strip())
+ db = None
+ QSqlDatabase.removeDatabase(QSqlDatabase.database().connectionName())
+ assert actual == expected.replace('(port)', str(httpbin.port)).splitlines()
@bdd.then("the history file should be empty")