From 54ca73f630816ff6afa1a334fff9d5438474059c Mon Sep 17 00:00:00 2001 From: Jenn Mueng <30991498+jennmueng@users.noreply.github.com> Date: Thu, 10 Oct 2024 14:58:07 -0700 Subject: [PATCH 1/2] Add unit tests for AutofixContext.get_repo_client with RepoClientType --- tests/automation/autofix/test_autofix_context.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/automation/autofix/test_autofix_context.py b/tests/automation/autofix/test_autofix_context.py index 5d8e38665..31e1ab9fb 100644 --- a/tests/automation/autofix/test_autofix_context.py +++ b/tests/automation/autofix/test_autofix_context.py @@ -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, From d3d5985d8267cd3783dc049be37a110377ddf44e Mon Sep 17 00:00:00 2001 From: Jenn Mueng <30991498+jennmueng@users.noreply.github.com> Date: Thu, 10 Oct 2024 14:58:09 -0700 Subject: [PATCH 2/2] Add unit tests for AutofixContext.get_repo_client with RepoClientType --- .../autofix/test_autofix_context.py | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tests/automation/autofix/test_autofix_context.py b/tests/automation/autofix/test_autofix_context.py index 31e1ab9fb..75300b834 100644 --- a/tests/automation/autofix/test_autofix_context.py +++ b/tests/automation/autofix/test_autofix_context.py @@ -265,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):