def test_iter(hist): list(hist.async_read()) url = QUrl('http://www.example.com/') hist.add_url(url, atime=12345) entry = history.Entry(url=url, atime=12345, redirect=False, title="") assert list(hist) == [entry]
def web_history(stubs, web_history_stub): """Pre-populate the web-history stub with some history entries.""" web_history_stub.history_dict = collections.OrderedDict([ ('http://qutebrowser.org', history.Entry( datetime(2015, 9, 5).timestamp(), QUrl('http://qutebrowser.org'), 'qutebrowser | qutebrowser')), ('https://python.org', history.Entry( datetime(2016, 3, 8).timestamp(), QUrl('https://python.org'), 'Welcome to Python.org')), ('https://github.com', history.Entry( datetime(2016, 5, 1).timestamp(), QUrl('https://github.com'), 'GitHub')), ]) return web_history_stub
def hist_interface(): entry = history.Entry(atime=0, url=QUrl('http://www.example.com/'), title='example') history_dict = {'http://www.example.com/': entry} fake_hist = FakeWebHistory(history_dict) interface = history.WebHistoryInterface(fake_hist) QWebHistoryInterface.setDefaultInterface(interface) yield QWebHistoryInterface.setDefaultInterface(None)
def test_add_item_redirect(qtbot, hist): list(hist.async_read()) url = 'http://www.example.com/' with qtbot.assertNotEmitted(hist.add_completion_item): with qtbot.waitSignal(hist.item_added): hist.add_url(QUrl(url), redirect=True, atime=12345) entry = history.Entry(url=QUrl(url), redirect=True, atime=12345, title="") assert hist.history_dict[url] == entry
def test_add_item(qtbot, hist): list(hist.async_read()) url = 'http://www.example.com/' with qtbot.waitSignals([hist.add_completion_item, hist.item_added]): hist.add_url(QUrl(url), atime=12345, title="the title") entry = history.Entry(url=QUrl(url), redirect=False, atime=12345, title="the title") assert hist.history_dict[url] == entry
def test_add_item_redirect_update(qtbot, tmpdir): """A redirect update added should override a non-redirect one.""" url = 'http://www.example.com/' hist_file = tmpdir / 'filled-history' hist_file.write('12345 {}\n'.format(url)) hist = history.WebHistory(hist_dir=str(tmpdir), hist_name='filled-history') list(hist.async_read()) with qtbot.assertNotEmitted(hist.add_completion_item): with qtbot.waitSignal(hist.item_added): hist.add_url(QUrl(url), redirect=True, atime=67890) entry = history.Entry(url=QUrl(url), redirect=True, atime=67890, title="") assert hist.history_dict[url] == entry
def test_adding_item_during_async_read(qtbot, hist, redirect): """Check what happens when adding URL while reading the history.""" url = QUrl('http://www.example.com/') with qtbot.assertNotEmitted(hist.add_completion_item), \ qtbot.assertNotEmitted(hist.item_added): hist.add_url(url, redirect=redirect, atime=12345) if redirect: with qtbot.assertNotEmitted(hist.add_completion_item): with qtbot.waitSignal(hist.async_read_done): list(hist.async_read()) else: with qtbot.waitSignals([hist.add_completion_item, hist.async_read_done]): list(hist.async_read()) assert not hist._temp_history expected = history.Entry(url=url, atime=12345, redirect=redirect, title="") assert list(hist.history_dict.values()) == [expected]
hist = history.WebHistory(hist_dir=str(tmpdir), hist_name='filled-history') list(hist.async_read()) with qtbot.assertNotEmitted(hist.add_completion_item): with qtbot.waitSignal(hist.item_added): hist.add_url(QUrl(url), redirect=True, atime=67890) entry = history.Entry(url=QUrl(url), redirect=True, atime=67890, title="") assert hist.history_dict[url] == entry @pytest.mark.parametrize('line, expected', [ ( # old format without title '12345 http://example.com/', history.Entry(atime=12345, url=QUrl('http://example.com/'), title='',) ), ( # trailing space without title '12345 http://example.com/ ', history.Entry(atime=12345, url=QUrl('http://example.com/'), title='',) ), ( # new format with title '12345 http://example.com/ this is a title', history.Entry(atime=12345, url=QUrl('http://example.com/'), title='this is a title') ), ( # weird NUL bytes '\x0012345 http://example.com/',