-
Notifications
You must be signed in to change notification settings - Fork 15.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
community: Handling missing key in Google Trends API response. (#15864)
- **Description:** Handing response where _interest_over_time_ is missing. - **Issue:** #15859 - **Dependencies:** None
- Loading branch information
Showing
2 changed files
with
39 additions
and
1 deletion.
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
33 changes: 33 additions & 0 deletions
33
libs/community/tests/integration_tests/utilities/test_google_trends.py
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,33 @@ | ||
"""Unit test for Google Trends API Wrapper.""" | ||
import os | ||
from unittest.mock import patch | ||
|
||
from langchain_community.utilities.google_trends import GoogleTrendsAPIWrapper | ||
|
||
|
||
@patch("serpapi.SerpApiClient.get_json") | ||
def test_unexpected_response(mocked_serpapiclient): | ||
os.environ["SERPAPI_API_KEY"] = "123abcd" | ||
resp = { | ||
"search_metadata": { | ||
"id": "659f32ec36e6a9107b46b5b4", | ||
"status": "Error", | ||
"json_endpoint": "https://serpapi.com/searches/.../659f32ec36e6a9107b46b5b4.json", | ||
"created_at": "2024-01-11 00:14:36 UTC", | ||
"processed_at": "2024-01-11 00:14:36 UTC", | ||
"google_trends_url": "https://trends.google.com/trends/api/explore?tz=420&req=%7B%22comparisonItem%22%3A%5B%7B%22keyword%22%3A%22Lego+building+trends+2022%22%2C%22geo%22%3A%22%22%2C%22time%22%3A%22today+12-m%22%7D%5D%2C%22category%22%3A0%2C%22property%22%3A%22%22%2C%22userConfig%22%3A%22%7BuserType%3A+%5C%22USER_TYPE_LEGIT_USER%5C%22%7D%22%7D", | ||
"prettify_html_file": "https://serpapi.com/searches/.../659f32ec36e6a9107b46b5b4.prettify", | ||
"total_time_taken": 90.14, | ||
}, | ||
"search_parameters": { | ||
"engine": "google_trends", | ||
"q": "Lego building trends 2022", | ||
"date": "today 12-m", | ||
"tz": "420", | ||
"data_type": "TIMESERIES", | ||
}, | ||
"error": "We couldn't get valid ... Please try again later.", | ||
} | ||
mocked_serpapiclient.return_value = resp | ||
tool = GoogleTrendsAPIWrapper() | ||
tool.run("does not matter") |