11import json
2- import os
32import unittest
43from pathlib import Path
54from unittest .mock import MagicMock , patch
1312class TestItalyToscanyFetcher (unittest .TestCase ):
1413 def setUp (self ):
1514 self .fetcher = ItalyToscanyFetcher ()
16- self .test_data_dir = Path (os . path . dirname ( __file__ )) / "test_data"
15+ self .test_data_dir = Path (__file__ ). parent / "test_data"
1716
1817 def _load_json (self , filename ):
1918 with open (self .test_data_dir / filename , "r" , encoding = "utf-8" ) as f :
@@ -48,6 +47,7 @@ def test_get_metadata_merges_wfs_and_station_table(self, mock_requests_session):
4847
4948 result_df = self .fetcher .get_metadata ()
5049
50+ self .assertEqual (result_df .index .name , constants .GAUGE_ID )
5151 self .assertEqual (list (result_df .index ), ["TOS01004005" , "TOS01004007" , "TOS01004379" ])
5252 self .assertEqual (result_df .loc ["TOS01004005" , constants .STATION_NAME ], "Carrara" )
5353 self .assertEqual (result_df .loc ["TOS01004005" , constants .RIVER ], "Carrione" )
@@ -59,6 +59,11 @@ def test_get_metadata_merges_wfs_and_station_table(self, mock_requests_session):
5959 self .assertAlmostEqual (result_df .loc ["TOS01004005" , "zero_idrometrico" ], 95.69 , places = 2 )
6060 self .assertEqual (result_df .loc ["TOS01004005" , constants .COUNTRY ], "Italy" )
6161 self .assertEqual (result_df .loc ["TOS01004005" , constants .SOURCE ], self .fetcher .SOURCE )
62+ self .assertEqual (mock_session .get .call_count , 2 )
63+ self .assertEqual (mock_session .get .call_args_list [0 ].args [0 ], self .fetcher .METADATA_URL )
64+ self .assertEqual (mock_session .get .call_args_list [1 ].args [0 ], self .fetcher .STATION_TABLE_URL )
65+ self .assertEqual (mock_session .get .call_args_list [0 ].kwargs ["timeout" ], 60 )
66+ self .assertEqual (mock_session .get .call_args_list [1 ].kwargs ["timeout" ], 60 )
6267
6368 @patch ("rivretrieve.utils.requests_retry_session" )
6469 def test_get_data_daily_stage (self , mock_requests_session ):
@@ -83,8 +88,12 @@ def test_get_data_daily_stage(self, mock_requests_session):
8388 ).set_index (constants .TIME_INDEX )
8489
8590 assert_frame_equal (result_df , expected_df )
91+ self .assertEqual (result_df .index .name , constants .TIME_INDEX )
8692 params = mock_session .get .call_args .kwargs ["params" ]
8793 self .assertEqual (params ["IDST" ], "idro_l" )
94+ self .assertEqual (params ["IDS" ], "TOS02004365" )
95+ self .assertEqual (mock_session .get .call_args .args [0 ], self .fetcher .ARCHIVE_URL )
96+ self .assertEqual (mock_session .get .call_args .kwargs ["timeout" ], 60 )
8897
8998 @patch ("rivretrieve.utils.requests_retry_session" )
9099 def test_get_data_daily_discharge (self , mock_requests_session ):
@@ -109,8 +118,10 @@ def test_get_data_daily_discharge(self, mock_requests_session):
109118 ).set_index (constants .TIME_INDEX )
110119
111120 assert_frame_equal (result_df , expected_df )
121+ self .assertEqual (result_df .index .name , constants .TIME_INDEX )
112122 params = mock_session .get .call_args .kwargs ["params" ]
113123 self .assertEqual (params ["IDST" ], "idro_p" )
124+ self .assertEqual (params ["IDS" ], "TOS02004365" )
114125
115126 @patch ("rivretrieve.utils.requests_retry_session" )
116127 def test_get_data_returns_empty_when_archive_has_no_table (self , mock_requests_session ):
@@ -126,6 +137,7 @@ def test_get_data_returns_empty_when_archive_has_no_table(self, mock_requests_se
126137 )
127138
128139 self .assertTrue (result_df .empty )
140+ self .assertEqual (result_df .index .name , constants .TIME_INDEX )
129141
130142 def test_unsupported_variable_raises (self ):
131143 with self .assertRaises (ValueError ):
0 commit comments