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 baidu.py, bing.py, duckduckgo.py, google.py
mojeek.py. parsijoo.py, quora.py, yahoo.py, youtube.py (fossasia#368)
- Loading branch information
Showing
9 changed files
with
161 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,17 @@ | ||
from bs4 import BeautifulSoup | ||
|
||
from app.scrapers import Baidu | ||
|
||
|
||
def test_parse_response(): | ||
html_text = """<div class="result c-container "><h3 class="t"> | ||
<a href="mock_url" target="_blank">mock_title</a> | ||
</h3></div>""" | ||
dummy_soup = BeautifulSoup(html_text, 'html.parser') | ||
resp = Baidu().parse_response(dummy_soup) | ||
expected_resp = [{ | ||
'title': u'mock_title', | ||
'link': u'mock_url' | ||
}] | ||
if not resp == expected_resp: | ||
raise AssertionError() |
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,19 @@ | ||
from bs4 import BeautifulSoup | ||
|
||
from app.scrapers import Bing | ||
|
||
|
||
def test_parse_response(): | ||
html_text = """<li class="b_algo"> | ||
<h2><a href="mock_url">mock_title</h2> | ||
<div class="b_caption"><p>mock_desc</p> | ||
</div><li>""" | ||
dummy_soup = BeautifulSoup(html_text, 'html.parser') | ||
resp = Bing().parse_response(dummy_soup) | ||
expected_resp = [{ | ||
'title': u'mock_title', | ||
'link': u'mock_url', | ||
'desc': u'mock_desc' | ||
}] | ||
if not expected_resp == resp: | ||
raise AssertionError() |
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,17 @@ | ||
from bs4 import BeautifulSoup | ||
|
||
from app.scrapers import DuckDuckGo | ||
|
||
|
||
def test_parse_response(): | ||
html_text = """<h2 class="result__title"> | ||
<a class="result__a" href="mock_url">mock_title</a> | ||
</h2>""" | ||
dummy_soup = BeautifulSoup(html_text, 'html.parser') | ||
resp = DuckDuckGo().parse_response(dummy_soup) | ||
expected_resp = [{ | ||
'title': u'mock_title', | ||
'link': u'mock_url' | ||
}] | ||
if not resp == expected_resp: | ||
raise AssertionError() |
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,17 @@ | ||
from bs4 import BeautifulSoup | ||
|
||
from app.scrapers import Google | ||
|
||
|
||
def test_parse_response(): | ||
html_text = """<h3 class="r"> | ||
<a href="mock_url">mock_title</a> | ||
</h3>""" | ||
dummy_soup = BeautifulSoup(html_text, 'html.parser') | ||
expected_resp = [{ | ||
'title': u'mock_title', | ||
'link': u'mock_url' | ||
}] | ||
resp = Google().parse_response(dummy_soup) | ||
if not resp == expected_resp: | ||
raise AssertionError() |
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,15 @@ | ||
from bs4 import BeautifulSoup | ||
|
||
from app.scrapers import Mojeek | ||
|
||
|
||
def test_parse_response(): | ||
html_text = '<a href="mock_url" class="ob">mock_title</a>' | ||
dummy_soup = BeautifulSoup(html_text, 'html.parser') | ||
expected_resp = [{ | ||
'title': u'mock_title', | ||
'link': u'mock_url' | ||
}] | ||
resp = Mojeek().parse_response(dummy_soup) | ||
if not resp == expected_resp: | ||
raise AssertionError() |
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,23 @@ | ||
from bs4 import BeautifulSoup | ||
|
||
from app.scrapers import Parsijoo | ||
|
||
|
||
def test_parse_response(): | ||
html_text = """<div class="result"> | ||
<span class="result-title"> | ||
<a href="mock_url">""" + " " * 22 + """mock_title </a></span> | ||
<span class="result-url">mock_url</span> | ||
<span class="result-desc">""" + " " * 34 + """ mock_desc </span> | ||
<span class="result-similar"><a href="mock_similar_link" | ||
title="mock_similar_title">mock_similar</a> | ||
</span></div>""" | ||
dummy_soup = BeautifulSoup(html_text, 'html.parser') | ||
expected_resp = [{ | ||
'title': u'mock_title', | ||
'link': u'mock_url', | ||
'desc': u'mock_desc' | ||
}] | ||
resp = Parsijoo().parse_response(dummy_soup) | ||
if not resp == expected_resp: | ||
raise AssertionError() |
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,17 @@ | ||
from bs4 import BeautifulSoup | ||
|
||
from app.scrapers import Quora | ||
|
||
|
||
def test_parse_response(): | ||
html_text = "<div><a class='question_link' href='/mock_url'>" \ | ||
"<span class='question_text'><span class='rendered_qtext'>" \ | ||
"mock_title</span></span></a></div>" | ||
dummy_soup = BeautifulSoup(html_text, 'html.parser') | ||
expected_resp = [{ | ||
'title': u'mock_title', | ||
'link': u'https://www.quora.com/mock_url' | ||
}] | ||
resp = Quora().parse_response(dummy_soup) | ||
if not resp == expected_resp: | ||
raise AssertionError() |
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,17 @@ | ||
from bs4 import BeautifulSoup | ||
|
||
from app.scrapers import Yahoo | ||
|
||
|
||
def test_parse_response(): | ||
html_text = '<h3 class="title"><a class=" ac-algo fz-l ac-21th lh-24"' \ | ||
' href="//r.search.yahoo.com/_ylt=Awr;_ylu=X3--/RV=2/RE=15/RO=10' \ | ||
'/RU=mock_url/RK=2/RS=Gne">mock_title</a></h3> ' | ||
dummy_soup = BeautifulSoup(html_text, 'html.parser') | ||
expected_resp = [{ | ||
'title': u'mock_title', | ||
'link': u'mock_url' | ||
}] | ||
resp = Yahoo().parse_response(dummy_soup) | ||
if not resp == expected_resp: | ||
raise AssertionError() |
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,19 @@ | ||
from bs4 import BeautifulSoup | ||
|
||
from app.scrapers import Youtube | ||
|
||
|
||
def test_parse_response(): | ||
html_text = '<a href="/channel/UCQprMsG-raCIMlBudm20iLQ" ' \ | ||
'class="yt-uix-sessionlink">mock_channel</a><a href=' \ | ||
'"/watch?v=mock" class="yt-uix-tile-link yt-ui-ellipsis ' \ | ||
'yt-ui-ellipsis-2 yt-uix-sessionlink" ' \ | ||
'title="mock_title">mock_title</a>' | ||
dummy_soup = BeautifulSoup(html_text, 'html.parser') | ||
expected_resp = [{ | ||
'title': u'mock_title', | ||
'link': u'https://www.youtube.com/watch?v=mock' | ||
}] | ||
resp = Youtube().parse_response(dummy_soup) | ||
if not resp == expected_resp: | ||
raise AssertionError() |