mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-18 22:44:21 +01:00
* Fix all but one flake8 linting errors * Remove unused imports * Wrap strings that are too long * Add basic autogpts/autogpt/.flake8 * Delete planning_agent.py * Delete default_prompts.py * Delete _test_json_parser.py * Refactor the example function call in AgentProfileGeneratorConfiguration from a string to an object * Rewrite/update docstrings here and there while I'm at it * Minor change to the description of the `open_file` command * Use `user-agent` from config in web_selenium.py * Delete hardcoded ABILITIES from core/planning/templates.py * Delete duplicate and superseded test from test_image_gen.py * Fix parameter definitions in mock_commands.py * Delete code analysis blocks from test_spinner.py, test_url_validation.py
44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
import pytest
|
|
from git.exc import GitCommandError
|
|
from git.repo.base import Repo
|
|
|
|
from autogpt.agents.agent import Agent
|
|
from autogpt.agents.utils.exceptions import CommandExecutionError
|
|
from autogpt.commands.git_operations import clone_repository
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_clone_from(mocker):
|
|
return mocker.patch.object(Repo, "clone_from")
|
|
|
|
|
|
def test_clone_auto_gpt_repository(workspace, mock_clone_from, agent: Agent):
|
|
mock_clone_from.return_value = None
|
|
|
|
repo = "github.com/Significant-Gravitas/Auto-GPT.git"
|
|
scheme = "https://"
|
|
url = scheme + repo
|
|
clone_path = workspace.get_path("auto-gpt-repo")
|
|
|
|
expected_output = f"Cloned {url} to {clone_path}"
|
|
|
|
clone_result = clone_repository(url=url, clone_path=clone_path, agent=agent)
|
|
|
|
assert clone_result == expected_output
|
|
mock_clone_from.assert_called_once_with(
|
|
url=f"{scheme}{agent.legacy_config.github_username}:{agent.legacy_config.github_api_key}@{repo}", # noqa: E501
|
|
to_path=clone_path,
|
|
)
|
|
|
|
|
|
def test_clone_repository_error(workspace, mock_clone_from, agent: Agent):
|
|
url = "https://github.com/this-repository/does-not-exist.git"
|
|
clone_path = workspace.get_path("does-not-exist")
|
|
|
|
mock_clone_from.side_effect = GitCommandError(
|
|
"clone", "fatal: repository not found", ""
|
|
)
|
|
|
|
with pytest.raises(CommandExecutionError):
|
|
clone_repository(url=url, clone_path=clone_path, agent=agent)
|