File size: 1,318 Bytes
844f884
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from app.utils.climate_intelligence import (
    build_climate_intelligence_context,
    extract_nigeria_location,
    infer_crop_and_growth_stage,
)


def test_build_climate_intelligence_context_contains_climate_risk_and_recommendations():
    context = build_climate_intelligence_context(
        latitude=10.0,
        longitude=7.0,
        crop="maize",
        growth_stage="pre-planting",
        days=7,
    )

    assert isinstance(context, dict)
    assert "location" in context
    assert "current_weather" in context
    assert "forecast" in context
    assert "climate_risk" in context
    assert "recommendations" in context
    assert context["location"]["country"] == "Nigeria"
    assert context["climate_risk"] in {"low", "medium", "high"}
    assert isinstance(context["recommendations"], list)
    assert context["recommendations"]


def test_extract_nigeria_location_handles_lagos_and_ikeja():
    assert extract_nigeria_location("What is the weather like in Lagos?")[0] == "Lagos"
    assert extract_nigeria_location("Ikeja weather forecast")[0] == "Ikeja"


def test_infer_crop_and_growth_stage_handles_farm_questions():
    crop, stage = infer_crop_and_growth_stage("Should I plant maize in Kaduna before the rains?")
    assert crop == "maize"
    assert stage in {"pre-planting", "planting"}