Coverage for tests\test_dependentes.py: 100%
43 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-07 20:50 +0100
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-07 20:50 +0100
1dependente_id = None
2import json
4def test_add_dependenta(client):
5 global dependente_id
6 response = client.post("/addDependenta", json={
7 "nom": "Dependenta Test",
8 "idBotiga": "GTGqQOmFv0gDwi53uT2C"
9 })
10 assert response.status_code == 200
11 assert response.json()["message"] == "Dependenta afegida"
13 # Obtener ID de la dependenta recién creada
14 response = client.get("/getDependentes")
15 dependentes = response.json()["dependentes"]
16 dependente_id = next((dep["id"] for dep in dependentes if dep["nom"] == "Dependenta Test"), None)
17 assert dependente_id is not None
19def test_add_dependenta_missing_fields(client):
20 response = client.post("/addDependenta", json={"nom": "Dependenta Sin Botiga"})
21 assert response.status_code == 422
23 # Validar que el error está relacionado con el campo "idBotiga"
24 error_detail = response.json()["detail"]
25 assert any(item["loc"] == ["body", "idBotiga"] and item["msg"] == "Field required" for item in error_detail)
29def test_add_dependenta_store_dependenta_not_found(client):
30 response = client.put("/addDependentaStore", json={
31 "idDependenta": "nonexistent_dependenta_id",
32 "idBotiga": "NAmL5PKwKsrkB5QzYbxJ"
33 })
34 assert response.status_code == 404
35 assert response.json()["message"] == "Dependenta no existe"
37def test_add_dependenta_store_botiga_not_found(client):
38 global dependente_id
39 response = client.put("/addDependentaStore", json={
40 "idDependenta": dependente_id,
41 "idBotiga": "nonexistent_store_id"
42 })
43 assert response.status_code == 404
44 assert response.json()["message"] == "Botiga no existe"
47def test_add_dependenta_store_success(client):
48 global dependente_id
49 response = client.put("/addDependentaStore", json={
50 "idDependenta": dependente_id,
51 "idBotiga": "NAmL5PKwKsrkB5QzYbxJ"
52 })
53 assert response.status_code == 200
54 assert response.json()["message"] == "Tenda de asignada"
56def test_delete_dependenta(client):
57 global dependente_id
60 response = client.request(
61 method="DELETE",
62 url="/eliminarDependenta",
63 data=json.dumps({"idDependenta": dependente_id, "idBotiga": "NAmL5PKwKsrkB5QzYbxJ"}),
64 headers={"Content-Type": "application/json"}
65 )
66 assert response.status_code == 200
67 assert response.json()["message"] == "Dependenta eliminada"
69def test_get_dependentes_botiga_with_dependentes(client):
70 response = client.post("/getDependentesBotiga", json={"idBotiga": "NAmL5PKwKsrkB5QzYbxJ"})
71 assert response.status_code == 200
72 assert "dependentes" in response.json()
74def test_get_dependentes_botiga_without_dependentes(client):
75 response = client.post("/getDependentesBotiga", json={"idBotiga": "aW7n76Y61aD4dNAPzvAq"})
76 assert response.status_code == 200
77 assert response.json()["dependentes"] == []
79def test_get_dependentes_botiga_nonexistent_store(client):
80 response = client.post("/getDependentesBotiga", json={"idBotiga": "nonexistent_store"})
81 assert response.status_code == 404
82 assert response.json()["message"] == "Botiga no existe"