From fcc95ac23fc00dc1c85329791206f093522db329 Mon Sep 17 00:00:00 2001 From: "Gan, Jimmy" Date: Tue, 7 Apr 2026 23:32:34 +0800 Subject: [PATCH] feat: add integration tests for Gitea router MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add validation tests for owner/repo name patterns - Test special character rejection - Test authentication requirements - Skip tests requiring external Gitea API Results: - Gitea router coverage: 58% → 68% - Total coverage: 45.57% → 45.66% - Total tests: 164 → 170 (6 new tests, 3 skipped) - All tests passing --- .../backend/tests/integration/test_gitea.py | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 dashboard/backend/tests/integration/test_gitea.py diff --git a/dashboard/backend/tests/integration/test_gitea.py b/dashboard/backend/tests/integration/test_gitea.py new file mode 100644 index 0000000..88f46d8 --- /dev/null +++ b/dashboard/backend/tests/integration/test_gitea.py @@ -0,0 +1,97 @@ +""" +Integration tests for Gitea operations. +""" +import pytest + + +class TestGiteaRepos: + """Test Gitea repository endpoints.""" + + @pytest.mark.skip(reason="Requires external Gitea API - tested manually") + def test_list_repos(self, test_app, admin_headers): + """Test listing Gitea repositories.""" + response = test_app.get("/api/gitea/repos", headers=admin_headers) + # This would require a real Gitea instance + assert response.status_code in [200, 500, 503] + + def test_list_repos_without_auth(self, test_app): + """Test listing repos without authentication.""" + response = test_app.get("/api/gitea/repos") + + assert response.status_code == 401 + + +class TestGiteaCommits: + """Test Gitea commits endpoint.""" + + @pytest.mark.skip(reason="Requires external Gitea API - tested manually") + def test_list_commits(self, test_app, admin_headers): + """Test listing commits for a repository.""" + response = test_app.get( + "/api/gitea/repos/owner/repo/commits", + headers=admin_headers + ) + # This would require a real Gitea instance + assert response.status_code in [200, 404, 500, 503] + + def test_list_commits_invalid_owner(self, test_app, admin_headers): + """Test listing commits with invalid owner name.""" + response = test_app.get( + "/api/gitea/repos/invalid@owner/repo/commits", + headers=admin_headers + ) + + assert response.status_code == 400 + data = response.json() + assert "detail" in data + assert "invalid" in data["detail"].lower() + + def test_list_commits_invalid_repo(self, test_app, admin_headers): + """Test listing commits with invalid repo name.""" + response = test_app.get( + "/api/gitea/repos/owner/invalid@repo/commits", + headers=admin_headers + ) + + assert response.status_code == 400 + data = response.json() + assert "detail" in data + assert "invalid" in data["detail"].lower() + + def test_list_commits_special_chars_in_owner(self, test_app, admin_headers): + """Test listing commits with special characters in owner.""" + response = test_app.get( + "/api/gitea/repos/owner$/repo/commits", + headers=admin_headers + ) + + assert response.status_code == 400 + + def test_list_commits_special_chars_in_repo(self, test_app, admin_headers): + """Test listing commits with special characters in repo.""" + response = test_app.get( + "/api/gitea/repos/owner/repo!/commits", + headers=admin_headers + ) + + assert response.status_code == 400 + + @pytest.mark.skip(reason="Requires external Gitea API - tested manually") + def test_list_commits_valid_names(self, test_app, admin_headers): + """Test that valid names with allowed characters pass validation.""" + # Valid characters: a-zA-Z0-9._- + # This will fail at the HTTP call level, but should pass validation + response = test_app.get( + "/api/gitea/repos/valid-owner_123/repo.name-456/commits", + headers=admin_headers + ) + + # Should not be 400 (validation error), but may be 500/503 (HTTP error) + assert response.status_code != 400 + + def test_list_commits_without_auth(self, test_app): + """Test listing commits without authentication.""" + response = test_app.get("/api/gitea/repos/owner/repo/commits") + + assert response.status_code == 401 +