Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tests for PR#1266 #1269

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions tests/automation/autofix/test_autofix_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
CodebaseState,
StepType,
)
from seer.automation.codebase.repo_client import RepoClientType
from seer.automation.autofix.state import ContinuationState
from seer.automation.models import (
EventDetails,
Expand Down Expand Up @@ -264,6 +265,56 @@ def test_store_multiple_keys(self):
self.assertEqual(result2[0].role, "assistant")
self.assertEqual(result2[0].content, "Test message 2")

@patch("seer.automation.autofix.autofix_context.RepoClient")
@patch("seer.automation.autofix.autofix_context.get_read_app_credentials")
@patch("seer.automation.autofix.autofix_context.get_write_app_credentials")
@patch("seer.automation.autofix.autofix_context.get_codecov_unit_test_app_credentials")
def test_get_repo_client_with_different_types(
self,
mock_get_codecov_unit_test_app_credentials,
mock_get_write_app_credentials,
mock_get_read_app_credentials,
mock_RepoClient,
):
instance = self.autofix_context
mock_repo = MagicMock()
instance.repos = [mock_repo]

mock_get_read_app_credentials.return_value = ("read_app_id", "read_private_key")
mock_get_write_app_credentials.return_value = ("write_app_id", "write_private_key")
mock_get_codecov_unit_test_app_credentials.return_value = ("codecov_app_id", "codecov_private_key")

# Test READ type
instance.get_repo_client(type=RepoClientType.READ)
mock_RepoClient.from_repo_definition.assert_called_with(mock_repo, RepoClientType.READ)
mock_get_read_app_credentials.assert_called_once()

# Reset mock calls
mock_RepoClient.from_repo_definition.reset_mock()
mock_get_read_app_credentials.reset_mock()

# Test WRITE type
instance.get_repo_client(type=RepoClientType.WRITE)
mock_RepoClient.from_repo_definition.assert_called_with(mock_repo, RepoClientType.WRITE)
mock_get_write_app_credentials.assert_called_once()

# Reset mock calls
mock_RepoClient.from_repo_definition.reset_mock()
mock_get_write_app_credentials.reset_mock()

# Test CODECOV_UNIT_TEST type
instance.get_repo_client(type=RepoClientType.CODECOV_UNIT_TEST)
mock_RepoClient.from_repo_definition.assert_called_with(mock_repo, RepoClientType.CODECOV_UNIT_TEST)
mock_get_codecov_unit_test_app_credentials.assert_called_once()

@patch("seer.automation.autofix.autofix_context.RepoClient")
def test_get_repo_client_with_repo_name(self, mock_RepoClient):
instance = self.autofix_context
instance.repos = [MagicMock(full_name="repo1"), MagicMock(full_name="repo2")]

instance.get_repo_client(repo_name="repo2", type=RepoClientType.READ)
mock_RepoClient.from_repo_definition.assert_called_with(instance.repos[1], RepoClientType.READ)


class TestAutofixContextPrCommit(unittest.TestCase):
def setUp(self):
Expand Down
Loading