def test_upload_no_files(self): # Call under test ret_val = uploader.upload([]) self.assertEqual(ret_val, uploader.UploadErrors()) # First thing called by _upload_single is _get_client # Assert that no clients were created uploader.datastore.Client.assert_not_called()
def test_heal_files_failed_to_delete(self): num_files = 5 self._write_files(num_files, num_not_ready=0) errors = uploader.UploadErrors() errors.failed_to_delete = self._temp_files self.assertEqual(len(os.listdir(self.directory)), num_files) # Call under test uploader.heal(errors) self.assertEqual(len(os.listdir(self.directory)), 0) self._temp_files = list()
def test_heal_files_failed_to_record_success_in_ds(self): temp = uploader._record_status_in_datastore uploader._record_status_in_datastore = Mock() fnames = self._get_file_names(5) for success in (True, False): errors = uploader.UploadErrors() if success: errors.datastore_success = fnames else: errors.datastore_failure = fnames # Call under test uploader.heal(errors) uploader._record_status_in_datastore.assert_called_with( fnames, success=success) # Clean up uploader._record_status_in_datastore = temp
def test_heal_files_failed_to_upload(self): temp = uploader._record_status_in_datastore uploader._record_status_in_datastore = Mock() fnames = self._get_file_names(5) errors = uploader.UploadErrors() errors.failed_to_upload = fnames pool = Mock() # Don't care about the return value here, just that it is iterable # so that uploader.upload doesn't complain pool.map = Mock(return_value=[]) uploader.Pool = Mock(return_value=pool) # Call under test uploader.heal(errors) # Ensure upload was called correctly pool.map.assert_called_with(uploader._upload_single, fnames) # Clean up uploader._record_status_in_datastore = temp