Subir todos los cambios recientes a la rama principal
This commit is contained in:
71
backend/tests/test_clients.py
Normal file
71
backend/tests/test_clients.py
Normal file
@@ -0,0 +1,71 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from app.main import app
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
@pytest.fixture
|
||||
def sample_client_data():
|
||||
return {
|
||||
"clave": "12345",
|
||||
"tipo_cliente": "Regular",
|
||||
"nombre": "Cliente Prueba",
|
||||
"pais": "México",
|
||||
"estado": "Chihuahua",
|
||||
"ciudad": "Cd. Juárez",
|
||||
"direccion": "Calle Falsa 123",
|
||||
"numero_ext": "12",
|
||||
"cp": "32000",
|
||||
"colonia": "Centro",
|
||||
"lada": "656",
|
||||
"telefono1": "1234567890",
|
||||
"telefono2": "0987654321",
|
||||
"tel_directo": "1231231234",
|
||||
"ext": "101",
|
||||
"fax": "1231231235",
|
||||
"horario": "9:00 - 18:00",
|
||||
"pagina": "www.clienteprueba.com",
|
||||
"correo": "cliente@prueba.com",
|
||||
"medio_publicidad": "Internet",
|
||||
"nacionalidad": "Mexicana",
|
||||
"logo": "logo.png"
|
||||
}
|
||||
|
||||
def test_create_client(sample_client_data):
|
||||
response = client.post("/api/v1/clients", json=sample_client_data)
|
||||
assert response.status_code == 200
|
||||
assert response.json()["clave"] == sample_client_data["clave"]
|
||||
|
||||
def test_read_client(sample_client_data):
|
||||
# Create a client first
|
||||
create_response = client.post("/api/v1/clients", json=sample_client_data)
|
||||
client_id = create_response.json()["id"]
|
||||
|
||||
# Read the client
|
||||
response = client.get(f"/api/v1/clients/{client_id}")
|
||||
assert response.status_code == 200
|
||||
assert response.json()["id"] == client_id
|
||||
|
||||
def test_update_client(sample_client_data):
|
||||
# Create a client first
|
||||
create_response = client.post("/api/v1/clients", json=sample_client_data)
|
||||
client_id = create_response.json()["id"]
|
||||
|
||||
# Update the client
|
||||
updated_data = {"nombre": "Cliente Actualizado"}
|
||||
response = client.put(f"/api/v1/clients/{client_id}", json=updated_data)
|
||||
assert response.status_code == 200
|
||||
assert response.json()["nombre"] == "Cliente Actualizado"
|
||||
|
||||
def test_delete_client(sample_client_data):
|
||||
# Create a client first
|
||||
create_response = client.post("/api/v1/clients", json=sample_client_data)
|
||||
client_id = create_response.json()["id"]
|
||||
|
||||
# Delete the client
|
||||
response = client.delete(f"/api/v1/clients/{client_id}")
|
||||
assert response.status_code == 200
|
||||
|
||||
# Verify deletion
|
||||
response = client.get(f"/api/v1/clients/{client_id}")
|
||||
assert response.status_code == 404
|
||||
27
backend/tests/test_security.py
Normal file
27
backend/tests/test_security.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import pytest
|
||||
from app.core.security import SecurityUtils
|
||||
from datetime import timedelta
|
||||
|
||||
# Test password hashing and verification
|
||||
def test_password_hashing():
|
||||
plain_password = "securepassword123"
|
||||
hashed_password = SecurityUtils.hash_password(plain_password)
|
||||
|
||||
assert SecurityUtils.verify_password(plain_password, hashed_password) == True
|
||||
assert SecurityUtils.verify_password("wrongpassword", hashed_password) == False
|
||||
|
||||
# Test JWT token generation and validation
|
||||
def test_jwt_token_generation():
|
||||
payload = {"sub": "12345", "email": "test@example.com"}
|
||||
token = SecurityUtils.create_access_token(payload, expires_delta=timedelta(minutes=15))
|
||||
|
||||
decoded_payload = SecurityUtils.verify_token(token)
|
||||
assert decoded_payload is not None
|
||||
assert decoded_payload["sub"] == "12345"
|
||||
assert decoded_payload["email"] == "test@example.com"
|
||||
|
||||
# Test TOTP secret generation
|
||||
def test_totp_secret_generation():
|
||||
secret = SecurityUtils.generate_totp_secret()
|
||||
assert len(secret) > 0
|
||||
assert isinstance(secret, str)
|
||||
Reference in New Issue
Block a user