@@ -154,3 +154,56 @@ async def test_handle_new_storage_directory(
154154 assert stored_file .type == FileType .DIRECTORY
155155
156156 assert not storage_engine .called
157+
158+
159+ @pytest .mark .asyncio
160+ async def test_store_files_is_false (
161+ mocker ,
162+ session_factory : DbSessionFactory ,
163+ mock_config : Config ,
164+ fixture_message_directory : MessageDb ,
165+ ):
166+ mock_ipfs_client = mocker .MagicMock ()
167+ ipfs_stats = {
168+ "Hash" : "QmPZrod87ceK4yVvXQzRexDcuDgmLxBiNJ1ajLjLoMx9sU" ,
169+ "Size" : 0 ,
170+ "CumulativeSize" : 4560 ,
171+ "Blocks" : 2 ,
172+ "Type" : "file" ,
173+ }
174+ mock_ipfs_client .files .stat = mocker .AsyncMock (return_value = ipfs_stats )
175+
176+ mock_config .storage .store_files .value = False
177+
178+ message = fixture_message_directory
179+ storage_engine = mocker .AsyncMock ()
180+
181+ storage_service = StorageService (
182+ storage_engine = storage_engine ,
183+ ipfs_service = IpfsService (ipfs_client = mock_ipfs_client ),
184+ node_cache = mocker .AsyncMock (),
185+ )
186+ get_hash_content_mock = mocker .patch .object (storage_service , "get_hash_content" )
187+ store_message_handler = StoreMessageHandler (
188+ storage_service = storage_service , grace_period = 24
189+ )
190+
191+ with session_factory () as session :
192+ await store_message_handler .fetch_related_content (
193+ session = session , message = message
194+ )
195+ session .commit ()
196+
197+ with session_factory () as session :
198+ stored_files = list ((session .execute (select (StoredFileDb ))).scalars ())
199+
200+ assert len (stored_files ) == 1
201+ stored_file = stored_files [0 ]
202+
203+ # Check the updates to the message content
204+ assert stored_file .hash == ipfs_stats ["Hash" ]
205+ assert stored_file .size == - 1
206+ assert stored_file .type == FileType .FILE
207+
208+ storage_engine .assert_not_called ()
209+ get_hash_content_mock .assert_not_called ()
0 commit comments