本文整理汇总了Python中tests.testcase.TestMode.need_recordingfile方法的典型用法代码示例。如果您正苦于以下问题:Python TestMode.need_recordingfile方法的具体用法?Python TestMode.need_recordingfile怎么用?Python TestMode.need_recordingfile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.testcase.TestMode
的用法示例。
在下文中一共展示了TestMode.need_recordingfile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sas_process
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recordingfile [as 别名]
def test_sas_process(self):
# SAS URL is calculated from storage key, so this test runs live only
if TestMode.need_recordingfile(self.test_mode):
return
# Arrange
queue_name = self._create_queue()
self.qs.put_message(queue_name, u'message1')
token = self.qs.generate_queue_shared_access_signature(
queue_name,
QueuePermissions.PROCESS,
datetime.utcnow() + timedelta(hours=1),
)
# Act
service = QueueService(
account_name=self.settings.STORAGE_ACCOUNT_NAME,
sas_token=token,
)
self._set_service_options(service, self.settings)
result = service.get_messages(queue_name)
# Assert
self.assertIsNotNone(result)
self.assertEqual(1, len(result))
message = result[0]
self.assertIsNotNone(message)
self.assertNotEqual('', message.id)
self.assertEqual(u'message1', message.content)
示例2: test_shared_access_share
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recordingfile [as 别名]
def test_shared_access_share(self):
# SAS URL is calculated from storage key, so this test runs live only
if TestMode.need_recordingfile(self.test_mode):
return
# Arrange
file_name = 'file1'
dir_name = 'dir1'
data = b'hello world'
share_name = self._create_share()
self.fs.create_directory(share_name, dir_name)
self.fs.create_file_from_bytes(share_name, dir_name, file_name, data)
token = self.fs.generate_share_shared_access_signature(
share_name,
expiry=datetime.utcnow() + timedelta(hours=1),
permission=SharePermissions.READ,
)
url = self.fs.make_file_url(
share_name,
dir_name,
file_name,
sas_token=token,
)
# Act
response = requests.get(url)
# Assert
self.assertTrue(response.ok)
self.assertEqual(data, response.content)
示例3: test_account_sas
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recordingfile [as 别名]
def test_account_sas(self):
# SAS URL is calculated from storage key, so this test runs live only
if TestMode.need_recordingfile(self.test_mode):
return
# Arrange
table_name = self._create_table()
entity = {"PartitionKey": "test", "RowKey": "test1", "text": "hello"}
self.ts.insert_entity(table_name, entity)
entity["RowKey"] = "test2"
self.ts.insert_entity(table_name, entity)
token = self.ts.generate_account_shared_access_signature(
ResourceTypes.OBJECT,
AccountPermissions.READ,
datetime.utcnow() + timedelta(hours=1),
datetime.utcnow() - timedelta(minutes=1),
)
# Act
service = TableService(account_name=self.settings.STORAGE_ACCOUNT_NAME, sas_token=token)
self._set_service_options(service, self.settings)
entities = list(service.query_entities(table_name))
# Assert
self.assertEqual(len(entities), 2)
self.assertEqual(entities[0].text, "hello")
self.assertEqual(entities[1].text, "hello")
示例4: test_sas_update
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recordingfile [as 别名]
def test_sas_update(self):
# SAS URL is calculated from storage key, so this test runs live only
if TestMode.need_recordingfile(self.test_mode):
return
# Arrange
entity = self._insert_random_entity()
token = self.ts.generate_table_shared_access_signature(
self.table_name,
TablePermissions.UPDATE,
datetime.utcnow() + timedelta(hours=1),
)
# Act
service = TableService(
account_name=self.settings.STORAGE_ACCOUNT_NAME,
sas_token=token,
)
self._set_service_options(service, self.settings)
updated_entity = self._create_updated_entity_dict(entity.PartitionKey, entity.RowKey)
resp = service.update_entity(self.table_name, updated_entity)
# Assert
received_entity = self.ts.get_entity(self.table_name, entity.PartitionKey, entity.RowKey)
self._assert_updated_entity(received_entity)
示例5: test_sas_add_inside_range
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recordingfile [as 别名]
def test_sas_add_inside_range(self):
# SAS URL is calculated from storage key, so this test runs live only
if TestMode.need_recordingfile(self.test_mode):
return
# Arrange
token = self.ts.generate_table_shared_access_signature(
self.table_name,
TablePermissions.ADD,
datetime.utcnow() + timedelta(hours=1),
start_pk='test', start_rk='test1',
end_pk='test', end_rk='test1',
)
# Act
service = TableService(
account_name=self.settings.STORAGE_ACCOUNT_NAME,
sas_token=token,
)
self._set_service_options(service, self.settings)
entity = self._create_random_entity_dict('test', 'test1')
service.insert_entity(self.table_name, entity)
# Assert
resp = self.ts.get_entity(self.table_name, 'test', 'test1')
self._assert_default_entity(resp)
示例6: test_sas_query
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recordingfile [as 别名]
def test_sas_query(self):
# SAS URL is calculated from storage key, so this test runs live only
if TestMode.need_recordingfile(self.test_mode):
return
# Arrange
entity = self._insert_random_entity()
token = self.ts.generate_table_shared_access_signature(
self.table_name,
TablePermissions.QUERY,
datetime.utcnow() + timedelta(hours=1),
datetime.utcnow() - timedelta(minutes=1),
)
# Act
service = TableService(
account_name=self.settings.STORAGE_ACCOUNT_NAME,
sas_token=token,
)
self._set_service_options(service, self.settings)
entities = list(self.ts.query_entities(self.table_name,
filter="PartitionKey eq '{}'".format(entity['PartitionKey'])))
# Assert
self.assertEqual(len(entities), 1)
self._assert_default_entity(entities[0])
示例7: test_generate_account_sas
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recordingfile [as 别名]
def test_generate_account_sas(self):
# SAS URL is calculated from storage key, so this test runs live only
if TestMode.need_recordingfile(self.test_mode):
return
# Arrange
token = self.account.generate_shared_access_signature(
Services.BLOB,
ResourceTypes.OBJECT,
AccountPermissions.READ,
datetime.utcnow() + timedelta(hours=1),
)
service = self.account.create_block_blob_service()
data = b'shared access signature with read permission on blob'
container_name='container1'
blob_name = 'blob1.txt'
try:
service.create_container(container_name)
service.create_blob_from_bytes(container_name, blob_name, data)
# Act
url = service.make_blob_url(
container_name,
blob_name,
sas_token=token,
)
response = requests.get(url)
# Assert
self.assertTrue(response.ok)
self.assertEqual(data, response.content)
finally:
service.delete_container(container_name)
示例8: test_sas_signed_identifier
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recordingfile [as 别名]
def test_sas_signed_identifier(self):
# SAS URL is calculated from storage key, so this test runs live only
if TestMode.need_recordingfile(self.test_mode):
return
# Arrange
entity = self._insert_random_entity()
access_policy = AccessPolicy()
access_policy.start = '2011-10-11'
access_policy.expiry = '2018-10-12'
access_policy.permission = TablePermissions.QUERY
identifiers = {'testid': access_policy}
entities = self.ts.set_table_acl(self.table_name, identifiers)
token = self.ts.generate_table_shared_access_signature(
self.table_name,
id='testid',
)
# Act
service = TableService(
account_name=self.settings.STORAGE_ACCOUNT_NAME,
sas_token=token,
)
self._set_service_options(service, self.settings)
entities = list(self.ts.query_entities(self.table_name, filter="PartitionKey eq '{}'".format(entity.PartitionKey)))
# Assert
self.assertEqual(len(entities), 1)
self._assert_default_entity(entities[0])
示例9: test_shared_read_access_blob
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recordingfile [as 别名]
def test_shared_read_access_blob(self):
# SAS URL is calculated from storage key, so this test runs live only
if TestMode.need_recordingfile(self.test_mode):
return
# Arrange
blob_name = self._create_block_blob()
token = self.bs.generate_blob_shared_access_signature(
self.container_name,
blob_name,
permission=BlobPermissions.READ,
expiry=datetime.utcnow() + timedelta(hours=1),
)
# Act
url = self.bs.make_blob_url(
self.container_name,
blob_name,
sas_token=token,
)
response = requests.get(url)
# Assert
self.assertTrue(response.ok)
self.assertEqual(self.byte_data, response.content)
示例10: test_shared_delete_access_blob
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recordingfile [as 别名]
def test_shared_delete_access_blob(self):
# SAS URL is calculated from storage key, so this test runs live only
if TestMode.need_recordingfile(self.test_mode):
return
# Arrange
blob_name = self._create_block_blob()
token = self.bs.generate_blob_shared_access_signature(
self.container_name,
blob_name,
permission=BlobPermissions.DELETE,
expiry=datetime.utcnow() + timedelta(hours=1),
)
url = self.bs.make_blob_url(
self.container_name,
blob_name,
sas_token=token,
)
# Act
response = requests.delete(url)
# Assert
self.assertTrue(response.ok)
with self.assertRaises(AzureMissingResourceHttpError):
blob = self.bs.get_blob_to_bytes(self.container_name, blob_name)
示例11: test_shared_read_access_blob_with_content_query_params
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recordingfile [as 别名]
def test_shared_read_access_blob_with_content_query_params(self):
# SAS URL is calculated from storage key, so this test runs live only
if TestMode.need_recordingfile(self.test_mode):
return
# Arrange
blob_name = self._create_block_blob()
token = self.bs.generate_blob_shared_access_signature(
self.container_name,
blob_name,
permission=BlobPermissions.READ,
expiry=datetime.utcnow() + timedelta(hours=1),
cache_control='no-cache',
content_disposition='inline',
content_encoding='utf-8',
content_language='fr',
content_type='text',
)
url = self.bs.make_blob_url(
self.container_name,
blob_name,
sas_token=token,
)
# Act
response = requests.get(url)
# Assert
self.assertEqual(self.byte_data, response.content)
self.assertEqual(response.headers['cache-control'], 'no-cache')
self.assertEqual(response.headers['content-disposition'], 'inline')
self.assertEqual(response.headers['content-encoding'], 'utf-8')
self.assertEqual(response.headers['content-language'], 'fr')
self.assertEqual(response.headers['content-type'], 'text')
示例12: test_shared_write_access_blob
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recordingfile [as 别名]
def test_shared_write_access_blob(self):
# SAS URL is calculated from storage key, so this test runs live only
if TestMode.need_recordingfile(self.test_mode):
return
# Arrange
updated_data = b'updated blob data'
blob_name = self._create_block_blob()
token = self.bs.generate_blob_shared_access_signature(
self.container_name,
blob_name,
permission=BlobPermissions.WRITE,
expiry=datetime.utcnow() + timedelta(hours=1),
)
url = self.bs.make_blob_url(
self.container_name,
blob_name,
sas_token=token,
)
# Act
headers = {'x-ms-blob-type': self.bs.blob_type}
response = requests.put(url, headers=headers, data=updated_data)
# Assert
self.assertTrue(response.ok)
blob = self.bs.get_blob_to_bytes(self.container_name, blob_name)
self.assertEqual(updated_data, blob.content)
示例13: test_get_blob_to_stream_with_progress_parallel
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recordingfile [as 别名]
def test_get_blob_to_stream_with_progress_parallel(self):
# parallel tests introduce random order of requests, can only run live
if TestMode.need_recordingfile(self.test_mode):
return
# Arrange
# Act
progress = []
def callback(current, total):
progress.append((current, total))
with open(FILE_PATH, 'wb') as stream:
blob = self.bs.get_blob_to_stream(
self.container_name, self.byte_blob, stream,
progress_callback=callback,
max_connections=5)
# Assert
self.assertIsInstance(blob, Blob)
with open(FILE_PATH, 'rb') as stream:
actual = stream.read()
self.assertEqual(self.byte_data, actual)
self.assert_download_progress(len(self.byte_data), self.bs.MAX_CHUNK_GET_SIZE, progress, single_download=False)
示例14: test_sas_signed_identifier
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recordingfile [as 别名]
def test_sas_signed_identifier(self):
# SAS URL is calculated from storage key, so this test runs live only
if TestMode.need_recordingfile(self.test_mode):
return
# Arrange
blob_name = self._create_block_blob()
access_policy = AccessPolicy()
access_policy.start = '2011-10-11'
access_policy.expiry = '2018-10-12'
access_policy.permission = BlobPermissions.READ
identifiers = {'testid': access_policy}
resp = self.bs.set_container_acl(self.container_name, identifiers)
token = self.bs.generate_blob_shared_access_signature(
self.container_name,
blob_name,
id='testid'
)
# Act
service = BlockBlobService(
self.settings.STORAGE_ACCOUNT_NAME,
sas_token=token,
request_session=requests.Session(),
)
self._set_service_options(service, self.settings)
result = service.get_blob_to_bytes(self.container_name, blob_name)
# Assert
self.assertEqual(self.byte_data, result.content)
示例15: test_sas_update
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recordingfile [as 别名]
def test_sas_update(self):
# SAS URL is calculated from storage key, so this test runs live only
if TestMode.need_recordingfile(self.test_mode):
return
# Arrange
queue_name = self._create_queue()
self.qs.put_message(queue_name, u'message1')
token = self.qs.generate_queue_shared_access_signature(
queue_name,
QueuePermissions.UPDATE,
datetime.utcnow() + timedelta(hours=1),
)
result = self.qs.get_messages(queue_name)
# Act
service = QueueService(
account_name=self.settings.STORAGE_ACCOUNT_NAME,
sas_token=token,
)
self._set_service_options(service, self.settings)
service.update_message(
queue_name,
result[0].id,
result[0].pop_receipt,
visibility_timeout=0,
content=u'updatedmessage1',
)
# Assert
result = self.qs.get_messages(queue_name)
self.assertEqual(u'updatedmessage1', result[0].content)