@@ -291,7 +291,7 @@ def test_services_is_allowed_mimetype():
291291 ),
292292 ],
293293)
294- def test_services_search_has_text (indexer_settings , kwargs , expected ):
294+ def test_services_search_can_serialize_content (indexer_settings , kwargs , expected ):
295295 """
296296 Only allowed mimetypes of uploaded files in ready state can have an indexable
297297 content.
@@ -313,7 +313,7 @@ def test_services_search_has_text(indexer_settings, kwargs, expected):
313313 ** params ,
314314 )
315315
316- assert expected == SearchIndexer ().has_text (item )
316+ assert expected == SearchIndexer ().can_serialize_content (item )
317317
318318
319319@pytest .mark .usefixtures ("indexer_settings" )
@@ -646,6 +646,43 @@ def test_services_search_indexers_ignore_content_if_not_ready(mock_push):
646646 }
647647
648648
649+ @patch .object (SearchIndexer , "push" )
650+ @pytest .mark .usefixtures ("indexer_settings" )
651+ def test_services_search_indexers_ignore_content_if_too_big (
652+ mock_push , indexer_settings
653+ ):
654+ """
655+ Should not fill the content data when the file is over the limit
656+ setting SEARCH_INDEXER_CONTENT_MAX_SIZE
657+ """
658+ indexer_settings .SEARCH_INDEXER_CONTENT_MAX_SIZE = 50
659+
660+ item = factories .ItemFactory (
661+ mimetype = "text/plain" ,
662+ type = models .ItemTypeChoices .FILE ,
663+ update_upload_state = models .ItemUploadStateChoices .READY ,
664+ upload_bytes = "a" * 49 ,
665+ )
666+
667+ # too big
668+ too_big_item = factories .ItemFactory (
669+ mimetype = "text/plain" ,
670+ type = models .ItemTypeChoices .FILE ,
671+ update_upload_state = models .ItemUploadStateChoices .READY ,
672+ upload_bytes = "a" * 50 ,
673+ )
674+
675+ assert SearchIndexer ().index () == 2
676+
677+ assert mock_push .call_count == 1
678+
679+ results = {item ["id" ]: item ["content" ] for item in mock_push .call_args [0 ][0 ]}
680+ assert results == {
681+ str (item .id ): "a" * 49 ,
682+ str (too_big_item .id ): "" ,
683+ }
684+
685+
649686@patch .object (SearchIndexer , "push" )
650687@pytest .mark .usefixtures ("indexer_settings" )
651688def test_services_search_indexers_ancestors_link_reach (mock_push ):
0 commit comments