70 lines
2.8 KiB
Python
70 lines
2.8 KiB
Python
|
|
import io
|
||
|
|
import json
|
||
|
|
import pytest
|
||
|
|
from fastapi.testclient import TestClient
|
||
|
|
from fiscalibre.web import app
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.fixture
|
||
|
|
def client(tmp_path, monkeypatch):
|
||
|
|
monkeypatch.setenv("FISCALIBRE_DATA_DIR", str(tmp_path / "data"))
|
||
|
|
return TestClient(app, base_url="http://localhost:8765")
|
||
|
|
|
||
|
|
|
||
|
|
def creer(client, profil):
|
||
|
|
r = client.post("/dossier/nouveau", data={"profil": profil}, follow_redirects=False)
|
||
|
|
assert r.status_code == 303
|
||
|
|
return r.headers["location"].split("/")[2].split("?")[0]
|
||
|
|
|
||
|
|
|
||
|
|
def test_accueil_et_3_profils(client):
|
||
|
|
assert client.get("/").status_code == 200
|
||
|
|
for p in ["particulier", "autonome", "societe"]:
|
||
|
|
ref = creer(client, p)
|
||
|
|
page = client.get(f"/dossier/{ref}")
|
||
|
|
assert page.status_code == 200
|
||
|
|
assert b"2025" in page.content
|
||
|
|
|
||
|
|
|
||
|
|
def test_saisie_pdf_et_json(client):
|
||
|
|
ref = creer(client, "particulier")
|
||
|
|
r = client.post(f"/dossier/{ref}/enregistrer?etape=identite", data={"i_prenom": "Zoé", "i_nom": "Dumas"}, follow_redirects=False)
|
||
|
|
assert r.status_code == 303
|
||
|
|
r = client.post(f"/dossier/{ref}/enregistrer?etape=revenus", data={"m_revenu_emploi": "60 000,25"}, follow_redirects=False)
|
||
|
|
assert r.status_code == 303
|
||
|
|
rapport = client.get(f"/dossier/{ref}/export/pdf")
|
||
|
|
assert rapport.status_code == 200 and rapport.content.startswith(b"%PDF")
|
||
|
|
assert len(rapport.content) > 4000
|
||
|
|
donnees = client.get(f"/dossier/{ref}/export/json")
|
||
|
|
document = json.loads(donnees.content)
|
||
|
|
assert document["dossier"]["data"]["identite"]["prenom"] == "Zoé"
|
||
|
|
assert document["calcul"]["pret_a_transmettre"] is False
|
||
|
|
|
||
|
|
|
||
|
|
def test_validation_rejet_montant_negatif(client):
|
||
|
|
ref = creer(client, "societe")
|
||
|
|
r = client.post(f"/dossier/{ref}/enregistrer?etape=revenus", data={"m_recettes_entreprise": "-3"}, follow_redirects=False)
|
||
|
|
assert r.status_code == 303
|
||
|
|
assert "erreur=" in r.headers["location"]
|
||
|
|
|
||
|
|
|
||
|
|
def test_import_csv(client):
|
||
|
|
ref = creer(client, "autonome")
|
||
|
|
donnees = "categorie;montant;description\nrecettes_entreprise;100,50;Client\ndepenses_entreprise;20,50;Outils\n"
|
||
|
|
r = client.post(f"/dossier/{ref}/importer", files={"fichier": ("ventes.csv", donnees.encode(), "text/csv")}, follow_redirects=False)
|
||
|
|
assert r.status_code == 303
|
||
|
|
bilan = json.loads(client.get(f"/dossier/{ref}/export/json").content)
|
||
|
|
assert bilan["calcul"]["lignes"]["ARC / T1 (préparation)"]["13500"] == "80.00"
|
||
|
|
|
||
|
|
|
||
|
|
def test_csv_rejet_categorie_inconnue(client):
|
||
|
|
ref = creer(client, "particulier")
|
||
|
|
donnees = b"categorie;montant;description\nweb_virus;100;test\n"
|
||
|
|
r = client.post(f"/dossier/{ref}/importer", files={"fichier": ("x.csv", donnees, "text/csv")})
|
||
|
|
assert r.status_code == 422
|
||
|
|
|
||
|
|
|
||
|
|
def test_host_non_local_interdit(client):
|
||
|
|
r = client.get("/", headers={"host": "fiscalibre.example.com"})
|
||
|
|
assert r.status_code == 403
|