test: add edge case tests for unicode, empty repos, malformed API
Add tests for unicode descriptions, repos with no commits and no release, malformed JSON responses, HTML responses, control characters in names, empty and very long descriptions. fixes #13 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -287,6 +287,41 @@ class TestGetWithRetry429:
|
||||
assert mock_sleep.call_count == 2
|
||||
|
||||
|
||||
class TestGetPaginatedEdgeCases:
|
||||
"""Test edge cases for API responses."""
|
||||
|
||||
def _make_client(self):
|
||||
return GiteaClient("http://gitea.local:3000", "tok")
|
||||
|
||||
def test_get_paginated_malformed_json(self):
|
||||
"""Response with invalid JSON raises JSONDecodeError."""
|
||||
import json
|
||||
|
||||
client = self._make_client()
|
||||
mock_resp = MagicMock()
|
||||
mock_resp.raise_for_status = MagicMock()
|
||||
mock_resp.json.side_effect = json.JSONDecodeError("Expecting value", "", 0)
|
||||
|
||||
with patch.object(client.session, "get", return_value=mock_resp):
|
||||
with pytest.raises(json.JSONDecodeError):
|
||||
client._get_paginated("/api/v1/user/repos")
|
||||
|
||||
def test_get_repos_html_response(self):
|
||||
"""HTML response (status 200 but HTML content) raises on json parsing."""
|
||||
import json
|
||||
|
||||
client = self._make_client()
|
||||
mock_resp = MagicMock()
|
||||
mock_resp.raise_for_status = MagicMock()
|
||||
mock_resp.json.side_effect = json.JSONDecodeError(
|
||||
"Expecting value", "<html>Maintenance</html>", 0
|
||||
)
|
||||
|
||||
with patch.object(client.session, "get", return_value=mock_resp):
|
||||
with pytest.raises(json.JSONDecodeError):
|
||||
client.get_repos()
|
||||
|
||||
|
||||
class TestGetLatestCommit:
|
||||
"""Test get_latest_commit method."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user