generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 189
test(http_request): add integration test for http_request tool #113
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
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,92 @@ | ||
| """Integration tests for HTTP request functionality using Strands Agent. | ||
| This module contains integration tests that verify the HTTP request tool's ability | ||
| to handle various HTTP methods (GET, POST, PUT) and operations like downloading | ||
| files and interacting with AWS S3 services. | ||
| """ | ||
|
|
||
| import os | ||
|
|
||
| import pytest | ||
| from strands import Agent | ||
| from strands_tools import http_request | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def agent(): | ||
| """Create an Agent instance configured with HTTP request tool.""" | ||
| return Agent(tools=[http_request]) | ||
|
|
||
|
|
||
| def test_get_http_request(agent): | ||
| """Test GET request functionality by fetching GitHub repository information. | ||
| Verifies that the agent can successfully make a GET request to the GitHub API | ||
| and retrieve repository star count information. | ||
| """ | ||
| response = agent( | ||
| "Send a GET request to https://api.github.com/repos/strands-agents/sdk-python and show me the number of stars" | ||
| ) | ||
| print(str(response)) | ||
| assert "stars" in str(response).lower() | ||
|
|
||
|
|
||
| def test_post_http_request(agent): | ||
| """Test POST request functionality with JSON payload. | ||
| Verifies that the agent can successfully make a POST request with a JSON body | ||
| to httpbin.org and receive the expected response containing the sent data. | ||
| Note: | ||
| Test may be skipped if the external endpoint is unavailable or returns | ||
| a cancelled response due to service instability. | ||
| """ | ||
| response = agent('Send a POST request to https://httpbin.org/post with JSON body {"foo": "bar"}') | ||
| if "cancelled" in str(response).lower(): | ||
| pytest.skip("This test is flaky due to their endpoint. Skipping for now.") | ||
| assert "foo" in str(response).lower(), str(response) | ||
|
|
||
|
|
||
| def test_update_http_request(agent): | ||
| """Test PUT request functionality with JSON payload. | ||
| Verifies that the agent can successfully make a PUT request with a JSON body | ||
| to httpbin.org for update operations and receive the expected response. | ||
| Note: | ||
| Test may be skipped if the external endpoint is unavailable or returns | ||
| a cancelled response due to service instability. | ||
| """ | ||
| response = agent('Send a PUT request to https://httpbin.org/put with JSON body {"update": true}') | ||
| if "cancelled" in str(response).lower(): | ||
| pytest.skip("This test is flaky due to their endpoint. Skipping for now.") | ||
| assert "update" in str(response).lower(), str(response) | ||
|
|
||
|
|
||
| def test_download_http_request(agent): | ||
| """Test file download functionality via HTTP request. | ||
| Verifies that the agent can successfully download a file (PNG image) from | ||
| a remote URL and provide confirmation of the download operation. | ||
| """ | ||
| response = agent("Download the PNG logo from https://www.python.org/static/community_logos/python-logo.png") | ||
| assert "successfully" in str(response).lower() or "image" in str(response).lower(), str(response) | ||
|
|
||
|
|
||
| @pytest.mark.skipif("AWS_ACCESS_KEY_ID" not in os.environ, reason="ACCESS_KEY_ID environment variable missing") | ||
| def test_list_s3_bucket_http_request(agent): | ||
| """Test AWS S3 bucket listing functionality via HTTP requests. | ||
| Verifies that the agent can successfully interact with AWS S3 services | ||
| to list buckets in a specified region using HTTP requests. | ||
| Note: | ||
| This test requires AWS_ACCESS_KEY_ID environment variable to be set. | ||
| The test will be skipped if AWS credentials are not available. | ||
| Uses AWS_REGION environment variable or defaults to 'us-east-1'. | ||
| """ | ||
| region = os.getenv("AWS_REGION", "us-east-1") | ||
| response = agent(f"List all S3 buckets in region {region}.") | ||
| assert "s3 buckets" in str(response).lower(), str(response) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.