File size: 1,055 Bytes
5f12c93
 
2c5d6e7
 
 
 
5f12c93
 
2c5d6e7
5f12c93
 
 
2c5d6e7
5f12c93
 
2c5d6e7
 
9223feb
5f12c93
 
 
2c5d6e7
 
 
 
5f12c93
9223feb
 
2c5d6e7
 
 
 
 
9223feb
2c5d6e7
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
Fixtures compartidas para los tests de Módulo 6.

La base se reemplaza por un MagicMock (los tests mockean la capa CRUD, no la DB
real). La autenticación usa tokens JWT reales generados con la misma clave que
valida la app, así se ejercita el flujo de seguridad de verdad.
"""
import pytest
from unittest.mock import MagicMock
from fastapi.testclient import TestClient

from app.main import app
from app.dependencies import get_db, create_access_token


@pytest.fixture
def db():
    return MagicMock()


@pytest.fixture
def client(db):
    app.dependency_overrides[get_db] = lambda: db
    with TestClient(app) as c:
        yield c
    app.dependency_overrides.clear()


def _headers(rol: str) -> dict:
    token = create_access_token(sub="1", rol=rol)
    return {"Authorization": f"Bearer {token}"}


@pytest.fixture
def admin_headers() -> dict:
    return _headers("ADMINISTRATIVO")


@pytest.fixture
def medico_headers() -> dict:
    return _headers("MEDICO")


@pytest.fixture
def limpieza_headers() -> dict:
    return _headers("LIMPIEZA")