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