@@ -700,6 +700,31 @@ def test_shelflistitem_row_pagination(api_settings, shelflist_solr_env,
700700 assert row_numbers [- 1 ] == offset + limit - 1
701701
702702
703+ def test_shelflistitem_row_limit_one (api_settings , shelflist_solr_env ,
704+ get_shelflist_urls , api_client ,
705+ redis_obj , get_found_ids ):
706+ """
707+ When paginating a `shelflistitems` list view, requesting a limit of
708+ one item should work as expected.
709+ """
710+ recs = shelflist_solr_env .records ['shelflistitem' ]
711+ loc = recs [0 ]['location_code' ]
712+ loc_recs = [r for r in recs if r ['location_code' ] == loc ]
713+ using = api_settings .REST_VIEWS_HAYSTACK_CONNECTIONS ['ShelflistItems' ]
714+ index = ShelflistItemIndex (using = using )
715+ manifest = index .get_location_manifest (loc )
716+ redis_key = '{}:{}' .format (REDIS_SHELFLIST_PREFIX , loc )
717+ redis_obj (redis_key ).set (manifest )
718+ limit_p = api_settings .REST_FRAMEWORK ['PAGINATE_BY_PARAM' ]
719+ url = get_shelflist_urls (shelflist_solr_env .records ['shelflistitem' ])[loc ]
720+ paginated_url = f"{ url } ?{ limit_p } =1"
721+ response = api_client .get (paginated_url )
722+ found_ids = get_found_ids ('id' , response )
723+ row_numbers = get_found_ids ('rowNumber' , response )
724+ assert found_ids == [manifest [0 ]]
725+ assert row_numbers == [0 ]
726+
727+
703728def test_shelflistitem_row_filtering (api_settings , shelflist_solr_env ,
704729 get_shelflist_urls , api_client ,
705730 assemble_shelflist_test_records ,
@@ -781,8 +806,8 @@ def test_shelflistitem_list_row_caching(api_settings, shelflist_solr_env,
781806 cache miss.
782807 """
783808 mocker .patch .object (
784- RedisObject , 'get_index ' , mocker .Mock (
785- side_effect = lambda * args : list (range (1000 , 1000 + len (args )))
809+ RedisObject , 'get ' , mocker .Mock (
810+ side_effect = lambda l , lt : list (range (1000 , 1000 + len (l )))
786811 )
787812 )
788813 ShelflistItemSerializer ._lookup_cache ['row_numbers' ] = {}
@@ -807,28 +832,28 @@ def test_shelflistitem_list_row_caching(api_settings, shelflist_solr_env,
807832 # Redis to get the first item, and we extrapolate to get the rest
808833 # of the items in the list.
809834 assert len (manifest ) > 1
810- call_stack .append (mocker .call (* manifest ))
811- assert RedisObject .get_index .mock_calls == call_stack
835+ call_stack .append (mocker .call (manifest , 'values' ))
836+ assert RedisObject .get .mock_calls == call_stack
812837
813838 # Now when we request detail views for individual rows in the list,
814839 # it should still use the cached row number, if it finds it,
815840 # instead of querying Redis.
816841 for ping_row in (0 , 2 , len (manifest ) - 1 ):
817842 api_client .get (f"{ url } { manifest [ping_row ]} " )
818- assert RedisObject .get_index .mock_calls == call_stack
843+ assert RedisObject .get .mock_calls == call_stack
819844
820845 # When we hit the list view again it should refresh the cache,
821846 # resulting in an additional call to Redis.
822847 api_client .get (url )
823- call_stack .append (mocker .call (* manifest ))
824- assert RedisObject .get_index .mock_calls == call_stack
848+ call_stack .append (mocker .call (manifest , 'values' ))
849+ assert RedisObject .get .mock_calls == call_stack
825850
826851 # If we clear the serializer lookup_cache, then hitting the detail
827852 # view for an individual row requests the rowNumber from Redis.
828853 ShelflistItemSerializer ._lookup_cache ['row_numbers' ] = {}
829854 api_client .get (f"{ url } { manifest [- 1 ]} " )
830- call_stack .append (mocker .call (manifest [- 1 ]))
831- assert RedisObject .get_index .mock_calls == call_stack
855+ call_stack .append (mocker .call (manifest [- 1 ], 'value' ))
856+ assert RedisObject .get .mock_calls == call_stack
832857
833858
834859def test_shelflistitem_putpatch_requires_auth (api_settings ,
0 commit comments