Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fixing tests to fit latest merges into master

Itamar Friedman5a8700060e55
diff --git a/requirements.txt b/requirements.txt
index dbfa774183..210f06d067 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -25,3 +25,5 @@ black
sourcery
isort
gitpython==3.1.31
+pytest
+pytest-mock
\ No newline at end of file
diff --git a/tests/local_cache_test.py b/tests/local_cache_test.py
index 9ac6aa54d9..91c922b062 100644
--- a/tests/local_cache_test.py
+++ b/tests/local_cache_test.py
@@ -1,5 +1,6 @@
import os
import sys
+import unittest
from autogpt.memory.local import LocalCache
diff --git a/tests/smoke_test.py b/tests/smoke_test.py
index 8d33cf8987..50e97b7b41 100644
--- a/tests/smoke_test.py
+++ b/tests/smoke_test.py
@@ -3,7 +3,7 @@ import subprocess
import sys
import unittest
-from autogpt.file_operations import delete_file, read_file
+from autogpt.commands.file_operations import delete_file, read_file
env_vars = {"MEMORY_BACKEND": "no_memory", "TEMPERATURE": "0"}
diff --git a/tests/unit/test_browse_scrape_links.py b/tests/unit/test_browse_scrape_links.py
index 0f051c1439..0a3340e739 100644
--- a/tests/unit/test_browse_scrape_links.py
+++ b/tests/unit/test_browse_scrape_links.py
@@ -4,7 +4,7 @@
# pip install pytest-mock
import pytest
-from scripts.browse import scrape_links
+from autogpt.commands.web_requests import scrape_links
"""
Code Analysis
@@ -55,7 +55,7 @@ class TestScrapeLinks:
mock_response.text = (
"<html><body><a href='https://www.google.com'>Google</a></body></html>"
)
- mocker.patch("requests.get", return_value=mock_response)
+ mocker.patch("requests.Session.get", return_value=mock_response)
# Call the function with a valid URL
result = scrape_links("https://www.example.com")
@@ -68,7 +68,7 @@ class TestScrapeLinks:
# Mock the requests.get() function to return an HTTP error response
mock_response = mocker.Mock()
mock_response.status_code = 404
- mocker.patch("requests.get", return_value=mock_response)
+ mocker.patch("requests.Session.get", return_value=mock_response)
# Call the function with an invalid URL
result = scrape_links("https://www.invalidurl.com")
@@ -82,7 +82,7 @@ class TestScrapeLinks:
mock_response = mocker.Mock()
mock_response.status_code = 200
mock_response.text = "<html><body><p>No hyperlinks here</p></body></html>"
- mocker.patch("requests.get", return_value=mock_response)
+ mocker.patch("requests.Session.get", return_value=mock_response)
# Call the function with a URL containing no hyperlinks
result = scrape_links("https://www.example.com")
@@ -105,7 +105,7 @@ class TestScrapeLinks:
</body>
</html>
"""
- mocker.patch("requests.get", return_value=mock_response)
+ mocker.patch("requests.Session.get", return_value=mock_response)
# Call the function being tested
result = scrape_links("https://www.example.com")
diff --git a/tests/unit/test_browse_scrape_text.py b/tests/unit/test_browse_scrape_text.py
index 98f5f558ab..61c19b058d 100644
--- a/tests/unit/test_browse_scrape_text.py
+++ b/tests/unit/test_browse_scrape_text.py
@@ -41,7 +41,7 @@ class TestScrapeText:
mock_response = mocker.Mock()
mock_response.status_code = 200
mock_response.text = f"<html><body><div><p style='color: blue;'>{expected_text}</p></div></body></html>"
- mocker.patch("requests.get", return_value=mock_response)
+ mocker.patch("requests.Session.get", return_value=mock_response)
# Call the function with a valid URL and assert that it returns the expected text
url = "http://www.example.com"
@@ -50,7 +50,7 @@ class TestScrapeText:
# Tests that the function returns an error message when an invalid or unreachable url is provided.
def test_invalid_url(self, mocker):
# Mock the requests.get() method to raise an exception
- mocker.patch("requests.get", side_effect=requests.exceptions.RequestException)
+ mocker.patch("requests.Session.get", side_effect=requests.exceptions.RequestException)
# Call the function with an invalid URL and assert that it returns an error message
url = "http://www.invalidurl.com"
@@ -63,7 +63,7 @@ class TestScrapeText:
mock_response = mocker.Mock()
mock_response.status_code = 200
mock_response.text = "<html><body></body></html>"
- mocker.patch("requests.get", return_value=mock_response)
+ mocker.patch("requests.Session.get", return_value=mock_response)
# Call the function with a valid URL and assert that it returns an empty string
url = "http://www.example.com"
@@ -72,7 +72,7 @@ class TestScrapeText:
# Tests that the function returns an error message when the response status code is an http error (>=400).
def test_http_error(self, mocker):
# Mock the requests.get() method to return a response with a 404 status code
- mocker.patch("requests.get", return_value=mocker.Mock(status_code=404))
+ mocker.patch("requests.Session.get", return_value=mocker.Mock(status_code=404))
# Call the function with a URL
result = scrape_text("https://www.example.com")
@@ -87,7 +87,7 @@ class TestScrapeText:
mock_response = mocker.Mock()
mock_response.status_code = 200
mock_response.text = html
- mocker.patch("requests.get", return_value=mock_response)
+ mocker.patch("requests.Session.get", return_value=mock_response)
# Call the function with a URL
result = scrape_text("https://www.example.com")
diff --git a/tests/unit/test_commands.py b/tests/unit/test_commands.py
index 21982f7e63..e15709aa37 100644
--- a/tests/unit/test_commands.py
+++ b/tests/unit/test_commands.py
@@ -1,5 +1,5 @@
import autogpt.agent.agent_manager as agent_manager
-from autogpt.app import start_agent, list_agents
+from autogpt.app import start_agent, list_agents, execute_command
import unittest
from unittest.mock import patch, MagicMock