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 #1271

Draft
wants to merge 3 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
65 changes: 63 additions & 2 deletions tests/automation/codebase/test_repo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
from github import UnknownObjectException
from pydantic import ValidationError

from seer.automation.codebase.repo_client import RepoClient
from seer.automation.codebase.repo_client import RepoClient, RepoClientType
from seer.automation.models import RepoDefinition




@pytest.fixture
def mock_github():
with patch("seer.automation.codebase.repo_client.Github") as mock:
Expand Down Expand Up @@ -39,6 +41,39 @@ def repo_client(mock_github, mock_get_github_auth, repo_definition):
return RepoClient.from_repo_definition(repo_definition, "read")


@pytest.fixture
def mock_get_codecov_unit_test_app_credentials():
with patch("seer.automation.codebase.repo_client.get_codecov_unit_test_app_credentials") as mock:
yield mock


class TestRepoClientType:
def test_repo_client_type_values(self):
assert RepoClientType.READ == "read"
assert RepoClientType.WRITE == "write"
assert RepoClientType.CODECOV_UNIT_TEST == "codecov_unit_test"

def test_repo_client_from_repo_definition_read(self, mock_github, mock_get_github_auth, repo_definition):
with patch("seer.automation.codebase.repo_client.get_read_app_credentials") as mock_read_creds:
mock_read_creds.return_value = (1, "read_key")
client = RepoClient.from_repo_definition(repo_definition, RepoClientType.READ)
assert isinstance(client, RepoClient)
mock_read_creds.assert_called_once()

def test_repo_client_from_repo_definition_write(self, mock_github, mock_get_github_auth, repo_definition):
with patch("seer.automation.codebase.repo_client.get_write_app_credentials") as mock_write_creds:
mock_write_creds.return_value = (2, "write_key")
client = RepoClient.from_repo_definition(repo_definition, RepoClientType.WRITE)
assert isinstance(client, RepoClient)
mock_write_creds.assert_called_once()

def test_repo_client_from_repo_definition_codecov_unit_test(self, mock_github, mock_get_github_auth, repo_definition, mock_get_codecov_unit_test_app_credentials):
mock_get_codecov_unit_test_app_credentials.return_value = (3, "codecov_key")
client = RepoClient.from_repo_definition(repo_definition, RepoClientType.CODECOV_UNIT_TEST)
assert isinstance(client, RepoClient)
mock_get_codecov_unit_test_app_credentials.assert_called_once()


class TestRepoClient:

def test_repo_client_initialization(self, repo_client):
Expand Down Expand Up @@ -283,7 +318,33 @@ def test_all_files_included(self, get_github_app_auth_and_installation, mock_Git
RepoDefinition(provider="github", owner="getsentry", name="seer", external_id="123"),
)
result = client.get_index_file_set("main")
assert result == {"file1.py", "file2.py"}
assert result == {"file1.py"}


@patch("seer.automation.codebase.repo_client.AppConfig")
def test_get_codecov_unit_test_app_credentials(mock_app_config):
mock_config = MagicMock()
mock_config.GITHUB_CODECOV_UNIT_TEST_APP_ID = "test_app_id"
mock_config.GITHUB_CODECOV_UNIT_TEST_PRIVATE_KEY = "test_private_key"
mock_app_config.return_value = mock_config

app_id, private_key = get_codecov_unit_test_app_credentials()
assert app_id == "test_app_id"
assert private_key == "test_private_key"

@patch("seer.automation.codebase.repo_client.AppConfig")
def test_get_codecov_unit_test_app_credentials_fallback(mock_app_config):
mock_config = MagicMock()
mock_config.GITHUB_CODECOV_UNIT_TEST_APP_ID = None
mock_config.GITHUB_CODECOV_UNIT_TEST_PRIVATE_KEY = None
mock_app_config.return_value = mock_config

with patch("seer.automation.codebase.repo_client.get_write_app_credentials") as mock_get_write_creds:
mock_get_write_creds.return_value = ("fallback_app_id", "fallback_private_key")
app_id, private_key = get_codecov_unit_test_app_credentials()
assert app_id == "fallback_app_id"
assert private_key == "fallback_private_key"
mock_get_write_creds.assert_called_once()

@patch("seer.automation.codebase.repo_client.Github")
@patch(
Expand Down
Loading