@@ -118,6 +118,23 @@ def test_initialization(self, mock_config: BackupConfig) -> None:
118118 assert isinstance (command .logger , logging .Logger )
119119 assert command .logger .name == "autotarcompress.commands.cleanup"
120120
121+ def test_initialization_with_cleanup_all (self , mock_config : BackupConfig ) -> None :
122+ """Test CleanupCommand initialization with cleanup_all parameter.
123+
124+ Args:
125+ mock_config: Mock backup configuration.
126+
127+ """
128+ command = CleanupCommand (mock_config , cleanup_all = True )
129+
130+ assert command .config is mock_config
131+ assert command .cleanup_all is True
132+ assert isinstance (command .logger , logging .Logger )
133+
134+ # Test default value
135+ command_default = CleanupCommand (mock_config )
136+ assert command_default .cleanup_all is False
137+
121138 @patch .object (CleanupCommand , "_cleanup_files" )
122139 def test_execute_calls_cleanup_methods (
123140 self , mock_cleanup : Mock , cleanup_command : CleanupCommand
@@ -475,3 +492,65 @@ def test_file_extension_filtering(self, cleanup_command: CleanupCommand) -> None
475492
476493 # Should only process the 2 .tar.xz files and delete 1 (oldest)
477494 assert mock_unlink .call_count == 1
495+
496+ def test_cleanup_all_files_functionality (self , mock_config : BackupConfig ) -> None :
497+ """Test that cleanup_all deletes all files regardless of retention policy.
498+
499+ Args:
500+ mock_config: Mock backup configuration.
501+
502+ """
503+ command = CleanupCommand (mock_config , cleanup_all = True )
504+
505+ # Mock files for different extensions
506+ test_files = [
507+ "15-12-2024.tar.xz" ,
508+ "14-12-2024.tar.xz" ,
509+ "13-12-2024.tar.xz-decrypted" ,
510+ "12-12-2024.tar-extracted" ,
511+ "11-12-2024.tar.xz.enc" ,
512+ ]
513+
514+ with patch ("os.listdir" , return_value = test_files ), patch (
515+ "pathlib.Path.unlink"
516+ ) as mock_unlink , patch ("pathlib.Path.is_dir" , return_value = False ):
517+ command ._cleanup_all_files ()
518+
519+ # Should delete all files (4 calls for 4 different extensions)
520+ # Each extension will be processed, but only matching files deleted
521+ assert mock_unlink .call_count == len (test_files )
522+
523+ def test_execute_with_cleanup_all_calls_cleanup_all_files (
524+ self , mock_config : BackupConfig
525+ ) -> None :
526+ """Test that execute() calls _cleanup_all_files when cleanup_all is True.
527+
528+ Args:
529+ mock_config: Mock backup configuration.
530+
531+ """
532+ command = CleanupCommand (mock_config , cleanup_all = True )
533+
534+ with patch .object (command , "_cleanup_all_files" ) as mock_cleanup_all :
535+ result = command .execute ()
536+
537+ assert result is True
538+ mock_cleanup_all .assert_called_once ()
539+
540+ def test_execute_without_cleanup_all_calls_regular_cleanup (
541+ self , mock_config : BackupConfig
542+ ) -> None :
543+ """Test that execute() calls regular cleanup when cleanup_all is False.
544+
545+ Args:
546+ mock_config: Mock backup configuration.
547+
548+ """
549+ command = CleanupCommand (mock_config , cleanup_all = False )
550+
551+ with patch .object (command , "_cleanup_files" ) as mock_cleanup_files :
552+ result = command .execute ()
553+
554+ assert result is True
555+ # Should be called 4 times for different file extensions
556+ assert mock_cleanup_files .call_count == 4
0 commit comments