langchain/tests/integration_tests/utilities/test_googleserper_api.py
rogerserper b1446bea5f
google-serper: async + full json results + support for Google Images, Places and News (#4078)
* implemented arun, results, and aresults. Reuses aiosession if
available.
* helper tools GoogleSerperRun and GoogleSerperResults
* support for Google Images, Places and News (examples given) and
filtering based on time (e.g. past hour)
* updated docs
2023-05-03 22:35:48 -07:00

35 lines
1.1 KiB
Python

"""Integration test for Serper.dev's Google Search API Wrapper."""
import pytest
from langchain.utilities.google_serper import GoogleSerperAPIWrapper
def test_call() -> None:
"""Test that call gives the correct answer."""
search = GoogleSerperAPIWrapper()
output = search.run("What was Obama's first name?")
assert "Barack Hussein Obama II" in output
async def test_results() -> None:
"""Test that call gives the correct answer."""
search = GoogleSerperAPIWrapper()
output = search.results("What was Obama's first name?")
assert "Barack Hussein Obama II" in output["answerBox"]["answer"]
@pytest.mark.asyncio
async def test_async_call() -> None:
"""Test that call gives the correct answer."""
search = GoogleSerperAPIWrapper()
output = await search.arun("What was Obama's first name?")
assert "Barack Hussein Obama II" in output
@pytest.mark.asyncio
async def test_async_results() -> None:
"""Test that call gives the correct answer."""
search = GoogleSerperAPIWrapper()
output = await search.aresults("What was Obama's first name?")
assert "Barack Hussein Obama II" in output["answerBox"]["answer"]