def test_abort_copy_file(self): # Arrange data = b'12345678' * 1024 * 1024 self._create_remote_share() source_file = self._create_remote_file(file_data=data) sas_token = source_file.generate_shared_access_signature( permission=FilePermissions.READ, expiry=datetime.utcnow() + timedelta(hours=1), ) source_url = source_file.url + '?' + sas_token # Act target_file_name = 'targetfile' file_client = FileClient( self.get_file_url(), share=self.share_name, file_path=target_file_name, credential=self.settings.STORAGE_ACCOUNT_KEY) copy_resp = file_client.start_copy_from_url(source_url) self.assertEqual(copy_resp['copy_status'], 'pending') file_client.abort_copy(copy_resp) # Assert target_file = file_client.download_file() self.assertEqual(target_file.content_as_bytes(), b'') self.assertEqual(target_file.properties.copy.status, 'aborted')
def test_abort_copy_file_with_synchronous_copy_fails(self): # Arrange source_file = self._create_file() # Act target_file_name = 'targetfile' file_client = FileClient( self.get_file_url(), share=self.share_name, file_path=target_file_name, credential=self.settings.STORAGE_ACCOUNT_KEY) copy_resp = file_client.start_copy_from_url(source_file.url) with self.assertRaises(HttpResponseError): file_client.abort_copy(copy_resp) # Assert self.assertEqual(copy_resp['copy_status'], 'success')