forked from fossasia/query-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit tests for ask.py (fossasia#368)
- Loading branch information
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |