- pulp_client: get_repo / sync_repo / get_task (비동기 task href 반환)
- POST /repos/{uuid}/sync: remote 확인 후 동기화 시작, 진행률 조각 반환
- GET /repos/{uuid}/progress: progress_reports 합산 → 바/퍼센트,
완료/실패 시 hx-trigger 제거로 폴링 중단
- task_store: uuid→task_href 메모리 추적 (단일 인스턴스), 대시보드 '동기화 중' 집계
- views.task_progress: state/done/total/percent + created_resources에서 새 vN
- 동기화는 안전 동작이라 확인 모달 없이 실행 (스펙 §5-1)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
64 lines
2.0 KiB
Python
64 lines
2.0 KiB
Python
import httpx
|
|
import pytest
|
|
import respx
|
|
|
|
from app.config import get_settings, tls_verify
|
|
from app.pulp_client import PulpClient
|
|
from tests.conftest import PULP_TEST_URL
|
|
|
|
|
|
def test_tls_verify_prefers_ca_file(monkeypatch):
|
|
monkeypatch.setenv("PULP_CA_FILE", "/etc/ssl/boknet-ca.pem")
|
|
monkeypatch.setenv("PULP_VERIFY_TLS", "false")
|
|
get_settings.cache_clear()
|
|
assert tls_verify(get_settings()) == "/etc/ssl/boknet-ca.pem"
|
|
|
|
|
|
def test_tls_verify_falls_back_to_bool():
|
|
# conftest: CA 비어있음, VERIFY_TLS=false
|
|
assert tls_verify(get_settings()) is False
|
|
|
|
|
|
@respx.mock
|
|
def test_status_returns_json():
|
|
route = respx.get(f"{PULP_TEST_URL}/pulp/api/v3/status/").mock(
|
|
return_value=httpx.Response(200, json={"online": True, "versions": []})
|
|
)
|
|
with PulpClient() as pulp:
|
|
data = pulp.status()
|
|
assert route.called
|
|
assert data == {"online": True, "versions": []}
|
|
|
|
|
|
@respx.mock
|
|
def test_get_raises_on_http_error():
|
|
respx.get(f"{PULP_TEST_URL}/pulp/api/v3/status/").mock(
|
|
return_value=httpx.Response(503)
|
|
)
|
|
with PulpClient() as pulp, pytest.raises(httpx.HTTPStatusError):
|
|
pulp.status()
|
|
|
|
|
|
@respx.mock
|
|
def test_sync_repo_posts_remote_and_returns_task():
|
|
import json
|
|
|
|
route = respx.post(
|
|
f"{PULP_TEST_URL}/pulp/api/v3/repositories/rpm/rpm/abc/sync/"
|
|
).mock(return_value=httpx.Response(202, json={"task": "/pulp/api/v3/tasks/t1/"}))
|
|
with PulpClient() as pulp:
|
|
href = pulp.sync_repo("abc", "/pulp/api/v3/remotes/rpm/rpm/r1/")
|
|
assert href == "/pulp/api/v3/tasks/t1/"
|
|
body = json.loads(route.calls.last.request.content)
|
|
assert body == {"remote": "/pulp/api/v3/remotes/rpm/rpm/r1/"}
|
|
|
|
|
|
@respx.mock
|
|
def test_get_task_returns_state():
|
|
respx.get(f"{PULP_TEST_URL}/pulp/api/v3/tasks/t1/").mock(
|
|
return_value=httpx.Response(200, json={"state": "running"})
|
|
)
|
|
with PulpClient() as pulp:
|
|
task = pulp.get_task("/pulp/api/v3/tasks/t1/")
|
|
assert task["state"] == "running"
|