From c5cae35a2a22df802f0b240a4e5b3c0b74a52a95 Mon Sep 17 00:00:00 2001 From: ChristianOertlin Date: Fri, 10 Nov 2023 10:19:03 +0100 Subject: [PATCH] fix(relax clean flow cell criteria) (#2677) (patch) # Description relaxes criteria required to pass for deletion of a flow cell. Now either fastq files or spring files have to be present in housekeeper. --- cg/meta/clean/clean_flow_cells.py | 8 +- tests/meta/clean/test_clean_flow_cells_api.py | 73 +++++++++++++++++++ 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/cg/meta/clean/clean_flow_cells.py b/cg/meta/clean/clean_flow_cells.py index 9382972ca9..b1479b814e 100644 --- a/cg/meta/clean/clean_flow_cells.py +++ b/cg/meta/clean/clean_flow_cells.py @@ -76,9 +76,11 @@ def can_flow_cell_directory_be_deleted(self) -> bool: self.is_flow_cell_in_statusdb(), self.is_flow_cell_backed_up(), self.has_sequencing_metrics_in_statusdb(), - self.has_fastq_files_for_samples_in_housekeeper(), - self.has_spring_meta_data_files_for_samples_in_housekeeper(), - self.has_spring_files_for_samples_in_housekeeper(), + self.has_fastq_files_for_samples_in_housekeeper() + or ( + self.has_spring_meta_data_files_for_samples_in_housekeeper() + and self.has_spring_files_for_samples_in_housekeeper() + ), self.has_sample_sheet_in_housekeeper(), ] ) diff --git a/tests/meta/clean/test_clean_flow_cells_api.py b/tests/meta/clean/test_clean_flow_cells_api.py index 9a971cf7aa..8f31279a97 100644 --- a/tests/meta/clean/test_clean_flow_cells_api.py +++ b/tests/meta/clean/test_clean_flow_cells_api.py @@ -172,6 +172,79 @@ def test_can_flow_cell_be_deleted(flow_cell_clean_api_can_be_removed: CleanFlowC assert can_be_deleted +def test_can_flow_cell_be_deleted_no_spring_with_fastq( + flow_cell_clean_api_can_be_removed: CleanFlowCellAPI, +): + """Test that a flow cell can be deleted when it has fastq files but no spring files.""" + # GIVEN a flow cell that can be deleted + + with mock.patch( + "cg.meta.clean.clean_flow_cells.CleanFlowCellAPI.is_directory_older_than_21_days", + return_value=True, + ): + with mock.patch( + "cg.meta.clean.clean_flow_cells.CleanFlowCellAPI.has_spring_meta_data_files_for_samples_in_housekeeper", + return_value=False, + ): + # WHEN checking that the flow cell can be deleted + can_be_deleted: bool = ( + flow_cell_clean_api_can_be_removed.can_flow_cell_directory_be_deleted() + ) + + # THEN the check whether the flow cell can be deleted returns True + assert can_be_deleted + + +def test_can_flow_cell_be_deleted_spring_no_fastq( + flow_cell_clean_api_can_be_removed: CleanFlowCellAPI, +): + """Test that a flow cell can be deleted when it has spring files but no fastq files.""" + # GIVEN a flow cell that can be deleted + + with mock.patch( + "cg.meta.clean.clean_flow_cells.CleanFlowCellAPI.is_directory_older_than_21_days", + return_value=True, + ): + with mock.patch( + "cg.meta.clean.clean_flow_cells.CleanFlowCellAPI.has_fastq_files_for_samples_in_housekeeper", + return_value=False, + ): + # WHEN checking that the flow cell can be deleted + can_be_deleted: bool = ( + flow_cell_clean_api_can_be_removed.can_flow_cell_directory_be_deleted() + ) + + # THEN the check whether the flow cell can be deleted returns True + assert can_be_deleted + + +def test_can_flow_cell_be_deleted_no_spring_no_fastq( + flow_cell_clean_api_can_be_removed: CleanFlowCellAPI, +): + """Test that a flow cell can not be deleted when it has no spring files and no fastq files.""" + # GIVEN a flow cell that can be deleted + + with mock.patch( + "cg.meta.clean.clean_flow_cells.CleanFlowCellAPI.is_directory_older_than_21_days", + return_value=True, + ): + with mock.patch( + "cg.meta.clean.clean_flow_cells.CleanFlowCellAPI.has_fastq_files_for_samples_in_housekeeper", + return_value=False, + ): + with mock.patch( + "cg.meta.clean.clean_flow_cells.CleanFlowCellAPI.has_spring_meta_data_files_for_samples_in_housekeeper", + return_value=False, + ): + # WHEN checking that the flow cell can be deleted + can_be_deleted: bool = ( + flow_cell_clean_api_can_be_removed.can_flow_cell_directory_be_deleted() + ) + + # THEN the check whether the flow cell can be deleted returns True + assert not can_be_deleted + + def test_delete_flow_cell_directory(flow_cell_clean_api_can_be_removed: CleanFlowCellAPI): """Test that a flow cell directory is removed.""" # GIVEN a flow cell that can be removed