2017-02-08 09:28:04 +01:00
|
|
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
|
|
|
|
|
|
|
# Copyright 2017 Imran Sobir
|
|
|
|
#
|
|
|
|
# This file is part of qutebrowser.
|
|
|
|
#
|
|
|
|
# qutebrowser is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# qutebrowser is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-02-09 11:44:51 +01:00
|
|
|
import datetime
|
|
|
|
|
2017-02-08 09:28:04 +01:00
|
|
|
from PyQt5.QtCore import QUrl
|
2017-02-09 11:44:51 +01:00
|
|
|
import pytest
|
|
|
|
|
2017-02-08 09:28:04 +01:00
|
|
|
from qutebrowser.browser import history, qutescheme
|
|
|
|
from qutebrowser.utils import objreg
|
|
|
|
|
|
|
|
|
|
|
|
class TestHistoryHandler:
|
2017-02-09 11:44:51 +01:00
|
|
|
|
2017-02-08 09:28:04 +01:00
|
|
|
"""Test the qute://history endpoint."""
|
|
|
|
|
2017-02-09 12:32:59 +01:00
|
|
|
@pytest.fixture
|
2017-02-09 12:39:21 +01:00
|
|
|
def fake_web_history(self, fake_save_manager, tmpdir):
|
2017-02-09 12:32:59 +01:00
|
|
|
"""Create a fake web-history and register it into objreg."""
|
2017-02-09 12:39:21 +01:00
|
|
|
fake_web_history = history.WebHistory(tmpdir.dirname, 'fake-history')
|
2017-02-09 12:32:59 +01:00
|
|
|
objreg.register('web-history', fake_web_history)
|
|
|
|
|
|
|
|
yield fake_web_history
|
|
|
|
|
|
|
|
objreg.delete('web-history')
|
2017-02-08 09:28:04 +01:00
|
|
|
|
2017-02-09 12:32:59 +01:00
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def generate_fake_history(self, fake_web_history):
|
|
|
|
"""Create fake history for three different days."""
|
2017-02-08 09:28:04 +01:00
|
|
|
one_day = datetime.timedelta(days=1)
|
|
|
|
self.curr_date = datetime.datetime.today()
|
|
|
|
self.next_date = self.curr_date + one_day
|
|
|
|
self.prev_date = self.curr_date - one_day
|
|
|
|
|
|
|
|
today = history.Entry(atime=str(self.curr_date.timestamp()),
|
|
|
|
url=QUrl('www.today.com'), title='today')
|
|
|
|
tomorrow = history.Entry(atime=str(self.next_date.timestamp()),
|
|
|
|
url=QUrl('www.tomorrow.com'), title='tomorrow')
|
|
|
|
yesterday = history.Entry(atime=str(self.prev_date.timestamp()),
|
|
|
|
url=QUrl('www.yesterday.com'), title='yesterday')
|
|
|
|
|
2017-02-09 12:32:59 +01:00
|
|
|
fake_web_history = objreg.get('web-history')
|
|
|
|
fake_web_history._add_entry(today)
|
|
|
|
fake_web_history._add_entry(tomorrow)
|
|
|
|
fake_web_history._add_entry(yesterday)
|
|
|
|
fake_web_history.save()
|
2017-02-08 12:18:33 +01:00
|
|
|
|
2017-02-08 09:28:04 +01:00
|
|
|
def test_history_without_query(self):
|
2017-02-09 11:44:51 +01:00
|
|
|
"""Ensure qute://history shows today's history when it has no query."""
|
2017-02-08 09:28:04 +01:00
|
|
|
_mimetype, data = qutescheme.qute_history(QUrl("qute://history"))
|
|
|
|
key = "<span class=\"date\">{}</span>".format(
|
|
|
|
datetime.date.today().strftime("%a, %d %B %Y"))
|
|
|
|
assert key in data
|
|
|
|
|
|
|
|
def test_history_with_bad_query(self):
|
2017-02-09 11:44:51 +01:00
|
|
|
"""Ensure qute://history shows today's history when given bad query."""
|
2017-02-08 09:28:04 +01:00
|
|
|
url = QUrl("qute://history?date=204-blaah")
|
|
|
|
_mimetype, data = qutescheme.qute_history(url)
|
|
|
|
key = "<span class=\"date\">{}</span>".format(
|
|
|
|
datetime.date.today().strftime("%a, %d %B %Y"))
|
|
|
|
assert key in data
|
|
|
|
|
|
|
|
def test_history_today(self):
|
2017-02-09 11:44:51 +01:00
|
|
|
"""Ensure qute://history shows history for today."""
|
2017-02-08 09:28:04 +01:00
|
|
|
url = QUrl("qute://history")
|
|
|
|
_mimetype, data = qutescheme.qute_history(url)
|
|
|
|
assert "today" in data
|
|
|
|
assert "tomorrow" not in data
|
|
|
|
assert "yesterday" not in data
|
|
|
|
|
|
|
|
def test_history_yesterday(self):
|
2017-02-09 11:44:51 +01:00
|
|
|
"""Ensure qute://history shows history for yesterday."""
|
2017-02-08 09:28:04 +01:00
|
|
|
url = QUrl("qute://history?date=" + self.prev_date.strftime("%Y-%m-%d"))
|
|
|
|
_mimetype, data = qutescheme.qute_history(url)
|
|
|
|
assert "today" not in data
|
|
|
|
assert "tomorrow" not in data
|
|
|
|
assert "yesterday" in data
|
|
|
|
|
|
|
|
def test_history_tomorrow(self):
|
2017-02-09 11:44:51 +01:00
|
|
|
"""Ensure qute://history shows history for tomorrow."""
|
2017-02-08 09:28:04 +01:00
|
|
|
url = QUrl("qute://history?date=" + self.next_date.strftime("%Y-%m-%d"))
|
|
|
|
_mimetype, data = qutescheme.qute_history(url)
|
|
|
|
assert "today" not in data
|
|
|
|
assert "tomorrow" in data
|
|
|
|
assert "yesterday" not in data
|