22#
33# SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-MerginMaps-Commercial
44
5+ from mergin .sync .tasks import remove_transaction_chunks , remove_unused_chunks
56from . import DEFAULT_USER
67from .utils import (
78 add_user ,
2223
2324from mergin .app import db
2425from mergin .config import Configuration
26+ from mergin .sync .config import Configuration as SyncConfiguration
2527from mergin .sync .errors import (
2628 BigChunkError ,
2729 ProjectLocked ,
@@ -356,6 +358,7 @@ def test_create_version(client, data, expected, err_code):
356358 assert project .latest_version == 1
357359
358360 chunks = []
361+ chunk_ids = []
359362 if expected == 201 :
360363 # mimic chunks were uploaded
361364 for f in data ["changes" ]["added" ] + data ["changes" ]["updated" ]:
@@ -372,12 +375,21 @@ def test_create_version(client, data, expected, err_code):
372375 out_file .write (in_file .read (CHUNK_SIZE ))
373376
374377 chunks .append (chunk_location )
378+ chunk_ids .append (chunk )
375379
376- 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 )
377384 assert response .status_code == expected
378385 if expected == 201 :
379386 assert response .json ["version" ] == "v2"
380387 assert project .latest_version == 2
388+ # chunks exists after upload, cleanup job did not remove them
389+ assert all (os .path .exists (chunk ) for chunk in chunks )
390+ if chunk_ids :
391+ assert mock_remove .called_once_with (chunk_ids )
392+ remove_transaction_chunks (chunk_ids )
381393 assert all (not os .path .exists (chunk ) for chunk in chunks )
382394 else :
383395 assert project .latest_version == 1
0 commit comments