def test_remote_cancel_during_transfer( self, is_cancelled_mock, cancel_mock, FileDownloadMock, local_path_mock, remote_path_mock, start_progress_mock, import_channel_mock, ): local_path = tempfile.mkstemp()[1] local_path_mock.return_value = local_path remote_path_mock.return_value = "notest" FileDownloadMock.return_value.__iter__.side_effect = TransferCanceled() call_command("importchannel", "network", self.the_channel_id) # Check that is_cancelled was called is_cancelled_mock.assert_called_with() # Check that the FileDownload initiated FileDownloadMock.assert_called_with( "notest", local_path, cancel_check=is_cancelled_mock ) # Check that cancel was called cancel_mock.assert_called_with() # Test that import channel cleans up database file if cancelled self.assertFalse(os.path.exists(local_path))
def test_remote_cancel_during_transfer( self, is_cancelled_mock, cancel_mock, FileDownloadMock, local_path_mock, remote_path_mock, annotation_mock, get_import_export_mock, channel_list_status_mock, ): # If transfer is cancelled during transfer of first file local_path = tempfile.mkstemp()[1] local_path_mock.return_value = local_path remote_path_mock.return_value = "notest" # Mock this __iter__ so that the filetransfer can be looped over FileDownloadMock.return_value.__iter__.side_effect = TransferCanceled() get_import_export_mock.return_value = (1, list(LocalFile.objects.all()), 10) call_command("importcontent", "network", self.the_channel_id) # is_cancelled should be called thrice. is_cancelled_mock.assert_has_calls([call(), call()]) # Should be set to the local path we mocked FileDownloadMock.assert_called_with( "notest", local_path, session=Any(Session), cancel_check=is_cancelled_mock ) # Check that the command itself was also cancelled. cancel_mock.assert_called_with() annotation_mock.mark_local_files_as_available.assert_not_called() annotation_mock.set_leaf_node_availability_from_local_file_availability.assert_not_called() annotation_mock.recurse_annotation_up_tree.assert_not_called()
def test_local_cancel_during_transfer( self, is_cancelled_mock, cancel_mock, FileCopyMock, local_path_mock, start_progress_mock, import_channel_mock, ): local_dest_path = tempfile.mkstemp()[1] local_src_path = tempfile.mkstemp()[1] local_path_mock.side_effect = [local_dest_path, local_src_path] FileCopyMock.return_value.__iter__.side_effect = TransferCanceled() call_command("importchannel", "disk", self.the_channel_id, tempfile.mkdtemp()) # Check that is_cancelled was called is_cancelled_mock.assert_called_with() # Check that the FileCopy initiated FileCopyMock.assert_called_with(local_src_path, local_dest_path, cancel_check=is_cancelled_mock) # Check that cancel was called cancel_mock.assert_called_with() # Test that import channel cleans up database file if cancelled self.assertFalse(os.path.exists(local_dest_path))
def test_local_cancel_immediately(self, is_cancelled_mock, cancel_mock, FileCopyMock): # If cancel comes in before we do anything, make sure nothing happens! FileCopyMock.return_value.__iter__.side_effect = TransferCanceled() call_command("exportcontent", self.the_channel_id, tempfile.mkdtemp()) is_cancelled_mock.assert_has_calls([call()]) FileCopyMock.assert_not_called() cancel_mock.assert_called_with()
def test_local_cancel_during_transfer( self, is_cancelled_mock, cancel_mock, FileCopyMock, local_path_mock, start_progress_mock, ): # Make sure we cancel during transfer local_dest_path = tempfile.mkstemp()[1] local_src_path = tempfile.mkstemp()[1] local_path_mock.side_effect = [local_src_path, local_dest_path] FileCopyMock.return_value.__iter__.side_effect = TransferCanceled() call_command("exportcontent", self.the_channel_id, tempfile.mkdtemp()) is_cancelled_mock.assert_has_calls([call(), call(), call()]) FileCopyMock.assert_called_with(local_src_path, local_dest_path, cancel_check=is_cancelled_mock) cancel_mock.assert_called_with()
def test_cancel_during_transfer( self, is_cancelled_mock, cancel_mock, FileCopyMock, local_path_mock, start_progress_mock, ): # Make sure we clean up a database file that is canceled during export local_dest_path = tempfile.mkstemp()[1] local_src_path = tempfile.mkstemp()[1] local_path_mock.side_effect = [local_src_path, local_dest_path] FileCopyMock.return_value.__iter__.side_effect = TransferCanceled() call_command("exportchannel", self.the_channel_id, local_dest_path) is_cancelled_mock.assert_called_with() FileCopyMock.assert_called_with( local_src_path, local_dest_path, cancel_check=is_cancelled_mock ) cancel_mock.assert_called_with() self.assertFalse(os.path.exists(local_dest_path))
def test_local_cancel_during_transfer( self, is_cancelled_mock, cancel_mock, FileCopyMock, local_path_mock, annotation_mock, get_import_export_mock, channel_list_status_mock, ): # Local version of test above local_dest_path = tempfile.mkstemp()[1] local_src_path = tempfile.mkstemp()[1] local_path_mock.side_effect = [local_dest_path, local_src_path] FileCopyMock.return_value.__iter__.side_effect = TransferCanceled() get_import_export_mock.return_value = (1, list(LocalFile.objects.all()), 10) call_command("importcontent", "disk", self.the_channel_id, tempfile.mkdtemp()) is_cancelled_mock.assert_has_calls([call(), call()]) FileCopyMock.assert_called_with( local_src_path, local_dest_path, cancel_check=is_cancelled_mock ) cancel_mock.assert_called_with() annotation_mock.set_content_visibility.assert_called()