mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2026-01-07 00:04:26 +01:00
Validate URLs in web commands before execution (#2616)
Co-authored-by: Reinier van der Leer <github@pwuts.nl>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
# Generated by CodiumAI
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
from autogpt.commands.web_requests import scrape_text
|
||||
@@ -58,9 +59,14 @@ class TestScrapeText:
|
||||
url = "http://www.example.com"
|
||||
assert scrape_text(url) == expected_text
|
||||
|
||||
# Tests that the function returns an error message when an invalid or unreachable
|
||||
# Tests that an error is raised when an invalid url is provided.
|
||||
def test_invalid_url(self):
|
||||
url = "invalidurl.com"
|
||||
pytest.raises(ValueError, scrape_text, url)
|
||||
|
||||
# Tests that the function returns an error message when an unreachable
|
||||
# url is provided.
|
||||
def test_invalid_url(self, mocker):
|
||||
def test_unreachable_url(self, mocker):
|
||||
# Mock the requests.get() method to raise an exception
|
||||
mocker.patch(
|
||||
"requests.Session.get", side_effect=requests.exceptions.RequestException
|
||||
@@ -68,7 +74,7 @@ class TestScrapeText:
|
||||
|
||||
# Call the function with an invalid URL and assert that it returns an error
|
||||
# message
|
||||
url = "http://www.invalidurl.com"
|
||||
url = "http://thiswebsitedoesnotexist.net/"
|
||||
error_message = scrape_text(url)
|
||||
assert "Error:" in error_message
|
||||
|
||||
|
||||
Reference in New Issue
Block a user