Add test for blocking sites from search results
This commit is contained in:
parent
2856ae2f93
commit
b1404ab94c
|
@ -3,6 +3,9 @@ from app.filter import Filter
|
||||||
from app.utils.session import generate_user_key
|
from app.utils.session import generate_user_key
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from dateutil.parser import *
|
from dateutil.parser import *
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
from test.conftest import demo_config
|
||||||
|
|
||||||
|
|
||||||
def get_search_results(data):
|
def get_search_results(data):
|
||||||
|
@ -46,6 +49,29 @@ def test_post_results(client):
|
||||||
assert len(get_search_results(rv.data)) <= 15
|
assert len(get_search_results(rv.data)) <= 15
|
||||||
|
|
||||||
|
|
||||||
|
def test_block_results(client):
|
||||||
|
rv = client.post('/search', data=dict(q='pinterest'))
|
||||||
|
assert rv._status_code == 200
|
||||||
|
|
||||||
|
has_pinterest = False
|
||||||
|
for link in BeautifulSoup(rv.data, 'html.parser').find_all('a', href=True):
|
||||||
|
if 'pinterest.com' in urlparse(link['href']).netloc:
|
||||||
|
has_pinterest = True
|
||||||
|
break
|
||||||
|
|
||||||
|
assert has_pinterest
|
||||||
|
|
||||||
|
demo_config['block'] = 'pinterest.com'
|
||||||
|
rv = client.post('/config', data=demo_config)
|
||||||
|
assert rv._status_code == 302
|
||||||
|
|
||||||
|
rv = client.post('/search', data=dict(q='pinterest'))
|
||||||
|
assert rv._status_code == 200
|
||||||
|
|
||||||
|
for link in BeautifulSoup(rv.data, 'html.parser').find_all('a', href=True):
|
||||||
|
assert 'pinterest.com' not in urlparse(link['href']).netloc
|
||||||
|
|
||||||
|
|
||||||
# TODO: Unit test the site alt method instead -- the results returned
|
# TODO: Unit test the site alt method instead -- the results returned
|
||||||
# are too unreliable for this test in particular.
|
# are too unreliable for this test in particular.
|
||||||
# def test_site_alts(client):
|
# def test_site_alts(client):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user