File size: 1,628 Bytes
908ea54 25eff18 908ea54 | 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | from agroscan.api import create_app
class StubClassifier:
def diagnostico_e_tratamento(self, respostas):
if not respostas:
return {"error": "Respostas vazias ou inválidas"}
return {
"diagnostico": "Pragas do Solo",
"tratamento_nivel_1": "Org",
"tratamento_nivel_2": "Gen",
"tratamento_nivel_3": "Agr",
}
def test_health_endpoint():
app = create_app(classifier=StubClassifier())
client = app.test_client()
resp = client.get("/health")
assert resp.status_code == 200
assert resp.get_json()["status"] == "ok"
def test_index_page():
app = create_app(classifier=StubClassifier())
client = app.test_client()
resp = client.get("/")
assert resp.status_code == 200
assert b"AgroScan" in resp.data
def test_diagnostico_endpoint():
app = create_app(classifier=StubClassifier())
client = app.test_client()
resp = client.post("/diagnostico", json={"respostas": ["texto"]})
assert resp.status_code == 200
assert resp.get_json()["diagnostico"] == "Pragas do Solo"
def test_perguntas_endpoint():
app = create_app(classifier=StubClassifier())
client = app.test_client()
resp = client.get("/perguntas")
data = resp.get_json()
assert resp.status_code == 200
assert isinstance(data.get("perguntas"), list)
assert len(data["perguntas"]) >= 1
def test_diagnostico_invalido():
app = create_app(classifier=StubClassifier())
client = app.test_client()
resp = client.post("/diagnostico", json={"respostas": []})
assert resp.status_code == 400
|