def exist_az_file(file_client: ShareFileClient) -> bool: """Check if existed Azure File. :param file_client: :type file_client: ShareClient :return: True if Azure file is existed. """ try: file_client.get_file_properties() return True except ResourceNotFoundError: return False
def test_get_file_range_with_md5(self): # parallel tests introduce random order of requests, can only run live if TestMode.need_recording_file(self.test_mode): return file_client = ShareFileClient( self.get_file_url(), share_name=self.share_name, file_path=self.directory_name + '/' + self.byte_file, credential=self.settings.STORAGE_ACCOUNT_KEY, max_single_get_size=self.MAX_SINGLE_GET_SIZE, max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) file_content = file_client.download_file(offset=0, length=1024, validate_content=True) # Assert self.assertIsNone(file_content.properties.content_settings.content_md5) # Arrange props = file_client.get_file_properties() props.content_settings.content_md5 = b'MDAwMDAwMDA=' file_client.set_http_headers(props.content_settings) # Act file_content = file_client.download_file(offset=0, length=1024, validate_content=True) # Assert self.assertEqual(b'MDAwMDAwMDA=', file_content.properties.content_settings.content_md5)
def test_old_api_copy_file_succeeds(self, resource_group, location, storage_account, storage_account_key): fsc = ShareServiceClient(self.account_url(storage_account, "file"), credential=storage_account_key, max_range_size=4 * 1024, api_version=self.api_version_1) share = self._create_share(fsc) file_name = self._get_file_reference() source_client = share.get_file_client(file_name) source_client.upload_file(self.short_byte_data) source_prop = source_client.get_file_properties() file_client = ShareFileClient(self.account_url(storage_account, "file"), share_name=share.share_name, file_path='file1copy', credential=storage_account_key, api_version=self.api_version_1) # Act copy = file_client.start_copy_from_url(source_client.url) # Assert dest_prop = file_client.get_file_properties() # to make sure the acl is copied from source self.assertEqual(source_prop['permission_key'], dest_prop['permission_key']) self.assertIsNotNone(copy) self.assertEqual(copy['copy_status'], 'success') self.assertIsNotNone(copy['copy_id']) copy_file = file_client.download_file().readall() self.assertEqual(copy_file, self.short_byte_data)
def test_get_file_properties_server_encryption(self): # Arrange file_client = ShareFileClient( self.get_file_url(), share_name=self.share_name, file_path=self.directory_name + '/' + self.byte_file, credential=self.settings.STORAGE_ACCOUNT_KEY, max_single_get_size=self.MAX_SINGLE_GET_SIZE, max_chunk_get_size=self.MAX_CHUNK_GET_SIZE) # Act props = file_client.get_file_properties() # Assert if self.is_file_encryption_enabled(): self.assertTrue(props.server_encrypted) else: self.assertFalse(props.server_encrypted)