Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve our pytests #384

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions app/test_server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
# Let's get pytest turned on before we start testing in earnest
# We need to support absolute_import project-wide before this will work...

from .scrapers import small_test
from .scrapers import scrapers, small_test


def test_small_test():
Expand All @@ -14,7 +14,6 @@ def test_small_test():
import pytest
import requests


PYTHON3 = sys.version_info.major >= 3
REASON = 'Python 3 blocked until #297 goes live'
TRAVIS_CI = os.getenv('TRAVIS', False) # Running in Travis CI?
Expand All @@ -27,17 +26,29 @@ def test_true():
@pytest.mark.xfail(PYTHON3 or not TRAVIS_CI, reason=REASON)
def test_invalid_url_api_call():
response = requests.get('http://localhost:7001/api/v1/search/invalid_url')
assert response.json()['Status Code'] == 404
assert response.status_code == 404


def make_engine_api_call(engine_name):
url = 'http://localhost:7001/api/v1/search/' + engine_name
assert requests.get(url).json()['Status Code'] == 400, engine_name
assert requests.get(url).status_code == 400, engine_name

if engine_name in ('dailymotion', 'exalead', 'mojeek', 'yandex'):
return # These engines need to be fixed so that they pass this test
response = requests.get(url + '?query=fossaisa&num=3')
assert response.status_code == 200, '{}: {}'.format(engine_name,
response.status_code)
links = response.json()
# These engines run in search_without_count() mode so we do not test length
if engine_name not in ('quora', 'youtube'):
assert len(links) == 3, '{}: {}'.format(engine_name, len(links))
assert all('link' in link for link in links), engine_name
assert all('title' in link for link in links), engine_name


@pytest.mark.xfail(PYTHON3 or not TRAVIS_CI, reason=REASON)
def test_engine_api_calls(engine_names=None):
engines = ('ask', 'baidu', 'bing', 'dailymotion', 'duckduckgo', 'exalead',
'google', 'mojeek', 'parsijoo', 'quora', 'yahoo', 'yandex', 'youtube')
engines = """ask baidu bing dailymotion duckduckgo exalead google
mojeek parsijoo quora yahoo yandex youtube""".split()
for engine_name in (engine_names or engines):
make_engine_api_call(engine_name)