Skip to content

Commit

Permalink
Added unit tests for baidu.py, bing.py, duckduckgo.py, google.py
Browse files Browse the repository at this point in the history
mojeek.py. parsijoo.py, quora.py, yahoo.py, youtube.py (fossasia#368)
  • Loading branch information
dilraj45 committed Jan 16, 2018
1 parent 6654766 commit 69e16b7
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/test_baidu.py
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()
19 changes: 19 additions & 0 deletions test/test_bing.py
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()
17 changes: 17 additions & 0 deletions test/test_duckduckgo.py
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()
17 changes: 17 additions & 0 deletions test/test_google.py
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()
15 changes: 15 additions & 0 deletions test/test_mojeek.py
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()
23 changes: 23 additions & 0 deletions test/test_parsijoo.py
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()
17 changes: 17 additions & 0 deletions test/test_quora.py
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()
17 changes: 17 additions & 0 deletions test/test_yahoo.py
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()
19 changes: 19 additions & 0 deletions test/test_youtube.py
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()

0 comments on commit 69e16b7

Please sign in to comment.