diff --git a/cmr/queries.py b/cmr/queries.py index 3e4a1f9..99ce60f 100644 --- a/cmr/queries.py +++ b/cmr/queries.py @@ -856,10 +856,12 @@ def cloud_cover(self, min_cover: FloatLike = 0, max_cover: FloatLike = 100) -> S :returns: self """ - if not min_cover and not max_cover: + has_min = min_cover is not None and min_cover != "" + has_max = max_cover is not None and max_cover != "" + if not has_min and not has_max: raise ValueError("Please provide at least min_cover, max_cover or both") - if min_cover and max_cover: + if has_min and has_max: try: minimum = float(min_cover) maxiumum = float(max_cover) diff --git a/tests/test_granule.py b/tests/test_granule.py index d14b319..ee70ecf 100644 --- a/tests/test_granule.py +++ b/tests/test_granule.py @@ -294,6 +294,22 @@ def test_day_night_flag_invalid_type_set(self): query.day_night_flag(True) # type: ignore[arg-type] self.assertNotIn(self.day_night_flag, query.params) + def test_cloud_cover_zero(self): + query = GranuleQuery().cloud_cover(0, 0) + self.assertEqual(query.params[self.cloud_cover], "0,0") + + def test_cloud_cover_zero_open_bound(self): + for bounds, expected in [(("", 0), ",0"), ((0, ""), "0,")]: + with self.subTest(bounds=bounds): + query = GranuleQuery().cloud_cover(*bounds) + self.assertEqual(query.params[self.cloud_cover], expected) + + def test_cloud_cover_invalid_with_zero(self): + for bounds in [(1, 0), (0, -1), (0, "invalid"), ("invalid", 0), ("", "")]: + with self.subTest(bounds=bounds): + with self.assertRaises(ValueError): + GranuleQuery().cloud_cover(*bounds) + def test_cloud_cover_min_only(self): query = GranuleQuery() query.cloud_cover(-70)