Skip to content

Commit

Permalink
Added unit tests for ask.py (fossasia#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
dilraj45 committed Jan 16, 2018
1 parent ade7f22 commit 6654766
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions test/test_ask.py
Original file line number Diff line number Diff line change
@@ -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 = """<div class="PartialSearchResults-noresults">
<div class="PartialSearchResults-noresults-body">
<p>No results for:</p>
<p><b>44754546546545545465465f4654f654654</b></p>
<p>Please try again.</p>
</div>
</div>"""
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 = """<div class="PartialSearchResults-item" data-zen="true">
<div class="PartialSearchResults-item-title">
<a class="PartialSearchResults-item-title-link result-link"
href='mock_url'>mock_title</a>
</div>
<p class="PartialSearchResults-item-abstract">mock_desc</p>
</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',
'desc': u'mock_desc'
}
]
if not resp == expected_resp:
raise AssertionError()


def test_parse_response_without_desc():
html_div = """<div class="PartialSearchResults-item" data-zen="true">
<div class="PartialSearchResults-item-title">
<a class="PartialSearchResults-item-title-link result-link"
href='mock_url'>mock_title</a>
</div>
</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()

0 comments on commit 6654766

Please sign in to comment.