def test_private_browsing(qtbot, tmpdir, fake_save_manager, config_stub): """Make sure no data is saved at all with private browsing.""" config_stub.data = {'general': {'private-browsing': True}} private_hist = history.WebHistory(hist_dir=str(tmpdir), hist_name='history') # Before initial read with qtbot.assertNotEmitted(private_hist.add_completion_item), \ qtbot.assertNotEmitted(private_hist.item_added): private_hist.add_url(QUrl('http://www.example.com/')) assert not private_hist._temp_history # read with qtbot.assertNotEmitted(private_hist.add_completion_item), \ qtbot.assertNotEmitted(private_hist.item_added): with qtbot.waitSignals([private_hist.async_read_done]): list(private_hist.async_read()) # after read with qtbot.assertNotEmitted(private_hist.add_completion_item), \ qtbot.assertNotEmitted(private_hist.item_added): private_hist.add_url(QUrl('http://www.example.com/')) assert not private_hist._temp_history assert not private_hist._new_history assert not private_hist.history_dict
def test_updated_entries(hist, tmpdir): (tmpdir / 'filled-history').write('12345 http://example.com/\n' '67890 http://example.com/\n') hist = history.WebHistory(hist_dir=str(tmpdir), hist_name='filled-history') list(hist.async_read()) assert hist.history_dict['http://example.com/'].atime == 67890 hist.add_url(QUrl('http://example.com/'), atime=99999) assert hist.history_dict['http://example.com/'].atime == 99999
def test_get_recent(hist, tmpdir): (tmpdir / 'filled-history').write('12345 http://example.com/') hist = history.WebHistory(hist_dir=str(tmpdir), hist_name='filled-history') list(hist.async_read()) hist.add_url(QUrl('http://www.qutebrowser.org/'), atime=67890) lines = hist.get_recent() expected = ['12345 http://example.com/', '67890 http://www.qutebrowser.org/'] assert lines == expected
def test_invalid_read(hist, tmpdir, caplog): (tmpdir / 'filled-history').write('foobar\n12345 http://example.com/') hist = history.WebHistory(hist_dir=str(tmpdir), hist_name='filled-history') with caplog.at_level(logging.WARNING): list(hist.async_read()) entries = list(hist.history_dict.values()) assert len(entries) == 1 assert len(caplog.records) == 1 msg = "Invalid history entry 'foobar': 2 or 3 fields expected!" assert caplog.records[0].msg == msg
def test_async_read_twice(monkeypatch, qtbot, tmpdir, caplog): (tmpdir / 'filled-history').write('\n'.join([ '12345 http://example.com/ title', '67890 http://example.com/', '12345 http://qutebrowser.org/ blah', ])) hist = history.WebHistory(hist_dir=str(tmpdir), hist_name='filled-history') next(hist.async_read()) with pytest.raises(StopIteration): next(hist.async_read()) expected = "Ignoring async_read() because reading is started." assert len(caplog.records) == 1 assert caplog.records[0].msg == expected
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_clear(qtbot, hist, tmpdir): hist_file = tmpdir / 'filled-history' hist_file.write('12345 http://example.com/\n') hist = history.WebHistory(hist_dir=str(tmpdir), hist_name='filled-history') list(hist.async_read()) hist.add_url(QUrl('http://www.qutebrowser.org/')) with qtbot.waitSignal(hist.cleared): hist.clear() assert not hist_file.read() assert not hist.history_dict assert not hist._new_history hist.add_url(QUrl('http://www.the-compiler.org/'), atime=67890) hist.save() lines = hist_file.read().splitlines() assert lines == ['67890 http://www.the-compiler.org/']
def test_save(hist, tmpdir): hist_file = tmpdir / 'filled-history' hist_file.write('12345 http://example.com/\n') hist = history.WebHistory(hist_dir=str(tmpdir), hist_name='filled-history') list(hist.async_read()) hist.add_url(QUrl('http://www.qutebrowser.org/'), atime=67890) hist.save() lines = hist_file.read().splitlines() expected = ['12345 http://example.com/', '67890 http://www.qutebrowser.org/'] assert lines == expected hist.add_url(QUrl('http://www.the-compiler.org/'), atime=99999) hist.save() expected.append('99999 http://www.the-compiler.org/') lines = hist_file.read().splitlines() assert lines == expected
def test_async_read_no_datadir(qtbot, config_stub, fake_save_manager): config_stub.data = {'general': {'private-browsing': False}} hist = history.WebHistory(hist_dir=None, hist_name='history') with qtbot.waitSignal(hist.async_read_done): list(hist.async_read())
def hist(tmpdir): return history.WebHistory(hist_dir=str(tmpdir), hist_name='history')
def test_read(hist, tmpdir, line): (tmpdir / 'filled-history').write(line + '\n') hist = history.WebHistory(hist_dir=str(tmpdir), hist_name='filled-history') list(hist.async_read())