@@ -171,6 +171,68 @@ def test_get_books_combined_filters(
171171 assert response_doc ["meta" ]["count" ] == 2
172172
173173
174+ @pytest .mark .parametrize (
175+ "needs_attention,expected_count" ,
176+ [
177+ pytest .param (None , 5 , id = "no-filter" ),
178+ pytest .param (True , 4 , id = "needs-attention" ),
179+ pytest .param (False , 1 , id = "does-not-need-attention" ),
180+ ],
181+ )
182+ def test_get_books_filter_by_needs_attention (
183+ client : TestClient ,
184+ create_book : Callable [..., Book ],
185+ create_title : Callable [..., Title ],
186+ needs_attention : bool | None ,
187+ expected_count : int ,
188+ ):
189+ """Test get books endpoint filtering by needs_attention"""
190+
191+ title = create_title ()
192+
193+ book_with_title = create_book (zim_metadata = {"Name" : title .name })
194+ title .books .append (book_with_title )
195+
196+ book_without_title = create_book (zim_metadata = {"Name" : "different_name" })
197+
198+ book_needs_processing = create_book (zim_metadata = {"Name" : title .name })
199+ title .books .append (book_needs_processing )
200+ book_needs_processing .needs_processing = True
201+
202+ book_has_error = create_book (zim_metadata = {"Name" : title .name })
203+ title .books .append (book_has_error )
204+ book_has_error .has_error = True
205+
206+ book_needs_file_operation = create_book (zim_metadata = {"Name" : title .name })
207+ title .books .append (book_needs_file_operation )
208+ book_needs_file_operation .needs_file_operation = True
209+
210+ url = (
211+ "/v1/books"
212+ if needs_attention is None
213+ else f"/v1/books?needs_attention={ str (needs_attention ).lower ()} "
214+ )
215+ response = client .get (url )
216+
217+ assert response .status_code == HTTPStatus .OK
218+ response_doc = response .json ()
219+ assert response_doc ["meta" ]["count" ] == expected_count
220+ assert len (response_doc ["items" ]) == expected_count
221+
222+ if needs_attention is True :
223+ returned_ids = {item ["id" ] for item in response_doc ["items" ]}
224+ assert returned_ids == {
225+ str (book_without_title .id ),
226+ str (book_needs_processing .id ),
227+ str (book_has_error .id ),
228+ str (book_needs_file_operation .id ),
229+ }
230+
231+ if needs_attention is False :
232+ returned_ids = {item ["id" ] for item in response_doc ["items" ]}
233+ assert returned_ids == {str (book_with_title .id )}
234+
235+
174236def test_get_books_filter_by_id (
175237 client : TestClient ,
176238 create_book : Callable [..., Book ],
0 commit comments