@@ -138,12 +138,83 @@ def test_latest_tds_observation_date_falls_back_to_collection_date(water_well_th
138138 session .commit ()
139139
140140
141+ def test_latest_tds_uses_latest_timestamp_within_same_day (water_well_thing ):
142+ with session_ctx () as session :
143+ csi = NMA_Chemistry_SampleInfo (
144+ thing_id = water_well_thing .id ,
145+ nma_sample_point_id = "TDS-TIME" ,
146+ collection_date = datetime (2024 , 2 , 1 , 9 , 0 , 0 ),
147+ )
148+ session .add (csi )
149+ session .flush ()
150+
151+ mc_early = NMA_MajorChemistry (
152+ chemistry_sample_info_id = csi .id ,
153+ analyte = "Total Dissolved Solids" ,
154+ symbol = "TDS" ,
155+ sample_value = 300.0 ,
156+ units = "mg/L" ,
157+ analysis_date = datetime (2024 , 2 , 1 , 8 , 0 , 0 ),
158+ )
159+ mc_late = NMA_MajorChemistry (
160+ chemistry_sample_info_id = csi .id ,
161+ analyte = "Total Dissolved Solids" ,
162+ symbol = "TDS" ,
163+ sample_value = 700.0 ,
164+ units = "mg/L" ,
165+ analysis_date = datetime (2024 , 2 , 1 , 18 , 0 , 0 ),
166+ )
167+ session .add (mc_early )
168+ session .add (mc_late )
169+ session .commit ()
170+
171+ session .execute (text ("REFRESH MATERIALIZED VIEW ogc_avg_tds_wells" ))
172+ session .commit ()
173+
174+ row = session .execute (
175+ text (
176+ "SELECT latest_tds_observation_date, latest_tds_value "
177+ "FROM ogc_latest_tds_wells WHERE id = :thing_id"
178+ ),
179+ {"thing_id" : water_well_thing .id },
180+ ).one ()
181+
182+ assert row .latest_tds_observation_date .isoformat () == "2024-02-01"
183+ assert float (row .latest_tds_value ) == 700.0
184+
185+ session .delete (mc_late )
186+ session .delete (mc_early )
187+ session .delete (csi )
188+ session .commit ()
189+ session .execute (text ("REFRESH MATERIALIZED VIEW ogc_avg_tds_wells" ))
190+ session .commit ()
191+
192+
141193def test_ogc_collections ():
142194 response = client .get ("/ogcapi/collections" )
143195 assert response .status_code == 200
144196 payload = response .json ()
145197 ids = {collection ["id" ] for collection in payload ["collections" ]}
146- assert {"locations" , "water_wells" , "springs" }.issubset (ids )
198+ assert {
199+ "locations" ,
200+ "water_wells" ,
201+ "springs" ,
202+ "latest_tds_wells" ,
203+ "depth_to_water_trend_wells" ,
204+ "water_well_summary" ,
205+ }.issubset (ids )
206+
207+
208+ def test_ogc_new_collection_items_endpoints ():
209+ for collection_id in (
210+ "latest_tds_wells" ,
211+ "depth_to_water_trend_wells" ,
212+ "water_well_summary" ,
213+ ):
214+ response = client .get (f"/ogcapi/collections/{ collection_id } /items?limit=10" )
215+ assert response .status_code == 200
216+ payload = response .json ()
217+ assert payload ["type" ] == "FeatureCollection"
147218
148219
149220@pytest .mark .skip ("PostGIS spatial operators not available in CI - see issue #449" )
0 commit comments