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