27 lines
919 B
Python
27 lines
919 B
Python
import polars as pl
|
|
import requests_mock
|
|
from collectors.weather import fetch_weather
|
|
|
|
def test_fetch_weather():
|
|
with requests_mock.Mocker() as m:
|
|
m.get("https://api.brightsky.dev/weather", json={
|
|
"weather": [
|
|
{
|
|
"timestamp": "2023-11-14T22:13:20+00:00",
|
|
"temperature": 10.5,
|
|
"wind_speed": 5.0,
|
|
"solar": 0.0,
|
|
"sunshine": 0.0,
|
|
"cloud_cover": 0.0,
|
|
"precipitation": 0.0,
|
|
"extra_field": "should_be_filtered"
|
|
}
|
|
]
|
|
})
|
|
|
|
df = fetch_weather()
|
|
assert isinstance(df, pl.DataFrame)
|
|
# Check that it filtered to the schema columns (7 columns)
|
|
assert df.shape == (1, 7)
|
|
assert "temperature" in df.columns
|
|
assert "extra_field" not in df.columns
|