def test_shared_access_share(self): # SAS URL is calculated from storage key, so this test runs live only if TestMode.need_recording_file(self.test_mode): return # Arrange file_name = 'file1' dir_name = 'dir1' data = b'hello world' share = self._create_share() dir1 = share.create_directory(dir_name) dir1.upload_file(file_name, data) token = share.generate_shared_access_signature( expiry=datetime.utcnow() + timedelta(hours=1), permission=SharePermissions.READ, ) sas_client = FileClient( self.get_file_url(), share=share.share_name, file_path=dir_name + '/' + file_name, credential=token, ) # Act print(sas_client.url) response = requests.get(sas_client.url) # Assert self.assertTrue(response.ok) self.assertEqual(data, response.content)
def test_file_sas_from_FileClient(storage_account, sas_token): f = FileClient( f"https://{storage_account}.file.core.windows.net/", share=SHARE_NAME, file_path=FILE_NAME, credential=sas_token, ) assert "??" not in f.url
def test_file_sas_from_FileClient_with_file_url(storage_account, sas_token): f = FileClient( f"https://{storage_account}.file.core.windows.net/{SHARE_NAME}/{FILE_NAME}", credential=sas_token, ) assert "??" not in f.url