diff --git a/test/test_ask.py b/test/test_ask.py new file mode 100644 index 00000000..b0d1c8f7 --- /dev/null +++ b/test/test_ask.py @@ -0,0 +1,62 @@ +from bs4 import BeautifulSoup + +from app.scrapers import Ask + + +def test_next_start(): + if 3 != Ask().next_start(2, None): + raise AssertionError() + + +def test_parse_response_for_none(): + html_text = """
+
+

No results for:

+

44754546546545545465465f4654f654654

+

Please try again.

+
+
""" + stub_soup = BeautifulSoup(html_text, 'html.parser') + resp = Ask().parse_response(stub_soup) + if resp: + raise AssertionError() + + +def test_parse_response_with_desc(): + html_div = """
+
+ mock_title +
+

mock_desc

+
""" + stub_soup_div = BeautifulSoup(html_div, 'html.parser') + resp = Ask().parse_response(stub_soup_div) + expected_resp = [ + { + 'link': u'mock_url', + 'title': u'mock_title', + 'desc': u'mock_desc' + } + ] + if not resp == expected_resp: + raise AssertionError() + + +def test_parse_response_without_desc(): + html_div = """
+
+ mock_title +
+
""" + stub_soup_div = BeautifulSoup(html_div, 'html.parser') + resp = Ask().parse_response(stub_soup_div) + expected_resp = [ + { + 'link': u'mock_url', + 'title': u'mock_title' + } + ] + if not resp == expected_resp: + raise AssertionError()