Skip to content

Commit

Permalink
Updated Test
Browse files Browse the repository at this point in the history
  • Loading branch information
luciferlinx101 committed Jul 2, 2023
1 parent cc9c7e6 commit 3845abe
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions tests/unit_tests/test_tool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@
from unittest.mock import Mock, patch, mock_open, MagicMock
from superagi.tool_manager import parse_github_url, download_tool, load_tools_config, download_and_extract_tools


def test_parse_github_url():
url = 'https://github.com/owner/repo'
assert parse_github_url(url) == 'owner/repo/main'


def setup_function():
os.makedirs('target_folder', exist_ok=True)


# Teardown function to remove the directory
def teardown_function():
shutil.rmtree('target_folder')


@patch('requests.get')
@patch('zipfile.ZipFile')
def test_download_tool(mock_zip, mock_get):
Expand All @@ -31,7 +35,6 @@ def test_download_tool(mock_zip, mock_get):
mock_zip.assert_called_once_with('target_folder/tool.zip', 'r')



@patch('json.load')
def test_load_tools_config(mock_json_load):
mock_json_load.return_value = {"tools": {"tool1": "url1", "tool2": "url2"}}
Expand All @@ -40,12 +43,13 @@ def test_load_tools_config(mock_json_load):
assert config == {"tool1": "url1", "tool2": "url2"}


@patch('superagi.tool_manager.download_tool')
@patch('superagi.tool_manager.load_tools_config')
def test_download_and_extract_tools(mock_load_tools_config, mock_download_tool):
@patch('superagi.tool_manager.download_tool')
def test_download_and_extract_tools(mock_download_tool, mock_load_tools_config):
mock_load_tools_config.return_value = {"tool1": "url1", "tool2": "url2"}

download_and_extract_tools()

mock_load_tools_config.assert_called_once()
mock_download_tool.assert_any_call('url1', 'tools/tool1')
mock_download_tool.assert_any_call('url2', 'tools/tool2')
mock_download_tool.assert_any_call('url1', os.path.join('superagi', 'tools', 'tool1'))
mock_download_tool.assert_any_call('url2', os.path.join('superagi', 'tools', 'tool2'))

0 comments on commit 3845abe

Please sign in to comment.