forked from Significant-Gravitas/AutoGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added tests for clone_repository (Significant-Gravitas#3558)
Co-authored-by: Nicholas Tindle <[email protected]> Co-authored-by: Richard Beales <[email protected]>
- Loading branch information
1 parent
dd96d98
commit aab79fd
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,42 @@ | ||
import pytest | ||
from git.exc import GitCommandError | ||
from git.repo.base import Repo | ||
|
||
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, config): | ||
mock_clone_from.return_value = None | ||
|
||
repo = "github.com/Significant-Gravitas/Auto-GPT.git" | ||
scheme = "https://" | ||
url = scheme + repo | ||
clone_path = str(workspace.get_path("auto-gpt-repo")) | ||
|
||
expected_output = f"Cloned {url} to {clone_path}" | ||
|
||
clone_result = clone_repository(url=url, clone_path=clone_path) | ||
|
||
assert clone_result == expected_output | ||
mock_clone_from.assert_called_once_with( | ||
url=f"{scheme}{config.github_username}:{config.github_api_key}@{repo}", | ||
to_path=clone_path, | ||
) | ||
|
||
|
||
def test_clone_repository_error(workspace, mock_clone_from): | ||
url = "https://github.com/this-repository/does-not-exist.git" | ||
clone_path = str(workspace.get_path("does-not-exist")) | ||
|
||
mock_clone_from.side_effect = GitCommandError( | ||
"clone", "fatal: repository not found", "" | ||
) | ||
|
||
result = clone_repository(url=url, clone_path=clone_path) | ||
|
||
assert "Error: " in result |