fix 5.4: return structured types from get_issue/get_pull_request/create_pull_request/update_pull_request
- IssueTools.get_issue now returns IssueModel instead of JSON string - PRTools.get_pull_request now returns PullRequestModel instead of JSON string - PRTools.create_pull_request now returns PullRequestModel instead of JSON string - PRTools.update_pull_request now returns PullRequestModel instead of JSON string - All methods have proper return type hints and raise exceptions on error - Updated tests to verify model objects are returned directly - Marked issue 5.4 as resolved in bad_code.md
This commit is contained in:
@@ -20,11 +20,11 @@ def test_get_issue_success() -> None:
|
||||
mock_client.issues.get_issue.return_value = issue
|
||||
|
||||
issue_tools: IssueTools = IssueTools(mock_client)
|
||||
res: str = issue_tools.get_issue("owner", "repo", 1)
|
||||
res: IssueModel = issue_tools.get_issue("owner", "repo", 1)
|
||||
|
||||
data: dict[str, Any] = json.loads(res)
|
||||
assert data["number"] == 1
|
||||
assert data["title"] == "Test Issue"
|
||||
assert isinstance(res, IssueModel)
|
||||
assert res.number == 1
|
||||
assert res.title == "Test Issue"
|
||||
mock_client.issues.get_issue.assert_called_once_with("owner", "repo", 1)
|
||||
|
||||
|
||||
@@ -33,8 +33,11 @@ def test_get_issue_failure() -> None:
|
||||
mock_client.issues.get_issue.side_effect = Exception("API Error")
|
||||
|
||||
issue_tools: IssueTools = IssueTools(mock_client)
|
||||
res: str = issue_tools.get_issue("owner", "repo", 1)
|
||||
assert "Error getting issue: API Error" in res
|
||||
try:
|
||||
issue_tools.get_issue("owner", "repo", 1)
|
||||
assert False, "Expected Exception"
|
||||
except Exception as e:
|
||||
assert str(e) == "API Error"
|
||||
|
||||
|
||||
def test_close_issue_success() -> None:
|
||||
|
||||
Reference in New Issue
Block a user