本文整理汇总了Python中conftest.Mock.read_from_file方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.read_from_file方法的具体用法?Python Mock.read_from_file怎么用?Python Mock.read_from_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类conftest.Mock
的用法示例。
在下文中一共展示了Mock.read_from_file方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_attach_and_detach_storage
# 需要导入模块: from conftest import Mock [as 别名]
# 或者: from conftest.Mock import read_from_file [as 别名]
def test_attach_and_detach_storage(self, manager):
data = Mock.mock_get('server/00798b85-efdc-41ca-8021-f6ef457b8531')
server = manager.get_server('00798b85-efdc-41ca-8021-f6ef457b8531')
assert len(server.storage_devices) == 1
assert server.storage_devices[0].title == 'Storage for server1.example.com'
data = Mock.mock_get('storage/01d4fcd4-e446-433b-8a9c-551a1284952e')
storage = manager.get_storage('01d4fcd4-e446-433b-8a9c-551a1284952e')
responses.add(
responses.POST,
Mock.base_url + '/server/00798b85-efdc-41ca-8021-f6ef457b8531/storage/attach',
body = Mock.read_from_file('storage_attach.json'),
status = 200,
content_type='application/json'
)
server.add_storage(storage)
assert len(server.storage_devices) == 2
assert server.storage_devices[0].title == 'Storage for server1.example.com'
assert server.storage_devices[1].title == 'Operating system disk'
responses.add(
responses.POST,
Mock.base_url + '/server/00798b85-efdc-41ca-8021-f6ef457b8531/storage/detach',
body = Mock.read_from_file('storage_attach.json'),
status = 200,
content_type='application/json'
)
server.remove_storage(server.storage_devices[1])
assert len(server.storage_devices) == 1
assert server.storage_devices[0].title == 'Storage for server1.example.com'
示例2: test_create_server
# 需要导入模块: from conftest import Mock [as 别名]
# 或者: from conftest.Mock import read_from_file [as 别名]
def test_create_server(self, manager):
responses.add(
responses.POST,
Mock.base_url + "/server",
body = Mock.read_from_file("server_create.json"),
status = 202,
content_type='application/json'
)
server1 = Server(core_number=2, memory_amount=1024, hostname="my.example.com",zone=ZONE.Chicago, storage_devices=[
Storage(os="Ubuntu 14.04", size=10),
Storage(size=100, title="storage disk 1")
])
manager.create_server(server1)
# assert correct values in response
assert type(server1).__name__ == "Server"
assert server1.core_number == "2"
assert server1.memory_amount == "1024"
# assert new data was populated
assert server1.video_model == "cirrus"
assert server1.vnc == "off"
assert server1.vnc_password == "aabbccdd"
示例3: test_create_server_with_dict
# 需要导入模块: from conftest import Mock [as 别名]
# 或者: from conftest.Mock import read_from_file [as 别名]
def test_create_server_with_dict(self, manager):
responses.add(
responses.POST,
Mock.base_url + '/server',
body=Mock.read_from_file('server_create.json'),
status=202,
content_type='application/json'
)
server1 = {
'core_number': 2,
'memory_amount': 1024,
'hostname': 'my.example.com',
'zone': ZONE.Chicago,
'storage_devices': [
{'os': 'Ubuntu 14.04', 'size': 10},
{'size': 100, 'title': 'storage disk 1'},
]
}
server1 = manager.create_server(server1)
# assert correct values in response
assert type(server1).__name__ == 'Server'
assert server1.core_number == '2'
assert server1.memory_amount == '1024'
# assert ips and storages have correct types
assert type(server1.storage_devices[0]).__name__ == 'Storage'
assert type(server1.ip_addresses[0]).__name__ == 'IP_address'
# assert new data was populated
assert server1.video_model == 'cirrus'
assert server1.vnc == 'off'
assert server1.vnc_password == 'aabbccdd'
示例4: test_create_server
# 需要导入模块: from conftest import Mock [as 别名]
# 或者: from conftest.Mock import read_from_file [as 别名]
def test_create_server(self, manager):
responses.add(
responses.POST,
Mock.base_url + '/server',
body=Mock.read_from_file('server_create.json'),
status=202,
content_type='application/json'
)
server1 = Server(
core_number=2,
memory_amount=1024,
hostname='my.example.com',
zone=ZONE.Chicago,
storage_devices=[
Storage(os='Ubuntu 14.04', size=10),
Storage(size=100, title='storage disk 1')
]
)
manager.create_server(server1)
# assert correct values in response
assert type(server1).__name__ == 'Server'
assert server1.core_number == '2'
assert server1.memory_amount == '1024'
# assert ips and storages have correct types
assert type(server1.storage_devices[0]).__name__ == 'Storage'
assert type(server1.ip_addresses[0]).__name__ == 'IP_address'
# assert new data was populated
assert server1.video_model == 'cirrus'
assert server1.vnc == 'off'
assert server1.vnc_password == 'aabbccdd'