def test_file_sas_from_FileServiceClient(storage_account, sas_token):
    service = FileServiceClient(
        f"https://{storage_account}.file.core.windows.net/",
        credential=sas_token)
    share = service.get_share_client(SHARE_NAME)
    f = share.get_file_client(FILE_NAME)
    assert "??" not in f.url
    def test_user_agent_custom(self):
        custom_app = "TestApp/v1.0"
        service = FileServiceClient(self.get_file_url(),
                                    credential=self.account_key,
                                    user_agent=custom_app)

        def callback1(response):
            self.assertTrue('User-Agent' in response.http_request.headers)
            self.assertEqual(
                response.http_request.headers['User-Agent'],
                "TestApp/v1.0 azsdk-python-storage-file/{} Python/{} ({})".
                format(VERSION, platform.python_version(),
                       platform.platform()))

        service.get_service_properties(raw_response_hook=callback1)

        def callback2(response):
            self.assertTrue('User-Agent' in response.http_request.headers)
            self.assertEqual(
                response.http_request.headers['User-Agent'],
                "TestApp/v2.0 azsdk-python-storage-file/{} Python/{} ({})".
                format(VERSION, platform.python_version(),
                       platform.platform()))

        service.get_service_properties(raw_response_hook=callback2,
                                       user_agent="TestApp/v2.0")
    def test_client_request_id_echo(self):
        # client request id is different for every request, so it will never match the recorded one
        if TestMode.need_recording_file(self.test_mode):
            return

        # Arrange
        request_id_header_name = 'x-ms-client-request-id'
        service = FileServiceClient(self.get_file_url(),
                                    credential=self.account_key)

        # Act make the client request ID slightly different
        def callback(response):
            response.http_response.status_code = 200
            response.http_response.headers[request_id_header_name] += '1'

        # Assert the client request ID validation is working
        with self.assertRaises(AzureError):
            service.get_service_properties(raw_response_hook=callback)

        # Act remove the echoed client request ID
        def callback(response):
            response.status_code = 200
            del response.http_response.headers[request_id_header_name]

        # Assert the client request ID validation is not throwing when the ID is not echoed
        service.get_service_properties(raw_response_hook=callback)
    def setUp(self):
        super(StorageShareTest, self).setUp()

        file_url = self.get_file_url()
        credentials = self.get_shared_key_credential()
        self.fsc = FileServiceClient(account_url=file_url,
                                     credential=credentials)
        self.test_shares = []
    def test_auth_shared_key(self):
        # Instantiate a FileServiceClient using a shared access key
        # [START create_file_service_client]
        from azure.storage.file import FileServiceClient
        file_service_client = FileServiceClient(account_url=self.url, credential=self.shared_access_key)
        # [END create_file_service_client]

        # Get account information for the File Service
        account_info = file_service_client.get_service_properties()
        assert account_info is not None
    def setUp(self):
        super(StorageDirectoryTest, self).setUp()

        url = self.get_file_url()
        credential = self.get_shared_key_credential()
        self.fsc = FileServiceClient(url, credential=credential)
        self.share_name = self.get_resource_name('utshare')

        if not self.is_playback():
            self.fsc.create_share(self.share_name)
Example #7
0
    def setUp(self):
        super(StorageFileTest, self).setUp()

        url = self.get_file_url()
        credential = self.get_shared_key_credential()

        # test chunking functionality by reducing the threshold
        # for chunking and the size of each chunk, otherwise
        # the tests would take too long to execute
        self.fsc = FileServiceClient(url, credential=credential, max_range_size=4 * 1024)
        self.share_name = self.get_resource_name('utshare')
        if not self.is_playback():
            self.fsc.create_share(self.share_name)

        self.short_byte_data = self.get_random_bytes(1024)

        remote_url = self.get_remote_file_url()
        remote_credential = self.get_remote_shared_key_credential()
        self.fsc2 = FileServiceClient(remote_url, credential=remote_credential)
        self.remote_share_name = None
    def test_user_agent_default(self):
        service = FileServiceClient(self.get_file_url(),
                                    credential=self.account_key)

        def callback(response):
            self.assertTrue('User-Agent' in response.http_request.headers)
            self.assertEqual(
                response.http_request.headers['User-Agent'],
                "azsdk-python-storage-file/{} Python/{} ({})".format(
                    VERSION, platform.python_version(), platform.platform()))

        service.get_service_properties(raw_response_hook=callback)
    def test_user_agent_append(self):
        service = FileServiceClient(self.get_file_url(), credential=self.account_key)

        def callback(response):
            self.assertTrue('User-Agent' in response.http_request.headers)
            self.assertEqual(
                response.http_request.headers['User-Agent'],
                "azsdk-python-storage-file/12.0.0b1 Python/{} ({}) customer_user_agent".format(
                    platform.python_version(),
                    platform.platform()))

        custom_headers = {'User-Agent': 'customer_user_agent'}
        service.get_service_properties(raw_response_hook=callback, headers=custom_headers)
Example #10
0
    def test_make_file_url_with_protocol(self):
        # Arrange
        url = self.get_file_url().replace('https', 'http')
        fsc = FileServiceClient(url, credential=self.settings.STORAGE_ACCOUNT_KEY)
        share = fsc.get_share_client("vhds")
        file_client = share.get_file_client("vhd_dir/my.vhd")

        # Act
        res = file_client.url

        # Assert
        self.assertEqual(res, 'http://' + self.settings.STORAGE_ACCOUNT_NAME
                         + '.file.core.windows.net/vhds/vhd_dir/my.vhd')
Example #11
0
 def test_transport_closed_only_once(self):
     if TestMode.need_recording_file(self.test_mode):
         return
     transport = RequestsTransport()
     url = self.get_file_url()
     credential = self.get_shared_key_credential()
     prefix = TEST_SHARE_PREFIX
     share_name = self.get_resource_name(prefix)
     with FileServiceClient(url, credential=credential,
                            transport=transport) as fsc:
         fsc.get_service_properties()
         assert transport.session is not None
         with fsc.get_share_client(share_name) as fc:
             assert transport.session is not None
         fsc.get_service_properties()
         assert transport.session is not None
    def setUp(self):
        super(FileServicePropertiesTest, self).setUp()

        url = self.get_file_url()
        credential = self.get_shared_key_credential()
        self.fsc = FileServiceClient(url, credential=credential)