22#
33# SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-MerginMaps-Commercial
44
5- from mergin .sync .tasks import remove_unused_chunks
5+ from mergin .sync .tasks import remove_transaction_chunks , remove_unused_chunks
66from . import DEFAULT_USER
77from .utils import (
88 add_user ,
@@ -358,6 +358,7 @@ def test_create_version(client, data, expected, err_code):
358358 assert project .latest_version == 1
359359
360360 chunks = []
361+ chunk_ids = []
361362 if expected == 201 :
362363 # mimic chunks were uploaded
363364 for f in data ["changes" ]["added" ] + data ["changes" ]["updated" ]:
@@ -374,17 +375,21 @@ def test_create_version(client, data, expected, err_code):
374375 out_file .write (in_file .read (CHUNK_SIZE ))
375376
376377 chunks .append (chunk_location )
378+ chunk_ids .append (chunk )
377379
378- response = client .post (f"v2/projects/{ project .id } /versions" , json = data )
380+ with patch (
381+ "mergin.sync.public_api_v2_controller.remove_transaction_chunks.delay"
382+ ) as mock_remove :
383+ response = client .post (f"v2/projects/{ project .id } /versions" , json = data )
379384 assert response .status_code == expected
380- # mock chunks expiration to check if removed
381385 if expected == 201 :
382386 assert response .json ["version" ] == "v2"
383387 assert project .latest_version == 2
384388 # chunks exists after upload, cleanup job did not remove them
385389 assert all (os .path .exists (chunk ) for chunk in chunks )
386- with patch .object (SyncConfiguration , "UPLOAD_CHUNKS_EXPIRATION" , 0 ):
387- remove_unused_chunks ()
390+ if chunk_ids :
391+ assert mock_remove .called_once_with (chunk_ids )
392+ remove_transaction_chunks (chunk_ids )
388393 assert all (not os .path .exists (chunk ) for chunk in chunks )
389394 else :
390395 assert project .latest_version == 1
0 commit comments