Files
stack/tests/api/test_gitea_client_base.py
kert ccae75c805 fix(api): Gitea client falls back to the public URL off the compose net
GiteaClient defaulted to cfg.services.git (http://git:3000), which only
resolves inside the compose network. The host-side bib-refresh-iom
timer's IOM alert step died on it every night (and before Nov 11 it was
also writing a worktree's bib). Use GITEA_API_URL when set, the
internal service when its name resolves, else https://git.<domain>.
2026-11-11 13:19:30 -05:00

39 lines
1.2 KiB
Python

"""GiteaClient picks an API base that resolves where it runs."""
from __future__ import annotations
import socket
import pytest
from api.clients.gitea.client import GiteaClient
@pytest.fixture(autouse=True)
def _no_env(monkeypatch):
monkeypatch.delenv("GITEA_API_URL", raising=False)
def test_inside_compose_uses_the_internal_service(monkeypatch):
monkeypatch.setattr(socket, "getaddrinfo", lambda *a, **k: [("ok",)])
assert GiteaClient("t").base_url == "http://git:3000/api/v1"
def test_on_the_host_falls_back_to_the_public_url(monkeypatch):
# The nightly bib-refresh-iom timer runs on the host, where the
# compose name "git" does not resolve; it failed every night.
def nxdomain(*a, **k):
raise socket.gaierror(-2, "Name or service not known")
monkeypatch.setattr(socket, "getaddrinfo", nxdomain)
assert GiteaClient("t").base_url == "https://git.fhirworx.io/api/v1"
def test_env_override_wins(monkeypatch):
monkeypatch.setenv("GITEA_API_URL", "https://example.test/api/v1/")
assert GiteaClient("t").base_url == "https://example.test/api/v1"
def test_explicit_base_url_is_untouched():
assert GiteaClient("t", base_url="http://x/api/v1").base_url == "http://x/api/v1"