示例#1
0
    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.copy_file_from_url(source_url)
        self.assertEqual(copy_resp.status(), 'pending')
        copy_resp.abort()

        # Assert
        target_file = file_client.download_file()
        self.assertEqual(target_file.content_as_bytes(), b'')
        self.assertEqual(target_file.properties.copy.status, 'aborted')
示例#2
0
    def test_copy_file_async_private_file_with_sas(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.copy_file_from_url(source_url)

        # Assert
        status = copy_resp.status()
        self.assertTrue(status in ['success', 'pending'])
        if status == 'pending':
            copy_resp.wait()

        actual_data = file_client.download_file().content_as_bytes()
        self.assertEqual(actual_data, data)
示例#3
0
    def test_copy_file_async_private_file(self):
        # Arrange
        self._create_remote_share()
        source_file = self._create_remote_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)
        with self.assertRaises(HttpResponseError) as e:
            file_client.copy_file_from_url(source_file.url)

        # Assert
        self.assertEqual(e.exception.error_code,
                         StorageErrorCode.cannot_verify_copy_source)
示例#4
0
    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.copy_file_from_url(source_file.url)

        with self.assertRaises(HttpResponseError):
            copy_resp.abort()

        # Assert
        self.assertEqual(copy_resp.status(), 'success')
示例#5
0
    def test_copy_file_with_existing_file(self):
        # Arrange
        source_client = self._create_file()
        file_client = FileClient(self.get_file_url(),
                                 share=self.share_name,
                                 file_path='file1copy',
                                 credential=self.settings.STORAGE_ACCOUNT_KEY)

        # Act
        copy = file_client.copy_file_from_url(source_client.url)

        # Assert
        self.assertIsNotNone(copy)
        self.assertEqual(copy.status(), 'success')
        self.assertIsNotNone(copy.copy_id())

        copy_file = file_client.download_file().content_as_bytes()
        self.assertEqual(copy_file, self.short_byte_data)