@@ -275,16 +275,23 @@ def call_list(self, system_id: Optional[str], catalogue_item_id: Optional[str])
275275 system_id = system_id , catalogue_item_id = catalogue_item_id , session = self .mock_session
276276 )
277277
278- def check_list_success (self ) -> None :
279- """Checks that a prior call to `call_list` worked as expected."""
278+ def check_list_success (self , assert_find : bool = True ) -> None :
279+ """Checks that a prior call to `call_list` worked as expected.
280280
281- expected_query = {}
282- if self ._system_id_filter :
283- expected_query ["system_id" ] = CustomObjectId (self ._system_id_filter )
284- if self ._catalogue_item_id_filter :
285- expected_query ["catalogue_item_id" ] = CustomObjectId (self ._catalogue_item_id_filter )
281+ :param assert_find: If `True` it asserts whether a `find_one` call was made, else it asserts that no call was
282+ made.
283+ """
286284
287- self .items_collection .find .assert_called_once_with (expected_query , session = self .mock_session )
285+ if assert_find :
286+ expected_query = {}
287+ if self ._system_id_filter :
288+ expected_query ["system_id" ] = CustomObjectId (self ._system_id_filter )
289+ if self ._catalogue_item_id_filter :
290+ expected_query ["catalogue_item_id" ] = CustomObjectId (self ._catalogue_item_id_filter )
291+
292+ self .items_collection .find .assert_called_once_with (expected_query , session = self .mock_session )
293+ else :
294+ self .items_collection .find .assert_not_called ()
288295
289296 assert self ._obtained_items_out == self ._expected_items_out
290297
@@ -306,13 +313,27 @@ def test_list_with_system_id_filter(self):
306313 self .call_list (system_id = str (ObjectId ()), catalogue_item_id = None )
307314 self .check_list_success ()
308315
316+ def test_list_with_invalid_system_id_filter (self ):
317+ """Test listing all items when giving an invalid `system_id`."""
318+
319+ self .mock_list ([])
320+ self .call_list (system_id = "invalid-id" , catalogue_item_id = None )
321+ self .check_list_success (assert_find = False )
322+
309323 def test_list_with_catalogue_category_id_filter (self ):
310324 """Test listing all items with a given `catalogue_category_id`."""
311325
312326 self .mock_list ([ITEM_IN_DATA_REQUIRED_VALUES_ONLY , ITEM_IN_DATA_ALL_VALUES_NO_PROPERTIES ])
313327 self .call_list (system_id = None , catalogue_item_id = str (ObjectId ()))
314328 self .check_list_success ()
315329
330+ def test_list_with_invalid_catalogue_category_id_filter (self ):
331+ """Test listing all items when given an invalid `catalogue_category_id`."""
332+
333+ self .mock_list ([])
334+ self .call_list (system_id = None , catalogue_item_id = "invalid-id" )
335+ self .check_list_success (assert_find = False )
336+
316337 def test_list_with_system_id_and_catalogue_category_id_with_no_results (self ):
317338 """Test listing all items with a `system_id` and `catalogue_category_id` filter returning no results."""
318339
0 commit comments