chore: commit remaining workspace changes
This commit is contained in:
67
backend/tests/core/test_git_service_gitea_pr.py
Normal file
67
backend/tests/core/test_git_service_gitea_pr.py
Normal file
@@ -0,0 +1,67 @@
|
||||
# [DEF:backend.tests.core.test_git_service_gitea_pr:Module]
|
||||
# @TIER: STANDARD
|
||||
# @SEMANTICS: tests, git, gitea, pull_request, fallback
|
||||
# @PURPOSE: Validate Gitea PR creation fallback behavior when configured server URL is stale.
|
||||
# @LAYER: Domain
|
||||
# @RELATION: TESTS -> backend.src.services.git_service.create_gitea_pull_request
|
||||
# @INVARIANT: A 404 from primary Gitea URL retries once against remote-url host when different.
|
||||
|
||||
import asyncio
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import HTTPException
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
|
||||
|
||||
from src.services.git_service import GitService
|
||||
|
||||
|
||||
# [DEF:test_derive_server_url_from_remote_strips_credentials:Function]
|
||||
# @PURPOSE: Ensure helper returns host base URL and removes embedded credentials.
|
||||
# @PRE: remote_url is an https URL with username/token.
|
||||
# @POST: Result is scheme+host only.
|
||||
def test_derive_server_url_from_remote_strips_credentials():
|
||||
service = GitService(base_path="test_repos")
|
||||
derived = service._derive_server_url_from_remote(
|
||||
"https://oauth2:token@giteabusya.bebesh.ru/busya/covid-vaccine-dashboard.git"
|
||||
)
|
||||
assert derived == "https://giteabusya.bebesh.ru"
|
||||
# [/DEF:test_derive_server_url_from_remote_strips_credentials:Function]
|
||||
|
||||
|
||||
# [DEF:test_create_gitea_pull_request_retries_with_remote_host_on_404:Function]
|
||||
# @PURPOSE: Verify create_gitea_pull_request retries with remote URL host after primary 404.
|
||||
# @PRE: primary server_url differs from remote_url host.
|
||||
# @POST: Method returns success payload from fallback request.
|
||||
def test_create_gitea_pull_request_retries_with_remote_host_on_404(monkeypatch):
|
||||
service = GitService(base_path="test_repos")
|
||||
calls = []
|
||||
|
||||
async def fake_gitea_request(method, server_url, pat, endpoint, payload=None):
|
||||
calls.append((method, server_url, endpoint))
|
||||
if len(calls) == 1:
|
||||
raise HTTPException(status_code=404, detail="Gitea API error: The target couldn't be found.")
|
||||
return {"number": 42, "html_url": "https://giteabusya.bebesh.ru/busya/covid-vaccine-dashboard/pulls/42", "state": "open"}
|
||||
|
||||
monkeypatch.setattr(service, "_gitea_request", fake_gitea_request)
|
||||
|
||||
result = asyncio.run(
|
||||
service.create_gitea_pull_request(
|
||||
server_url="https://gitea.bebesh.ru",
|
||||
pat="secret",
|
||||
remote_url="https://oauth2:secret@giteabusya.bebesh.ru/busya/covid-vaccine-dashboard.git",
|
||||
from_branch="ss-dev",
|
||||
to_branch="main",
|
||||
title="Promote ss-dev -> main",
|
||||
description="",
|
||||
)
|
||||
)
|
||||
|
||||
assert result["id"] == 42
|
||||
assert len(calls) == 2
|
||||
assert calls[0][1] == "https://gitea.bebesh.ru"
|
||||
assert calls[1][1] == "https://giteabusya.bebesh.ru"
|
||||
# [/DEF:test_create_gitea_pull_request_retries_with_remote_host_on_404:Function]
|
||||
|
||||
# [/DEF:backend.tests.core.test_git_service_gitea_pr:Module]
|
||||
Reference in New Issue
Block a user