From b6652ad6bc13e30a130dd34191ad336c67cf1157 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Tue, 21 Jun 2016 23:04:03 -0400 Subject: [PATCH] Test completion quickmark/bookmark deletion. Validate that quickmarks and bookmarks can be deleted from the url completion menu. --- tests/helpers/fixtures.py | 4 +-- tests/helpers/stubs.py | 13 ++++++++ tests/unit/completion/test_models.py | 45 ++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/tests/helpers/fixtures.py b/tests/helpers/fixtures.py index 819dda15d..5482d6e66 100644 --- a/tests/helpers/fixtures.py +++ b/tests/helpers/fixtures.py @@ -201,7 +201,7 @@ def host_blocker_stub(stubs): @pytest.yield_fixture def quickmark_manager_stub(stubs): """Fixture which provides a fake quickmark manager object.""" - stub = stubs.UrlMarkManagerStub() + stub = stubs.QuickmarkManagerStub() objreg.register('quickmark-manager', stub) yield stub objreg.delete('quickmark-manager') @@ -210,7 +210,7 @@ def quickmark_manager_stub(stubs): @pytest.yield_fixture def bookmark_manager_stub(stubs): """Fixture which provides a fake bookmark manager object.""" - stub = stubs.UrlMarkManagerStub() + stub = stubs.BookmarkManagerStub() objreg.register('bookmark-manager', stub) yield stub objreg.delete('bookmark-manager') diff --git a/tests/helpers/stubs.py b/tests/helpers/stubs.py index c0b9c4cf3..75ad69fbe 100644 --- a/tests/helpers/stubs.py +++ b/tests/helpers/stubs.py @@ -474,6 +474,19 @@ class UrlMarkManagerStub(QObject): super().__init__(parent) self.marks = {} + def delete(self, key): + del self.marks[key] + self.removed.emit(key) + + +class BookmarkManagerStub(UrlMarkManagerStub): + pass + + +class QuickmarkManagerStub(UrlMarkManagerStub): + def quickmark_del(self, key): + self.delete(key) + class WebHistoryStub(QObject): diff --git a/tests/unit/completion/test_models.py b/tests/unit/completion/test_models.py index 19bd3c2de..eaab94d01 100644 --- a/tests/unit/completion/test_models.py +++ b/tests/unit/completion/test_models.py @@ -177,6 +177,51 @@ def test_url_completion(config_stub, web_history, quickmarks, bookmarks): ] +def test_url_completion_delete_bookmark(config_stub, web_history, quickmarks, + bookmarks): + """Test deleting a bookmark from the url completion model.""" + config_stub.data['completion'] = {'timestamp-format': '%Y-%m-%d', + 'web-history-max-items': 2} + model = urlmodel.UrlCompletionModel() + index = Mock() + cat = Mock() + completion_widget = Mock() + index.isValid = Mock(return_value=True) + index.parent = Mock(return_value=cat) + index.data = Mock(return_value='https://github.com') + cat.child = Mock(return_value=index) + cat.data = Mock(return_value='Bookmarks') + completion_widget.currentIndex = Mock(return_value=index) + model.delete_cur_item(completion_widget) + assert 'https://github.com' not in bookmarks.marks + assert 'https://python.org' in bookmarks.marks + assert 'http://qutebrowser.org' in bookmarks.marks + + +def test_url_completion_delete_quickmark(config_stub, web_history, quickmarks, + bookmarks): + """Test deleting a bookmark from the url completion model.""" + config_stub.data['completion'] = {'timestamp-format': '%Y-%m-%d', + 'web-history-max-items': 2} + model = urlmodel.UrlCompletionModel() + index = Mock() + sibling = Mock() + cat = Mock() + completion_widget = Mock() + index.isValid = Mock(return_value=True) + index.parent = Mock(return_value=cat) + index.sibling = Mock(return_value=sibling) + sibling.isValid = Mock(return_value=True) + sibling.data = Mock(return_value='ddg') + cat.child = Mock(return_value=index) + cat.data = Mock(return_value='Quickmarks') + completion_widget.currentIndex = Mock(return_value=index) + model.delete_cur_item(completion_widget) + assert 'aw' in quickmarks.marks + assert 'ddg' not in quickmarks.marks + assert 'wiki' in quickmarks.marks + + def test_session_completion(session_manager_stub): session_manager_stub.sessions = ['default', '1', '2'] actual = _get_completions(miscmodels.SessionCompletionModel())