From 6654766b6a0b7731b77450c55df17766ae6bf61c Mon Sep 17 00:00:00 2001 From: dilraj45 Date: Sun, 14 Jan 2018 21:45:14 +0530 Subject: [PATCH] Added unit tests for ask.py (#368) --- test/test_ask.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 test/test_ask.py 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_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 = """
+ +
""" + 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()