fix: Update CI workflow to configure APT proxy and improve currency workflow tests
Some checks failed
Run Tests / test (push) Failing after 2m5s
Some checks failed
Run Tests / test (push) Failing after 2m5s
This commit is contained in:
@@ -25,6 +25,22 @@ jobs:
|
|||||||
uses: actions/setup-python@v5
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: "3.10"
|
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
|
# - name: Cache pip
|
||||||
# uses: actions/cache@v4
|
# uses: actions/cache@v4
|
||||||
# with:
|
# with:
|
||||||
|
|||||||
@@ -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():
|
@pytest.fixture
|
||||||
# create scenario first (reuse helper from other tests)
|
def seeded_currency(db_session):
|
||||||
from tests.unit.test_costs import _create_scenario
|
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 = {
|
payload = {
|
||||||
"scenario_id": sid,
|
"scenario_id": sid,
|
||||||
"amount": 500.0,
|
"amount": 500.0,
|
||||||
"description": "Capex with GBP",
|
"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
|
assert resp.status_code == 200
|
||||||
data = resp.json()
|
data = resp.json()
|
||||||
assert data["currency_code"] == "GBP" or data.get(
|
assert data.get("currency_code") == seeded_currency.code or data.get(
|
||||||
"currency", {}).get("code") == "GBP"
|
"currency", {}
|
||||||
|
).get("code") == seeded_currency.code
|
||||||
|
|
||||||
|
|
||||||
def test_create_opex_with_currency_id():
|
def test_create_opex_with_currency_id(api_client, seeded_currency):
|
||||||
from tests.unit.test_costs import _create_scenario
|
sid = _create_scenario(api_client)
|
||||||
from routes.currencies import list_currencies
|
|
||||||
|
|
||||||
sid = _create_scenario()
|
resp = api_client.get("/api/currencies/")
|
||||||
|
|
||||||
# fetch currencies to get an id
|
|
||||||
resp = client.get("/api/currencies/")
|
|
||||||
assert resp.status_code == 200
|
assert resp.status_code == 200
|
||||||
currencies = resp.json()
|
currencies = resp.json()
|
||||||
assert len(currencies) > 0
|
assert any(c["id"] == seeded_currency.id for c in currencies)
|
||||||
cid = currencies[0]["id"]
|
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
"scenario_id": sid,
|
"scenario_id": sid,
|
||||||
"amount": 120.0,
|
"amount": 120.0,
|
||||||
"description": "Opex with explicit id",
|
"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
|
assert resp.status_code == 200
|
||||||
data = resp.json()
|
data = resp.json()
|
||||||
assert data["currency_id"] == cid
|
assert data["currency_id"] == seeded_currency.id
|
||||||
|
|
||||||
|
|
||||||
def test_list_currencies_endpoint():
|
def test_list_currencies_endpoint(api_client, seeded_currency):
|
||||||
resp = client.get("/api/currencies/")
|
resp = api_client.get("/api/currencies/")
|
||||||
assert resp.status_code == 200
|
assert resp.status_code == 200
|
||||||
data = resp.json()
|
data = resp.json()
|
||||||
assert isinstance(data, list)
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user