@@ -57,6 +57,50 @@ async def test_request_params_valid(request_valid, defaults, input_bbox, expecte
5757 ),
5858 )
5959
60+ async def test_count_search (request_valid , defaults , mock_search , mock_search_result ):
61+ """
62+ Test the count setting during a search.
63+ """
64+ count = get_settings ().count
65+ qs = f"search?collections={ defaults .collection } "
66+
67+ assert count is False , "Default count setting should be False"
68+ response = await request_valid (
69+ qs ,
70+ expected_search_kwargs = dict (
71+ collection = defaults .collection ,
72+ token = None ,
73+ items_per_page = DEFAULT_ITEMS_PER_PAGE ,
74+ raise_errors = False ,
75+ count = False , # Ensure count is set to False
76+ validate = True ,
77+ ),
78+ )
79+ assert "numberMatched" not in response
80+
81+ # Reset search mock, set "number_matched" attribute of the search results mock for a counting search
82+ # and set count to True
83+ mock_search .reset_mock ()
84+ search_result = mock_search_result
85+ search_result .number_matched = len (search_result )
86+ get_settings ().count = True
87+
88+ response = await request_valid (
89+ qs ,
90+ expected_search_kwargs = dict (
91+ collection = defaults .collection ,
92+ token = None ,
93+ items_per_page = DEFAULT_ITEMS_PER_PAGE ,
94+ raise_errors = False ,
95+ count = True , # Ensure count is set to True
96+ validate = True ,
97+ ),
98+ )
99+ assert response ["numberMatched" ] == 2
100+
101+ # Reset count setting to default
102+ get_settings ().count = count
103+
60104
61105async def test_items_response (request_valid , defaults ):
62106 """Returned items properties must be mapped as expected"""
0 commit comments