From b1404ab94c9d30fb5abc819933a58f920becfaca Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Wed, 5 May 2021 13:41:05 -0400 Subject: [PATCH] Add test for blocking sites from search results --- test/test_results.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/test_results.py b/test/test_results.py index 38b9936..ff6fe4b 100644 --- a/test/test_results.py +++ b/test/test_results.py @@ -3,6 +3,9 @@ from app.filter import Filter from app.utils.session import generate_user_key from datetime import datetime from dateutil.parser import * +from urllib.parse import urlparse + +from test.conftest import demo_config def get_search_results(data): @@ -46,6 +49,29 @@ def test_post_results(client): 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 # are too unreliable for this test in particular. # def test_site_alts(client):