Fix commit roto 3
Browse files- .github/workflows/ci.yml +1 -2
- app/config.py +2 -3
- app/dependencies.py +12 -5
- tests/conftest.py +4 -3
- tests/test_camas.py +1 -1
.github/workflows/ci.yml
CHANGED
|
@@ -27,8 +27,7 @@ jobs:
|
|
| 27 |
name: Tests (pytest)
|
| 28 |
runs-on: ubuntu-latest
|
| 29 |
env:
|
| 30 |
-
|
| 31 |
-
SUPABASE_KEY: mock-key-for-testing-only
|
| 32 |
JWT_SECRET: ci-test-secret-key-not-used-in-production-32chars
|
| 33 |
ENVIRONMENT: development
|
| 34 |
MOCK_EXTERNAL_SERVICES: "true"
|
|
|
|
| 27 |
name: Tests (pytest)
|
| 28 |
runs-on: ubuntu-latest
|
| 29 |
env:
|
| 30 |
+
DATABASE_URL: postgresql://mock:mock@localhost:5432/mock
|
|
|
|
| 31 |
JWT_SECRET: ci-test-secret-key-not-used-in-production-32chars
|
| 32 |
ENVIRONMENT: development
|
| 33 |
MOCK_EXTERNAL_SERVICES: "true"
|
app/config.py
CHANGED
|
@@ -8,9 +8,8 @@ class Settings(BaseSettings):
|
|
| 8 |
extra="ignore",
|
| 9 |
)
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
supabase_key: str
|
| 14 |
|
| 15 |
# JWT β sin default para evitar secretos hardcodeados en cΓ³digo fuente
|
| 16 |
jwt_secret: str
|
|
|
|
| 8 |
extra="ignore",
|
| 9 |
)
|
| 10 |
|
| 11 |
+
# Base de datos
|
| 12 |
+
database_url: str
|
|
|
|
| 13 |
|
| 14 |
# JWT β sin default para evitar secretos hardcodeados en cΓ³digo fuente
|
| 15 |
jwt_secret: str
|
app/dependencies.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
"""
|
| 2 |
-
Dependencias compartidas de FastAPI: BD (
|
| 3 |
"""
|
| 4 |
import logging
|
| 5 |
from datetime import datetime, timedelta, timezone
|
|
@@ -7,7 +7,8 @@ from datetime import datetime, timedelta, timezone
|
|
| 7 |
from fastapi import Depends, HTTPException, status
|
| 8 |
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
| 9 |
from jose import JWTError, jwt
|
| 10 |
-
from
|
|
|
|
| 11 |
|
| 12 |
from app.config import settings
|
| 13 |
|
|
@@ -15,11 +16,17 @@ logger = logging.getLogger(__name__)
|
|
| 15 |
|
| 16 |
# βββ Base de datos βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
| 19 |
|
| 20 |
|
| 21 |
-
def get_db()
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
# βββ JWT βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 1 |
"""
|
| 2 |
+
Dependencias compartidas de FastAPI: BD (SQLAlchemy), JWT y autenticaciΓ³n.
|
| 3 |
"""
|
| 4 |
import logging
|
| 5 |
from datetime import datetime, timedelta, timezone
|
|
|
|
| 7 |
from fastapi import Depends, HTTPException, status
|
| 8 |
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
| 9 |
from jose import JWTError, jwt
|
| 10 |
+
from sqlalchemy import create_engine
|
| 11 |
+
from sqlalchemy.orm import declarative_base, sessionmaker, Session
|
| 12 |
|
| 13 |
from app.config import settings
|
| 14 |
|
|
|
|
| 16 |
|
| 17 |
# βββ Base de datos βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 18 |
|
| 19 |
+
engine = create_engine(settings.database_url)
|
| 20 |
+
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
| 21 |
+
Base = declarative_base()
|
| 22 |
|
| 23 |
|
| 24 |
+
def get_db():
|
| 25 |
+
db = SessionLocal()
|
| 26 |
+
try:
|
| 27 |
+
yield db
|
| 28 |
+
finally:
|
| 29 |
+
db.close()
|
| 30 |
|
| 31 |
|
| 32 |
# βββ JWT βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
tests/conftest.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
Fixtures compartidas para los tests de MΓ³dulo 6.
|
| 3 |
"""
|
| 4 |
import pytest
|
| 5 |
-
from unittest.mock import MagicMock
|
| 6 |
from fastapi.testclient import TestClient
|
| 7 |
|
| 8 |
from app.main import app
|
|
@@ -16,8 +16,9 @@ def override_get_db():
|
|
| 16 |
@pytest.fixture
|
| 17 |
def client():
|
| 18 |
app.dependency_overrides[get_db] = override_get_db
|
| 19 |
-
with
|
| 20 |
-
|
|
|
|
| 21 |
app.dependency_overrides.clear()
|
| 22 |
|
| 23 |
|
|
|
|
| 2 |
Fixtures compartidas para los tests de MΓ³dulo 6.
|
| 3 |
"""
|
| 4 |
import pytest
|
| 5 |
+
from unittest.mock import MagicMock, patch
|
| 6 |
from fastapi.testclient import TestClient
|
| 7 |
|
| 8 |
from app.main import app
|
|
|
|
| 16 |
@pytest.fixture
|
| 17 |
def client():
|
| 18 |
app.dependency_overrides[get_db] = override_get_db
|
| 19 |
+
with patch("app.main.Base.metadata.create_all"):
|
| 20 |
+
with TestClient(app) as c:
|
| 21 |
+
yield c
|
| 22 |
app.dependency_overrides.clear()
|
| 23 |
|
| 24 |
|
tests/test_camas.py
CHANGED
|
@@ -14,7 +14,7 @@ def test_get_camas_sin_auth(client: TestClient):
|
|
| 14 |
@pytest.mark.skip(reason="Requiere configurar token de test")
|
| 15 |
def test_crear_cama(client: TestClient):
|
| 16 |
payload = {
|
| 17 |
-
"numero":
|
| 18 |
"piso": 1,
|
| 19 |
"sector": "SALA_COMUN",
|
| 20 |
"tipo": "ESTANDAR",
|
|
|
|
| 14 |
@pytest.mark.skip(reason="Requiere configurar token de test")
|
| 15 |
def test_crear_cama(client: TestClient):
|
| 16 |
payload = {
|
| 17 |
+
"numero": 101,
|
| 18 |
"piso": 1,
|
| 19 |
"sector": "SALA_COMUN",
|
| 20 |
"tipo": "ESTANDAR",
|