Improve coverage and code cleanup
This commit is contained in:
parent
f8fcd48998
commit
99ede3f551
@ -32,45 +32,52 @@ from qutebrowser.browser import adblock
|
||||
from qutebrowser.utils import objreg
|
||||
from qutebrowser.commands import cmdexc
|
||||
|
||||
WHITELISTED_HOSTS = ('qutebrowser.org', 'goodhost.gov')
|
||||
|
||||
BLOCKED_HOSTS = ('verygoodhost.com',
|
||||
'goodhost.gov',
|
||||
'mediumhost.io',
|
||||
'malware.badhost.org',
|
||||
'4-verybadhost.com',
|
||||
'ads.worsthostever.net',
|
||||
'localhost')
|
||||
WHITELISTED_HOSTS = ('qutebrowser.org', 'mediumhost.io')
|
||||
|
||||
BLOCKLIST_HOSTS = ('localhost',
|
||||
'mediumhost.io',
|
||||
'malware.badhost.org',
|
||||
'4-verybadhost.com',
|
||||
'ads.worsthostever.net')
|
||||
|
||||
CLEAN_HOSTS = ('goodhost.gov', 'verygoodhost.com')
|
||||
|
||||
URLS_TO_CHECK = ('http://localhost',
|
||||
'ftp://goodhost.gov',
|
||||
'http://mediumhost.io',
|
||||
'http://malware.badhost.org',
|
||||
'http://4-verybadhost.com',
|
||||
'http://ads.worsthostever.net',
|
||||
'http://verygoodhost.com',
|
||||
'ftp://perfecthost.com',
|
||||
'http://goodhost.gov',
|
||||
'ftp://verygoodhost.com'
|
||||
'http://qutebrowser.org')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def data_tmpdir(monkeypatch, tmpdir):
|
||||
|
||||
"""Set tmpdir as datadir"""
|
||||
monkeypatch.setattr('qutebrowser.utils.standarddir.data',
|
||||
lambda: str(tmpdir))
|
||||
|
||||
tmpdir = str(tmpdir)
|
||||
monkeypatch.setattr('qutebrowser.utils.standarddir.data', lambda: tmpdir)
|
||||
|
||||
|
||||
# XXX Why does read_hosts needs basedir to be None
|
||||
# in order to print message 'run adblock-update to read host blocklist' ?
|
||||
# browser/adblock.py line 138
|
||||
class BaseDirStub:
|
||||
"""Mock for objreg.get['args']
|
||||
called in adblock.HostBlocker.read_hosts."""
|
||||
|
||||
"""Mock for objreg.get('args') called in adblock.HostBlocker.read_hosts."""
|
||||
|
||||
def __init__(self):
|
||||
self.basedir = None
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def basedir():
|
||||
|
||||
"""Register a Fake basedir."""
|
||||
|
||||
args = BaseDirStub()
|
||||
objreg.register('args', args)
|
||||
yield args
|
||||
@ -78,22 +85,29 @@ def basedir():
|
||||
|
||||
|
||||
class FakeDownloadItem(QObject):
|
||||
|
||||
"""Mock browser.downloads.DownloadItem."""
|
||||
|
||||
finished = pyqtSignal()
|
||||
|
||||
def __init__(self, fileobj):
|
||||
def __init__(self, fileobj, name):
|
||||
super().__init__()
|
||||
self.fileobj = fileobj
|
||||
self.name = name
|
||||
self.successful = True
|
||||
|
||||
|
||||
class FakeDownloadManager:
|
||||
|
||||
"""Mock browser.downloads.DownloadManager."""
|
||||
|
||||
def get(self, url, fileobj, **kwargs):
|
||||
"""Returns a FakeDownloadItem instance with a fileobj
|
||||
copied from given fake url file."""
|
||||
download_item = FakeDownloadItem(fileobj)
|
||||
|
||||
"""Return a FakeDownloadItem instance with a fileobj
|
||||
whose content is copied from the file the given url links to.
|
||||
"""
|
||||
|
||||
download_item = FakeDownloadItem(fileobj, name=url.path())
|
||||
with open(url.path(), 'rb') as fake_url_file:
|
||||
# Ensure cursors are at position 0 before copying
|
||||
fake_url_file.seek(0)
|
||||
@ -101,9 +115,12 @@ class FakeDownloadManager:
|
||||
shutil.copyfileobj(fake_url_file, download_item.fileobj)
|
||||
return download_item
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def download_stub(win_registry):
|
||||
|
||||
"""Register a FakeDownloadManager."""
|
||||
|
||||
stub = FakeDownloadManager()
|
||||
objreg.register('download-manager', stub,
|
||||
scope='window', window='last-focused')
|
||||
@ -111,150 +128,305 @@ def download_stub(win_registry):
|
||||
objreg.delete('download-manager', scope='window', window='last-focused')
|
||||
|
||||
|
||||
def create_zipfile(directory, files, zipname='test'):
|
||||
|
||||
"""Return a path to a created zip file
|
||||
|
||||
Args :
|
||||
- directory : path object where to create the zip file
|
||||
- files : list of paths to each file to add in the zipfile
|
||||
- zipname : name to give to the zip file.
|
||||
"""
|
||||
|
||||
def create_zipfile(files, directory, zipname='test'):
|
||||
"""Returns a zipfile populated with given files and its name."""
|
||||
directory = str(directory)
|
||||
zipfile_path = os.path.join(directory, zipname + '.zip')
|
||||
with zipfile.ZipFile(zipfile_path, 'w') as new_zipfile:
|
||||
for file_name in files:
|
||||
new_zipfile.write(file_name, arcname=os.path.basename(file_name))
|
||||
# Removes path from file name
|
||||
return new_zipfile, zipfile_path
|
||||
return zipfile_path
|
||||
|
||||
|
||||
def create_blocklist(directory,
|
||||
blocked_hosts=BLOCKLIST_HOSTS,
|
||||
name='hosts',
|
||||
line_format='one_per_line'):
|
||||
|
||||
"""Return a QUrl instance linking to a blocklist file.
|
||||
|
||||
Args:
|
||||
- directory : path object where to create the blocklist file
|
||||
- blocked_hosts : an iterable of string hosts to add to the blocklist
|
||||
- name : name to give to the blocklist file
|
||||
- line_format : 'etc_hosts' --> /etc/hosts format
|
||||
'one_per_line' --> one host per line format
|
||||
'not_correct' --> Not a correct hosts file format.
|
||||
"""
|
||||
|
||||
def create_blocklist(directory, blocked_hosts=BLOCKED_HOSTS,
|
||||
name='hosts', line_format=None):
|
||||
"""Returns a QUrl instance linking to a file with given name in given
|
||||
directory which contains a list of given blocked_hosts."""
|
||||
blocklist = QUrl(os.path.join(str(directory), name))
|
||||
with open(blocklist.path(), 'w', encoding='UTF-8') as hosts:
|
||||
# ensure comments are ignored when processing blocklist
|
||||
hosts.write('# Blocked Hosts List #\n\n')
|
||||
if line_format == 'etc_hosts':
|
||||
if line_format == 'etc_hosts': # /etc/hosts like format
|
||||
for path in blocked_hosts:
|
||||
hosts.write('127.0.0.1 ' + path + '\n')
|
||||
elif line_format == 'no_hosts':
|
||||
hosts.write('This file is not a hosts file')
|
||||
else: #one host per line format
|
||||
elif line_format == 'one_per_line':
|
||||
for path in blocked_hosts:
|
||||
hosts.write(path + '\n')
|
||||
elif line_format == 'not_correct':
|
||||
for path in blocked_hosts:
|
||||
hosts.write(path + ' This is not a correct hosts file\n')
|
||||
return blocklist
|
||||
|
||||
|
||||
def assert_urls(host_blocker,
|
||||
blocked_hosts=BLOCKED_HOSTS,
|
||||
blocked=BLOCKLIST_HOSTS,
|
||||
whitelisted_hosts=WHITELISTED_HOSTS,
|
||||
urls_to_check=URLS_TO_CHECK):
|
||||
|
||||
"""Test if urls_to_check are effectively blocked or not by HostBlocker
|
||||
Url in blocked_hosts and not in whitelisted_hosts should be blocked
|
||||
All other Urls should not be blocked."""
|
||||
whitelisted_hosts = list(whitelisted_hosts) + list(host_blocker.WHITELISTED)
|
||||
Ensure Urls in blocked and not in whitelisted are blocked
|
||||
All other Urls are not to be blocked."""
|
||||
|
||||
whitelisted = list(whitelisted_hosts) + list(host_blocker.WHITELISTED)
|
||||
for str_url in urls_to_check:
|
||||
url = QUrl(str_url)
|
||||
host = url.host()
|
||||
if host in blocked_hosts and host not in whitelisted_hosts:
|
||||
if host in blocked and host not in whitelisted:
|
||||
assert host_blocker.is_blocked(url)
|
||||
else:
|
||||
assert not host_blocker.is_blocked(url)
|
||||
|
||||
|
||||
class TestHostBlockerUpdate:
|
||||
def generic_blocklists(directory):
|
||||
|
||||
"""Tests for function adblock_update of class HostBlocker."""
|
||||
"""Return a generic list of files to be used in hosts-block-lists option.
|
||||
This list contains :
|
||||
- a remote zip file with 1 hosts file and 2 useless files
|
||||
- a remote zip file with only useless files
|
||||
(Should raise a FileNotFoundError)
|
||||
- a remote zip file with only one valid hosts file
|
||||
- a local text file with valid hosts
|
||||
- a remote text file without valid hosts format."""
|
||||
|
||||
def generic_blocklists(self, directory):
|
||||
file1 = create_blocklist(directory, BLOCKED_HOSTS[5:], 'hosts', 'etc_hosts')
|
||||
file2 = create_blocklist(directory, name='README', line_format='no_hosts')
|
||||
file3 = create_blocklist(directory, BLOCKED_HOSTS[:2], 'false_positive')
|
||||
files_to_zip = [file1.path(), file2.path(), file3.path()]
|
||||
zip_path = create_zipfile(files_to_zip, directory, 'block1')[1]
|
||||
remote_blocklist1 = QUrl(zip_path)
|
||||
# remote zip file with 1 hosts file and 2 useless files
|
||||
file1 = create_blocklist(directory,
|
||||
blocked_hosts=CLEAN_HOSTS,
|
||||
name='README',
|
||||
line_format='not_correct')
|
||||
file2 = create_blocklist(directory,
|
||||
blocked_hosts=BLOCKLIST_HOSTS[:3],
|
||||
name='hosts',
|
||||
line_format='etc_hosts')
|
||||
file3 = create_blocklist(directory,
|
||||
blocked_hosts=CLEAN_HOSTS,
|
||||
name='false_positive',
|
||||
line_format='one_per_line')
|
||||
files_to_zip = [file1.path(), file2.path(), file3.path()]
|
||||
zip_path = create_zipfile(directory, files_to_zip, 'block1')
|
||||
blocklist1 = QUrl(zip_path)
|
||||
|
||||
blocklist2 = create_blocklist(directory, [BLOCKED_HOSTS[4]], 'malwarelist', 'etc_hosts')
|
||||
zip_path = create_zipfile([blocklist2.path()], directory, 'block2')[1]
|
||||
remote_blocklist2 = QUrl(zip_path)
|
||||
# remote zip file without file named hosts
|
||||
# (Should raise a FileNotFoundError)
|
||||
file1 = create_blocklist(directory,
|
||||
blocked_hosts=CLEAN_HOSTS,
|
||||
name='md5sum',
|
||||
line_format='etc_hosts')
|
||||
file2 = create_blocklist(directory,
|
||||
blocked_hosts=CLEAN_HOSTS,
|
||||
name='README',
|
||||
line_format='not_correct')
|
||||
file3 = create_blocklist(directory,
|
||||
blocked_hosts=CLEAN_HOSTS,
|
||||
name='false_positive',
|
||||
line_format='one_per_line')
|
||||
files_to_zip = [file1.path(), file2.path(), file3.path()]
|
||||
zip_path = create_zipfile(directory, files_to_zip, 'block2')
|
||||
blocklist2 = QUrl(zip_path)
|
||||
|
||||
# A local list with one host per line
|
||||
local_blocklist3 = create_blocklist(directory, [BLOCKED_HOSTS[3]], 'mycustomblocklist', 'etc_hosts')
|
||||
local_blocklist3.setScheme('file')
|
||||
# remote zip file with only one valid hosts file inside
|
||||
blocklist3 = create_blocklist(directory,
|
||||
blocked_hosts=[BLOCKLIST_HOSTS[3]],
|
||||
name='malwarelist',
|
||||
line_format='etc_hosts')
|
||||
zip_path = create_zipfile(directory, [blocklist3.path()], 'block3')
|
||||
blocklist3 = QUrl(zip_path)
|
||||
|
||||
# A list that cannot be read due to its formatting
|
||||
remote_blocklist4 = create_blocklist(directory, [BLOCKED_HOSTS[2]], 'badlist', 'no_hosts')
|
||||
# local text file with valid hosts
|
||||
blocklist4 = create_blocklist(directory,
|
||||
blocked_hosts=[BLOCKLIST_HOSTS[4]],
|
||||
name='mycustomblocklist',
|
||||
line_format='one_per_line')
|
||||
blocklist4.setScheme('file')
|
||||
|
||||
return [remote_blocklist1, remote_blocklist2, local_blocklist3, remote_blocklist4]
|
||||
# remote text file without valid hosts format
|
||||
blocklist5 = create_blocklist(directory,
|
||||
blocked_hosts=CLEAN_HOSTS,
|
||||
name='notcorrectlist',
|
||||
line_format='not_correct')
|
||||
|
||||
def test_without_datadir(self, config_stub, tmpdir,
|
||||
monkeypatch, win_registry):
|
||||
"""No directory for data configured so no hosts file exists.
|
||||
CommandError is raised by adblock_update
|
||||
Ensure no url is blocked."""
|
||||
config_stub.data = {'content':
|
||||
{'host-block-lists': self.generic_blocklists(tmpdir),
|
||||
'host-blocking-enabled': True}}
|
||||
monkeypatch.setattr('qutebrowser.utils.standarddir.data',
|
||||
lambda: None)
|
||||
host_blocker = adblock.HostBlocker()
|
||||
with pytest.raises(cmdexc.CommandError):
|
||||
host_blocker.adblock_update(0)
|
||||
host_blocker.read_hosts()
|
||||
for str_url in URLS_TO_CHECK:
|
||||
assert not host_blocker.is_blocked(QUrl(str_url))
|
||||
return [blocklist1, blocklist2, blocklist3, blocklist4, blocklist5]
|
||||
|
||||
def test_disabled_blocking(self, basedir, config_stub, download_stub,
|
||||
data_tmpdir, tmpdir, win_registry):
|
||||
"""Ensure that no url is blocked when host blocking is disabled."""
|
||||
config_stub.data = {'content':
|
||||
{'host-block-lists': self.generic_blocklists(tmpdir),
|
||||
'host-blocking-enabled': False}}
|
||||
host_blocker = adblock.HostBlocker()
|
||||
|
||||
def test_without_datadir(config_stub, tmpdir, monkeypatch, win_registry):
|
||||
|
||||
"""No directory for data configured so no hosts file exists.
|
||||
CommandError is raised by adblock_update
|
||||
Ensure no url is blocked."""
|
||||
|
||||
config_stub.data = {'content':
|
||||
{'host-block-lists': generic_blocklists(tmpdir),
|
||||
'host-blocking-enabled': True}}
|
||||
monkeypatch.setattr('qutebrowser.utils.standarddir.data', lambda: None)
|
||||
host_blocker = adblock.HostBlocker()
|
||||
with pytest.raises(cmdexc.CommandError):
|
||||
host_blocker.adblock_update(0)
|
||||
host_blocker._in_progress[0].finished.emit()
|
||||
host_blocker.read_hosts()
|
||||
for str_url in URLS_TO_CHECK:
|
||||
assert not host_blocker.is_blocked(QUrl(str_url))
|
||||
host_blocker.read_hosts()
|
||||
for str_url in URLS_TO_CHECK:
|
||||
assert not host_blocker.is_blocked(QUrl(str_url))
|
||||
|
||||
def test_no_blocklist(self, config_stub, download_stub,
|
||||
data_tmpdir, basedir, tmpdir, win_registry):
|
||||
"""Ensure no host is blocked when no blocklist exists."""
|
||||
config_stub.data = {'content':
|
||||
{'host-block-lists' : None,
|
||||
'host-blocking-enabled': True}}
|
||||
host_blocker = adblock.HostBlocker()
|
||||
host_blocker.adblock_update(0)
|
||||
host_blocker.read_hosts()
|
||||
for str_url in URLS_TO_CHECK:
|
||||
assert not host_blocker.is_blocked(QUrl(str_url))
|
||||
|
||||
def test_successful_update(self, config_stub, basedir, download_stub,
|
||||
data_tmpdir, tmpdir, win_registry):
|
||||
config_stub.data = {'content':
|
||||
{'host-block-lists': self.generic_blocklists(tmpdir),
|
||||
'host-blocking-enabled': True,
|
||||
'host-blocking-whitelist': None}}
|
||||
host_blocker = adblock.HostBlocker()
|
||||
host_blocker.adblock_update(0)
|
||||
# Simulate download is finished
|
||||
# XXX Is it ok to use private attribute hostblocker._in_progress ?
|
||||
while host_blocker._in_progress != []:
|
||||
host_blocker._in_progress[0].finished.emit()
|
||||
host_blocker.read_hosts()
|
||||
assert_urls(host_blocker, BLOCKED_HOSTS[3:], whitelisted_hosts=[])
|
||||
def test_disabled_blocking_update(basedir, config_stub, download_stub,
|
||||
data_tmpdir, tmpdir, win_registry):
|
||||
|
||||
class TestHostBlockerIsBlocked:
|
||||
"""Ensure that no url is blocked when host blocking is disabled."""
|
||||
|
||||
"""Tests for function adblock_update of class HostBlocker."""
|
||||
config_stub.data = {'content':
|
||||
{'host-block-lists': generic_blocklists(tmpdir),
|
||||
'host-blocking-enabled': False}}
|
||||
host_blocker = adblock.HostBlocker()
|
||||
host_blocker.adblock_update(0)
|
||||
while host_blocker._in_progress:
|
||||
current_download = host_blocker._in_progress[0]
|
||||
current_download.finished.emit()
|
||||
host_blocker.read_hosts()
|
||||
for str_url in URLS_TO_CHECK:
|
||||
assert not host_blocker.is_blocked(QUrl(str_url))
|
||||
|
||||
def test_with_whitelist(self, config_stub, basedir, download_stub,
|
||||
data_tmpdir, tmpdir, win_registry):
|
||||
""""""
|
||||
# Simulate adblock_update has already been run,
|
||||
# exclude localhost from blocked-hosts file
|
||||
filtered_blocked_hosts = BLOCKED_HOSTS[:-1]
|
||||
blocklist = create_blocklist(tmpdir,
|
||||
blocked_hosts=filtered_blocked_hosts,
|
||||
name="blocked-hosts")
|
||||
config_stub.data = {'content':
|
||||
{'host-block-lists': [blocklist],
|
||||
'host-blocking-enabled': True,
|
||||
'host-blocking-whitelist': WHITELISTED_HOSTS}}
|
||||
host_blocker = adblock.HostBlocker()
|
||||
host_blocker.read_hosts()
|
||||
assert_urls(host_blocker)
|
||||
|
||||
def test_no_blocklist_update(config_stub, download_stub,
|
||||
data_tmpdir, basedir, tmpdir, win_registry):
|
||||
|
||||
"""Ensure no host is blocked when no blocklist exists."""
|
||||
|
||||
config_stub.data = {'content':
|
||||
{'host-block-lists' : None,
|
||||
'host-blocking-enabled': True}}
|
||||
host_blocker = adblock.HostBlocker()
|
||||
host_blocker.adblock_update(0)
|
||||
host_blocker.read_hosts()
|
||||
for str_url in URLS_TO_CHECK:
|
||||
assert not host_blocker.is_blocked(QUrl(str_url))
|
||||
|
||||
|
||||
def test_successful_update(config_stub, basedir, download_stub,
|
||||
data_tmpdir, tmpdir, win_registry):
|
||||
|
||||
"""Ensure hosts from host-block-lists are correctly
|
||||
blocked after update."""
|
||||
|
||||
config_stub.data = {'content':
|
||||
{'host-block-lists': generic_blocklists(tmpdir),
|
||||
'host-blocking-enabled': True,
|
||||
'host-blocking-whitelist': None}}
|
||||
host_blocker = adblock.HostBlocker()
|
||||
host_blocker.adblock_update(0)
|
||||
# Simulate download is finished
|
||||
# XXX Is it ok to use private list hostblocker._in_progress ?
|
||||
while host_blocker._in_progress:
|
||||
current_download = host_blocker._in_progress[0]
|
||||
current_download.finished.emit()
|
||||
host_blocker.read_hosts()
|
||||
assert_urls(host_blocker, whitelisted_hosts=[])
|
||||
|
||||
|
||||
def test_failed_dl_update(config_stub, basedir, download_stub,
|
||||
data_tmpdir, tmpdir, win_registry):
|
||||
|
||||
""" One blocklist fails to download
|
||||
Ensure no hosts from this list is blocked."""
|
||||
|
||||
dl_fail_blocklist = create_blocklist(tmpdir,
|
||||
blocked_hosts=CLEAN_HOSTS,
|
||||
name='download_will_fail',
|
||||
line_format='one_per_line')
|
||||
hosts_to_block = generic_blocklists(tmpdir) + [dl_fail_blocklist]
|
||||
config_stub.data = {'content':
|
||||
{'host-block-lists': hosts_to_block,
|
||||
'host-blocking-enabled': True,
|
||||
'host-blocking-whitelist': None}}
|
||||
host_blocker = adblock.HostBlocker()
|
||||
host_blocker.adblock_update(0)
|
||||
while host_blocker._in_progress:
|
||||
current_download = host_blocker._in_progress[0]
|
||||
# if current download is the file we want to fail, make it fail
|
||||
if current_download.name == dl_fail_blocklist.path():
|
||||
current_download.successful = False
|
||||
current_download.finished.emit()
|
||||
host_blocker.read_hosts()
|
||||
assert_urls(host_blocker, whitelisted_hosts=[])
|
||||
|
||||
|
||||
def test_blocking_with_whitelist(config_stub, basedir, download_stub,
|
||||
data_tmpdir, tmpdir):
|
||||
|
||||
"""Ensure hosts in host-blocking-whitelist are taken into account."""
|
||||
|
||||
# Simulate adblock_update has already been run by naming it blocked-hosts,
|
||||
# exclude localhost from blocked-hosts file as it is in
|
||||
# host_blocker.WHITELISTED
|
||||
filtered_blocked_hosts = BLOCKLIST_HOSTS[1:]
|
||||
blocklist = create_blocklist(tmpdir,
|
||||
blocked_hosts=filtered_blocked_hosts,
|
||||
name='blocked-hosts',
|
||||
line_format='one_per_line')
|
||||
config_stub.data = {'content':
|
||||
{'host-block-lists': [blocklist],
|
||||
'host-blocking-enabled': True,
|
||||
'host-blocking-whitelist': WHITELISTED_HOSTS}}
|
||||
host_blocker = adblock.HostBlocker()
|
||||
host_blocker.read_hosts()
|
||||
assert_urls(host_blocker)
|
||||
|
||||
|
||||
# XXX Intended behavior ?
|
||||
# User runs qutebrowser with host-blocking enabled
|
||||
# A blocklist is present in host-block-lists and blocked_hosts is populated
|
||||
#
|
||||
# User quits qutebrowser, empties host-block-lists from his config
|
||||
# User restarts qutebrowser, does adblock-update (which will return None)
|
||||
# read_hosts still returns hosts from unchanged blocked_hosts file
|
||||
#
|
||||
# Is this intended behavior or shouldn't on_config_changed be also called
|
||||
# during HostBlocker instance init to avoid this ?
|
||||
#
|
||||
# As a comparison,
|
||||
# host-block-lists is emptied with qutebrowser running
|
||||
# on_config_changed slot is activated
|
||||
# blocked_hosts is emptied
|
||||
# read_hosts doesn't return any host as expected
|
||||
|
||||
def test_config_change(config_stub, basedir, download_stub,
|
||||
data_tmpdir, tmpdir):
|
||||
|
||||
"""Ensure blocked_hosts gets a reset when host-block-list
|
||||
is changed to None."""
|
||||
|
||||
# Simulate adblock_update has already been run by naming it blocked-hosts,
|
||||
# exclude localhost from blocked-hosts file as it is in
|
||||
# host_blocker.WHITELISTED
|
||||
filtered_blocked_hosts = BLOCKLIST_HOSTS[1:]
|
||||
blocklist = create_blocklist(tmpdir,
|
||||
blocked_hosts=filtered_blocked_hosts,
|
||||
name='blocked-hosts',
|
||||
line_format='one_per_line')
|
||||
config_stub.data = {'content':
|
||||
{'host-block-lists': [blocklist],
|
||||
'host-blocking-enabled': True,
|
||||
'host-blocking-whitelist': None}}
|
||||
host_blocker = adblock.HostBlocker()
|
||||
host_blocker.read_hosts()
|
||||
config_stub.set('content', 'host-block-lists', None)
|
||||
host_blocker.read_hosts()
|
||||
for str_url in URLS_TO_CHECK:
|
||||
assert not host_blocker.is_blocked(QUrl(str_url))
|
||||
|
Loading…
Reference in New Issue
Block a user