refactor: extract focused clients from GiteaClient (Slices 1-6)
- Create gitea/issues_client.py with IssuesClient class (9 methods) - Create gitea/prs_client.py with PullRequestsClient class (17 methods) - Create gitea/files_client.py with FilesClient class (4 methods) - Create gitea/notifications_client.py with NotificationsClient class (2 methods) - Create gitea/repos_client.py with ReposClient class (2 methods) - Create gitea/__init__.py to export all client classes - Remove delegation methods from GiteaClient (now ~70 lines) - Update all callers to use sub-clients (client.issues, client.prs, etc.) - Update test files to mock sub-client attributes GiteaClient is now a facade that provides access to focused sub-clients: - repos: Repository operations (ReposClient) - issues: Issue operations (IssuesClient) - prs: Pull request operations (PullRequestsClient) - files: File and git ref operations (FilesClient) - notifications: Notification operations (NotificationsClient) Refs: #godclass-refactor
This commit is contained in:
+44
-20
@@ -11,7 +11,7 @@ def test_gitea_client_list_repo_issues() -> None:
|
||||
mock_get.return_value = mock_response
|
||||
|
||||
# Test default parameter ("open")
|
||||
client.list_repo_issues("owner", "repo")
|
||||
client.issues.list_repo_issues("owner", "repo")
|
||||
mock_get.assert_called_once()
|
||||
args, _ = mock_get.call_args
|
||||
assert "type=issues" in args[0]
|
||||
@@ -20,7 +20,7 @@ def test_gitea_client_list_repo_issues() -> None:
|
||||
mock_get.reset_mock()
|
||||
|
||||
# Test custom parameter ("closed")
|
||||
client.list_repo_issues("owner", "repo", state="closed")
|
||||
client.issues.list_repo_issues("owner", "repo", state="closed")
|
||||
mock_get.assert_called_once()
|
||||
args, _ = mock_get.call_args
|
||||
assert "type=issues" in args[0]
|
||||
@@ -36,7 +36,7 @@ def test_gitea_client_list_repo_pull_requests() -> None:
|
||||
mock_get.return_value = mock_response
|
||||
|
||||
# Test default parameter ("open")
|
||||
client.list_repo_pull_requests("owner", "repo")
|
||||
client.prs.list_repo_pull_requests("owner", "repo")
|
||||
mock_get.assert_called_once()
|
||||
args, _ = mock_get.call_args
|
||||
assert "state=open" in args[0]
|
||||
@@ -44,7 +44,7 @@ def test_gitea_client_list_repo_pull_requests() -> None:
|
||||
mock_get.reset_mock()
|
||||
|
||||
# Test custom parameter ("closed")
|
||||
client.list_repo_pull_requests("owner", "repo", state="closed")
|
||||
client.prs.list_repo_pull_requests("owner", "repo", state="closed")
|
||||
mock_get.assert_called_once()
|
||||
args, _ = mock_get.call_args
|
||||
assert "state=closed" in args[0]
|
||||
@@ -55,14 +55,17 @@ def test_gitea_client_list_assigned_issues() -> None:
|
||||
user_mock: MagicMock = MagicMock()
|
||||
user_mock.login = "testuser"
|
||||
|
||||
with patch.object(client, "get_authenticated_user", return_value=user_mock), \
|
||||
patch("httpx.Client.get") as mock_get:
|
||||
with (
|
||||
patch.object(client.repos, "get_authenticated_user", return_value=user_mock),
|
||||
patch.object(client.issues, "_get_user", return_value=user_mock),
|
||||
patch("httpx.Client.get") as mock_get,
|
||||
):
|
||||
mock_response: MagicMock = MagicMock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.json.return_value = []
|
||||
mock_get.return_value = mock_response
|
||||
|
||||
client.list_assigned_issues("owner", "repo")
|
||||
client.issues.list_assigned_issues("owner", "repo")
|
||||
mock_get.assert_called_once()
|
||||
args, _ = mock_get.call_args
|
||||
assert "type=issues" in args[0]
|
||||
@@ -74,18 +77,36 @@ def test_gitea_client_list_assigned_pull_requests() -> None:
|
||||
user_mock: MagicMock = MagicMock()
|
||||
user_mock.login = "testuser"
|
||||
|
||||
with patch.object(client, "get_authenticated_user", return_value=user_mock), \
|
||||
patch("httpx.Client.get") as mock_get:
|
||||
with (
|
||||
patch.object(client.repos, "get_authenticated_user", return_value=user_mock),
|
||||
patch.object(client.prs, "_get_user", return_value=user_mock),
|
||||
patch("httpx.Client.get") as mock_get,
|
||||
):
|
||||
mock_response: MagicMock = MagicMock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.json.return_value = [
|
||||
{"number": 1, "title": "PR 1", "assignee": {"login": "testuser"}, "user": {"login": "otheruser"}},
|
||||
{"number": 2, "title": "PR 2", "assignee": None, "user": {"login": "testuser"}},
|
||||
{"number": 3, "title": "PR 3", "assignee": {"login": "otheruser"}, "user": {"login": "otheruser"}}
|
||||
{
|
||||
"number": 1,
|
||||
"title": "PR 1",
|
||||
"assignee": {"login": "testuser"},
|
||||
"user": {"login": "otheruser"},
|
||||
},
|
||||
{
|
||||
"number": 2,
|
||||
"title": "PR 2",
|
||||
"assignee": None,
|
||||
"user": {"login": "testuser"},
|
||||
},
|
||||
{
|
||||
"number": 3,
|
||||
"title": "PR 3",
|
||||
"assignee": {"login": "otheruser"},
|
||||
"user": {"login": "otheruser"},
|
||||
},
|
||||
]
|
||||
mock_get.return_value = mock_response
|
||||
|
||||
res = client.list_assigned_pull_requests("owner", "repo")
|
||||
res = client.prs.list_assigned_pull_requests("owner", "repo")
|
||||
mock_get.assert_called_once()
|
||||
assert len(res) == 2
|
||||
numbers = [pr.number for pr in res]
|
||||
@@ -106,7 +127,7 @@ def test_gitea_client_list_unread_notifications() -> None:
|
||||
mock_get.return_value = mock_response
|
||||
|
||||
# Test without since
|
||||
res = client.list_unread_notifications()
|
||||
res = client.notifications.list_unread_notifications()
|
||||
mock_get.assert_called_once()
|
||||
_, kwargs = mock_get.call_args
|
||||
assert kwargs.get("params") == {"all": "false"}
|
||||
@@ -116,20 +137,23 @@ def test_gitea_client_list_unread_notifications() -> None:
|
||||
mock_get.reset_mock()
|
||||
|
||||
# Test with since
|
||||
res = client.list_unread_notifications(since="2026-06-30T21:41:16+02:00")
|
||||
res = client.notifications.list_unread_notifications(
|
||||
since="2026-06-30T21:41:16+02:00"
|
||||
)
|
||||
mock_get.assert_called_once()
|
||||
_, kwargs = mock_get.call_args
|
||||
assert kwargs.get("params") == {"all": "false", "since": "2026-06-30T21:41:16+02:00"}
|
||||
assert kwargs.get("params") == {
|
||||
"all": "false",
|
||||
"since": "2026-06-30T21:41:16+02:00",
|
||||
}
|
||||
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def test_gitea_client_get_authenticated_user_failure() -> None:
|
||||
client: GiteaClient = GiteaClient()
|
||||
with patch("httpx.Client.get") as mock_get:
|
||||
mock_get.side_effect = Exception("Connection error")
|
||||
with pytest.raises(RuntimeError, match="Could not get authenticated user"):
|
||||
client.get_authenticated_user()
|
||||
|
||||
|
||||
|
||||
client.repos.get_authenticated_user()
|
||||
|
||||
Reference in New Issue
Block a user