本文整理汇总了Python中tests.testcase.TestMode.need_recording_file方法的典型用法代码示例。如果您正苦于以下问题:Python TestMode.need_recording_file方法的具体用法?Python TestMode.need_recording_file怎么用?Python TestMode.need_recording_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.testcase.TestMode
的用法示例。
在下文中一共展示了TestMode.need_recording_file方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_account_sas
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recording_file [as 别名]
def test_account_sas(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 = self._create_file()
token = self.fs.generate_account_shared_access_signature(
ResourceTypes.OBJECT,
AccountPermissions.READ,
datetime.utcnow() + timedelta(hours=1),
)
# Act
url = self.fs.make_file_url(
self.share_name,
None,
file_name,
sas_token=token,
)
response = requests.get(url)
# Assert
self.assertTrue(response.ok)
self.assertEqual(self.short_byte_data, response.content)
示例2: test_shared_read_access_blob
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recording_file [as 别名]
def test_shared_read_access_blob(self):
# SAS URL is calculated from storage key, so this test runs live only
if TestMode.need_recording_file(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)
示例3: test_create_blob_from_stream_with_progress_truncated
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recording_file [as 别名]
def test_create_blob_from_stream_with_progress_truncated(self):
# parallel tests introduce random order of requests, can only run live
if TestMode.need_recording_file(self.test_mode):
return
# Arrange
blob_name = self._get_blob_reference()
data = self.get_random_bytes(LARGE_BLOB_SIZE)
with open(FILE_PATH, 'wb') as stream:
stream.write(data)
# Act
progress = []
def callback(current, total):
progress.append((current, total))
blob_size = len(data) - 512
with open(FILE_PATH, 'rb') as stream:
self.bs.create_blob_from_stream(self.container_name, blob_name, stream,
blob_size, progress_callback=callback)
# Assert
self.assertBlobEqual(self.container_name, blob_name, data[:blob_size])
self.assert_upload_progress(blob_size, self.bs.MAX_PAGE_SIZE, progress)
示例4: test_get_blob_range_with_range_md5
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recording_file [as 别名]
def test_get_blob_range_with_range_md5(self):
# parallel tests introduce random order of requests, can only run live
if TestMode.need_recording_file(self.test_mode):
return
blob = self.bs.get_blob_to_bytes(self.container_name, self.byte_blob, start_range=0,
end_range=1024, validate_content=True)
# Arrange
props = self.bs.get_blob_properties(self.container_name, self.byte_blob)
props.properties.content_settings.content_md5 = None;
self.bs.set_blob_properties(self.container_name, self.byte_blob, props.properties.content_settings)
# Act
blob = self.bs.get_blob_to_bytes(self.container_name, self.byte_blob, start_range=0,
end_range=1024, validate_content=True)
# Assert
self.assertTrue(hasattr(blob.properties.content_settings, "content_type"));
self.assertFalse(hasattr(blob.properties.content_settings, "content_md5"));
# Act
blob = self.bs.get_blob_to_bytes(self.container_name, self.byte_blob, start_range=0,
end_range=1024, validate_content=True)
# Assert
self.assertTrue(hasattr(blob.properties.content_settings, "content_type"));
self.assertFalse(hasattr(blob.properties.content_settings, "content_md5"));
示例5: test_sas_process
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recording_file [as 别名]
def test_sas_process(self):
# SAS URL is calculated from storage key, so this test runs live only
if TestMode.need_recording_file(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)
示例6: test_shared_write_access_file
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recording_file [as 别名]
def test_shared_write_access_file(self):
# SAS URL is calculated from storage key, so this test runs live only
if TestMode.need_recording_file(self.test_mode):
return
# Arrange
updated_data = b'updated file data'
file_name = self._create_file()
token = self.fs.generate_file_shared_access_signature(
self.share_name,
None,
file_name,
permission=FilePermissions.WRITE,
expiry=datetime.utcnow() + timedelta(hours=1),
)
url = self.fs.make_file_url(
self.share_name,
None,
file_name,
sas_token=token,
)
# Act
headers={'x-ms-range': 'bytes=0-16', 'x-ms-write': 'update'}
response = requests.put(url + '&comp=range', headers=headers, data=updated_data)
# Assert
self.assertTrue(response.ok)
file = self.fs.get_file_to_bytes(self.share_name, None, file_name)
self.assertEqual(updated_data, file.content[:len(updated_data)])
示例7: test_sas_signed_identifier
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recording_file [as 别名]
def test_sas_signed_identifier(self):
# SAS URL is calculated from storage key, so this test runs live only
if TestMode.need_recording_file(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])
示例8: test_sas_update
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recording_file [as 别名]
def test_sas_update(self):
# SAS URL is calculated from storage key, so this test runs live only
if TestMode.need_recording_file(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)
示例9: test_sas_upper_case_table_name
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recording_file [as 别名]
def test_sas_upper_case_table_name(self):
# SAS URL is calculated from storage key, so this test runs live only
if TestMode.need_recording_file(self.test_mode):
return
# Arrange
entity = self._insert_random_entity()
# Table names are case insensitive, so simply upper case our existing table name to test
token = self.ts.generate_table_shared_access_signature(
self.table_name.upper(),
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(service.query_entities(self.table_name,
filter="PartitionKey eq '{}'".format(entity['PartitionKey'])))
# Assert
self.assertEqual(len(entities), 1)
self._assert_default_entity(entities[0])
示例10: test_sas_update
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recording_file [as 别名]
def test_sas_update(self):
# SAS URL is calculated from storage key, so this test runs live only
if TestMode.need_recording_file(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)
示例11: test_sas_add_inside_range
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recording_file [as 别名]
def test_sas_add_inside_range(self):
# SAS URL is calculated from storage key, so this test runs live only
if TestMode.need_recording_file(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)
示例12: test_create_file_from_stream_with_progress_truncated
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recording_file [as 别名]
def test_create_file_from_stream_with_progress_truncated(self):
# parallel tests introduce random order of requests, can only run live
if TestMode.need_recording_file(self.test_mode):
return
# Arrange
file_name = self._get_file_reference()
data = self.get_random_bytes(LARGE_FILE_SIZE)
with open(INPUT_FILE_PATH, 'wb') as stream:
stream.write(data)
# Act
progress = []
def callback(current, total):
progress.append((current, total))
file_size = len(data) - 5
with open(INPUT_FILE_PATH, 'rb') as stream:
self.fs.create_file_from_stream(self.share_name, None, file_name, stream,
file_size, progress_callback=callback)
# Assert
self.assertFileEqual(self.share_name, None, file_name, data[:file_size])
self.assert_upload_progress(file_size, self.fs.MAX_RANGE_SIZE, progress, unknown_size=False)
示例13: test_account_sas
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recording_file [as 别名]
def test_account_sas(self):
# SAS URL is calculated from storage key, so this test runs live only
if TestMode.need_recording_file(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")
示例14: test_shared_delete_access_blob
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recording_file [as 别名]
def test_shared_delete_access_blob(self):
# SAS URL is calculated from storage key, so this test runs live only
if TestMode.need_recording_file(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)
示例15: test_shared_write_access_blob
# 需要导入模块: from tests.testcase import TestMode [as 别名]
# 或者: from tests.testcase.TestMode import need_recording_file [as 别名]
def test_shared_write_access_blob(self):
# SAS URL is calculated from storage key, so this test runs live only
if TestMode.need_recording_file(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)