fix: Update CI workflow to configure APT proxy and improve currency workflow tests
Some checks failed
Run Tests / test (push) Failing after 2m5s

This commit is contained in:
2025-10-25 16:34:10 +02:00
parent 2182f723f7
commit d455320eea
2 changed files with 61 additions and 25 deletions

View File

@@ -25,6 +25,22 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Configure apt proxy
run: |
set -euo pipefail
PROXY_HOST="http://apt-cacher:3142"
if ! curl -fsS --connect-timeout 3 "${PROXY_HOST}" >/dev/null; then
PROXY_HOST="http://192.168.88.14:3142"
fi
echo "Using APT proxy ${PROXY_HOST}"
echo "http_proxy=${PROXY_HOST}" >> "$GITHUB_ENV"
echo "https_proxy=${PROXY_HOST}" >> "$GITHUB_ENV"
echo "HTTP_PROXY=${PROXY_HOST}" >> "$GITHUB_ENV"
echo "HTTPS_PROXY=${PROXY_HOST}" >> "$GITHUB_ENV"
sudo tee /etc/apt/apt.conf.d/01proxy >/dev/null <<EOF
Acquire::http::Proxy "${PROXY_HOST}";
Acquire::https::Proxy "${PROXY_HOST}";
EOF
# - name: Cache pip
# uses: actions/cache@v4
# with:

View File

@@ -1,54 +1,74 @@
from tests.unit.test_costs import client
from uuid import uuid4
import pytest
from models.currency import Currency
def test_create_capex_with_currency_code_and_list():
# create scenario first (reuse helper from other tests)
from tests.unit.test_costs import _create_scenario
@pytest.fixture
def seeded_currency(db_session):
currency = Currency(code="GBP", name="British Pound", symbol="GBP")
db_session.add(currency)
db_session.commit()
db_session.refresh(currency)
sid = _create_scenario()
try:
yield currency
finally:
db_session.delete(currency)
db_session.commit()
def _create_scenario(api_client):
payload = {
"name": f"CurrencyScenario-{uuid4()}",
"description": "Currency workflow scenario",
}
resp = api_client.post("/api/scenarios/", json=payload)
assert resp.status_code == 200
return resp.json()["id"]
def test_create_capex_with_currency_code_and_list(api_client, seeded_currency):
sid = _create_scenario(api_client)
# create with currency_code
payload = {
"scenario_id": sid,
"amount": 500.0,
"description": "Capex with GBP",
"currency_code": "GBP",
"currency_code": seeded_currency.code,
}
resp = client.post("/api/costs/capex", json=payload)
resp = api_client.post("/api/costs/capex", json=payload)
assert resp.status_code == 200
data = resp.json()
assert data["currency_code"] == "GBP" or data.get(
"currency", {}).get("code") == "GBP"
assert data.get("currency_code") == seeded_currency.code or data.get(
"currency", {}
).get("code") == seeded_currency.code
def test_create_opex_with_currency_id():
from tests.unit.test_costs import _create_scenario
from routes.currencies import list_currencies
def test_create_opex_with_currency_id(api_client, seeded_currency):
sid = _create_scenario(api_client)
sid = _create_scenario()
# fetch currencies to get an id
resp = client.get("/api/currencies/")
resp = api_client.get("/api/currencies/")
assert resp.status_code == 200
currencies = resp.json()
assert len(currencies) > 0
cid = currencies[0]["id"]
assert any(c["id"] == seeded_currency.id for c in currencies)
payload = {
"scenario_id": sid,
"amount": 120.0,
"description": "Opex with explicit id",
"currency_id": cid,
"currency_id": seeded_currency.id,
}
resp = client.post("/api/costs/opex", json=payload)
resp = api_client.post("/api/costs/opex", json=payload)
assert resp.status_code == 200
data = resp.json()
assert data["currency_id"] == cid
assert data["currency_id"] == seeded_currency.id
def test_list_currencies_endpoint():
resp = client.get("/api/currencies/")
def test_list_currencies_endpoint(api_client, seeded_currency):
resp = api_client.get("/api/currencies/")
assert resp.status_code == 200
data = resp.json()
assert isinstance(data, list)
assert all("id" in c and "code" in c for c in data)
assert any(c["id"] == seeded_currency.id for c in data)