Make network inaccessible in test QWebPages.

Maybe fixes #553.
This commit is contained in:
Florian Bruhin 2015-03-16 08:32:17 +01:00
parent 57b7b43802
commit 777e3f58e1
2 changed files with 12 additions and 3 deletions

View File

@ -22,7 +22,6 @@
import unittest
from PyQt5.QtCore import QUrl, QPoint
from PyQt5.QtWebKitWidgets import QWebPage
from qutebrowser.browser import tabhistory
from qutebrowser.browser.tabhistory import TabHistoryItem as Item
@ -35,7 +34,7 @@ class SerializeHistoryTests(unittest.TestCase):
"""Tests for serialize()."""
def setUp(self):
self.page = QWebPage()
self.page = helpers.get_webpage()
self.history = self.page.history()
self.assertEqual(self.history.count(), 0)
@ -109,7 +108,7 @@ class SerializeHistorySpecialTests(unittest.TestCase):
"""Tests for serialize() without items set up in setUp."""
def setUp(self):
self.page = QWebPage()
self.page = helpers.get_webpage()
self.history = self.page.history()
self.assertEqual(self.history.count(), 0)

View File

@ -25,6 +25,8 @@ import contextlib
from unittest import mock
from PyQt5.QtGui import QKeyEvent
from PyQt5.QtWebKitWidgets import QWebPage
from PyQt5.QtNetwork import QNetworkAccessManager
@contextlib.contextmanager
@ -75,6 +77,14 @@ def fake_keyevent(key, modifiers=0, text=''):
return evtmock
def get_webpage():
"""Get a new QWebPage object."""
page = QWebPage()
nam = page.networkAccessManager()
nam.setNetworkAccessible(QNetworkAccessManager.NotAccessible)
return page
class MessageModule:
"""A drop-in replacement for qutebrowser.utils.message."""