@@ -113,6 +113,23 @@ def test_validate_size_well_above_cap_rejected() -> None:
113113 _validate_params ({"size" : 1000 })
114114
115115
116+ def test_validate_size_at_min_accepted () -> None :
117+ """size=1 (the minimum) is accepted."""
118+ assert _validate_params ({"size" : 1 }) == {"size" : 1 }
119+
120+
121+ def test_validate_size_below_min_rejected () -> None :
122+ """size < 1 is rejected client-side."""
123+ with pytest .raises (NewsdataValidationError ) as exc_info :
124+ _validate_params ({"size" : 0 })
125+ assert exc_info .value .param == "size"
126+
127+
128+ def test_validate_size_negative_rejected () -> None :
129+ with pytest .raises (NewsdataValidationError ):
130+ _validate_params ({"size" : - 5 })
131+
132+
116133@pytest .mark .parametrize (
117134 ("params" , "first_conflict" ),
118135 [
@@ -176,24 +193,49 @@ def test_validate_no_mutex_when_one_per_group_set() -> None:
176193
177194
178195def test_validate_float_param_accepts_float () -> None :
179- assert _validate_params ({"sentiment_score" : 44.5 }) == {"sentiment_score" : 44.5 }
196+ out = _validate_params ({"sentiment" : "positive" , "sentiment_score" : 44.5 })
197+ assert out == {"sentiment" : "positive" , "sentiment_score" : 44.5 }
180198
181199
182200def test_validate_float_param_accepts_int () -> None :
183201 """int is accepted alongside float — urlencode handles the conversion."""
184- assert _validate_params ({"sentiment_score" : 50 }) == {"sentiment_score" : 50 }
202+ out = _validate_params ({"sentiment" : "positive" , "sentiment_score" : 50 })
203+ assert out == {"sentiment" : "positive" , "sentiment_score" : 50 }
185204
186205
187206def test_validate_float_param_rejects_bool () -> None :
188207 """``bool`` is an ``int`` subclass — must still be rejected for sentiment_score."""
189208 with pytest .raises (NewsdataValidationError ) as exc_info :
190- _validate_params ({"sentiment_score" : True })
209+ _validate_params ({"sentiment" : "positive" , " sentiment_score" : True })
191210 assert exc_info .value .param == "sentiment_score"
211+ assert "must be a number" in str (exc_info .value )
192212
193213
194214def test_validate_float_param_rejects_str () -> None :
195- with pytest .raises (NewsdataValidationError ):
196- _validate_params ({"sentiment_score" : "44.5" })
215+ with pytest .raises (NewsdataValidationError ) as exc_info :
216+ _validate_params ({"sentiment" : "positive" , "sentiment_score" : "44.5" })
217+ assert exc_info .value .param == "sentiment_score"
218+ assert "must be a number" in str (exc_info .value )
219+
220+
221+ def test_sentiment_score_requires_sentiment () -> None :
222+ """sentiment_score alone (without sentiment) is rejected."""
223+ with pytest .raises (NewsdataValidationError ) as exc_info :
224+ _validate_params ({"sentiment_score" : 44.5 })
225+ assert exc_info .value .param == "sentiment_score"
226+ assert "sentiment" in str (exc_info .value ).lower ()
227+
228+
229+ def test_sentiment_score_with_sentiment_passes () -> None :
230+ """sentiment_score paired with sentiment passes through."""
231+ out = _validate_params ({"sentiment" : "positive" , "sentiment_score" : 44.5 })
232+ assert out == {"sentiment" : "positive" , "sentiment_score" : 44.5 }
233+
234+
235+ def test_sentiment_alone_passes () -> None :
236+ """sentiment without sentiment_score is allowed (regression)."""
237+ out = _validate_params ({"sentiment" : "positive" })
238+ assert out == {"sentiment" : "positive" }
197239
198240
199241def test_validate_unknown_param_passes_through () -> None :
@@ -312,6 +354,20 @@ def test_raw_query_apikey_case_insensitive_drop() -> None:
312354 assert out == {"q" : "news" }
313355
314356
357+ def test_raw_query_rejects_key_with_empty_value () -> None :
358+ """A key with an empty value (e.g., q=) is rejected."""
359+ with pytest .raises (NewsdataValidationError ) as exc_info :
360+ _parse_raw_query ("q=" , allowed_keys = {"q" , "raw_query" })
361+ assert exc_info .value .param == "q"
362+
363+
364+ def test_raw_query_rejects_key_with_no_value () -> None :
365+ """A bare key with no '=' (e.g., q&country=us) is rejected."""
366+ with pytest .raises (NewsdataValidationError ) as exc_info :
367+ _parse_raw_query ("q&country=us" , allowed_keys = {"q" , "country" , "raw_query" })
368+ assert exc_info .value .param == "q"
369+
370+
315371# ===========================================================================
316372# Retry-After parsing
317373# ===========================================================================
0 commit comments