本文整理汇总了Python中conftest.Mock.mock_get方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.mock_get方法的具体用法?Python Mock.mock_get怎么用?Python Mock.mock_get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类conftest.Mock
的用法示例。
在下文中一共展示了Mock.mock_get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_firewall_rule
# 需要导入模块: from conftest import Mock [as 别名]
# 或者: from conftest.Mock import mock_get [as 别名]
def test_add_firewall_rule(self, manager):
Mock.mock_get('server/00798b85-efdc-41ca-8021-f6ef457b8531')
server = manager.get_server('00798b85-efdc-41ca-8021-f6ef457b8531')
responses.add_callback(
responses.POST,
Mock.base_url + '/server/00798b85-efdc-41ca-8021-f6ef457b8531/firewall_rule',
content_type='application/json',
callback=firewall_rule_callback
)
returned_firewall = server.add_firewall_rule(FirewallRule(
position='1',
direction='in',
family='IPv4',
protocol='tcp',
source_address_start='192.168.1.1',
source_address_end='192.168.1.255',
destination_port_start='22',
destination_port_end='22',
action='accept'
))
# everything should run without errors, returned created object
assert returned_firewall.position == '1'
assert returned_firewall.direction == 'in'
assert returned_firewall.source_address_end == '192.168.1.255'
示例2: test_attach_and_detach_storage
# 需要导入模块: from conftest import Mock [as 别名]
# 或者: from conftest.Mock import mock_get [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'
示例3: test_get_tag
# 需要导入模块: from conftest import Mock [as 别名]
# 或者: from conftest.Mock import mock_get [as 别名]
def test_get_tag(self, manager):
Mock.mock_get('tag/TheTestTag')
tag = manager.get_tag('TheTestTag')
assert tag.name == 'TheTestTag'
assert tag.description == 'Description of TheTestTag'
assert len(tag.servers) == 2
assert tag.servers[0].uuid == '0057e20a-6878-43a7-b2b3-530c4a4bdc55'
示例4: test_get_populated_servers
# 需要导入模块: from conftest import Mock [as 别名]
# 或者: from conftest.Mock import mock_get [as 别名]
def test_get_populated_servers(self, manager):
data = Mock.mock_get('server')
data = Mock.mock_get('server/00798b85-efdc-41ca-8021-f6ef457b8531')
data = Mock.mock_get('server/009d64ef-31d1-4684-a26b-c86c955cbf46')
servers = manager.get_servers(populate=True)
for server in servers:
assert type(server).__name__ == 'Server'
示例5: test_get_tags
# 需要导入模块: from conftest import Mock [as 别名]
# 或者: from conftest.Mock import mock_get [as 别名]
def test_get_tags(self, manager):
Mock.mock_get('tag')
tags = manager.get_tags()
assert len(tags) == 2
assert tags[0].name == 'TheTestTag1'
assert tags[1].name == 'TheTestTag2'
assert tags[0].servers[0].uuid == '0057e20a-6878-43a7-b2b3-530c4a4bdc55'
示例6: test_list_and_get_firewall_rules
# 需要导入模块: from conftest import Mock [as 别名]
# 或者: from conftest.Mock import mock_get [as 别名]
def test_list_and_get_firewall_rules(self, manager):
Mock.mock_get('server/00798b85-efdc-41ca-8021-f6ef457b8531')
server = manager.get_server('00798b85-efdc-41ca-8021-f6ef457b8531')
target = 'server/00798b85-efdc-41ca-8021-f6ef457b8531/firewall_rule'
Mock.mock_get(target, 'firewall_rules.json')
firewall_rules = server.get_firewall_rules()
assert firewall_rules[0].position == '1'
示例7: test_remove_firewall_rule
# 需要导入模块: from conftest import Mock [as 别名]
# 或者: from conftest.Mock import mock_get [as 别名]
def test_remove_firewall_rule(self, manager):
Mock.mock_get('server/00798b85-efdc-41ca-8021-f6ef457b8531')
server = manager.get_server('00798b85-efdc-41ca-8021-f6ef457b8531')
target = 'server/00798b85-efdc-41ca-8021-f6ef457b8531/firewall_rule'
Mock.mock_get(target, 'firewall_rules.json')
firewall_rules = server.get_firewall_rules()
Mock.mock_delete('server/00798b85-efdc-41ca-8021-f6ef457b8531/firewall_rule/1')
res = firewall_rules[0].destroy()
Mock.mock_delete('server/00798b85-efdc-41ca-8021-f6ef457b8531/firewall_rule/1')
res = server.remove_firewall_rule(firewall_rules[0])
assert res == {}
示例8: test_update_server_non_updateable_fields
# 需要导入模块: from conftest import Mock [as 别名]
# 或者: from conftest.Mock import mock_get [as 别名]
def test_update_server_non_updateable_fields(self, manager):
data = Mock.mock_get('server/00798b85-efdc-41ca-8021-f6ef457b8531')
server = manager.get_server('00798b85-efdc-41ca-8021-f6ef457b8531')
with pytest.raises(Exception) as excinfo:
server.state = 'rekt'
assert "'state' is a readonly field" in str(excinfo.value)
示例9: test_get_ip
# 需要导入模块: from conftest import Mock [as 别名]
# 或者: from conftest.Mock import mock_get [as 别名]
def test_get_ip(self, manager):
data = Mock.mock_get("ip_address/10.1.0.101")
ip_addr = manager.get_IP("10.1.0.101")
assert type(ip_addr).__name__ == "IP_address"
assert ip_addr.address == "10.1.0.101"
assert ip_addr.ptr == "a.ptr.record"
示例10: test_get_account
# 需要导入模块: from conftest import Mock [as 别名]
# 或者: from conftest.Mock import mock_get [as 别名]
def test_get_account(self, manager):
data = Mock.mock_get("account")
res = manager.authenticate()
assert json.loads(data) == res
res = manager.get_account()
assert json.loads(data) == res
示例11: test_get_ip
# 需要导入模块: from conftest import Mock [as 别名]
# 或者: from conftest.Mock import mock_get [as 别名]
def test_get_ip(self, manager):
data = Mock.mock_get('ip_address/10.1.0.101')
ip_addr = manager.get_IP('10.1.0.101')
assert type(ip_addr).__name__ == 'IP_address'
assert ip_addr.address == '10.1.0.101'
assert ip_addr.ptr == 'a.ptr.record'
示例12: test_storage_update_oop
# 需要导入模块: from conftest import Mock [as 别名]
# 或者: from conftest.Mock import mock_get [as 别名]
def test_storage_update_oop(self, manager):
data = Mock.mock_get("storage/01d4fcd4-e446-433b-8a9c-551a1284952e")
storage = manager.get_storage("01d4fcd4-e446-433b-8a9c-551a1284952e")
Mock.mock_put("storage/01d4fcd4-e446-433b-8a9c-551a1284952e")
storage.update(title="my bigger data collection", size=15)
assert storage.title == "my bigger data collection"
assert storage.size == 15
示例13: test_start_server
# 需要导入模块: from conftest import Mock [as 别名]
# 或者: from conftest.Mock import mock_get [as 别名]
def test_start_server(self, manager):
data = Mock.mock_get("server/009d64ef-31d1-4684-a26b-c86c955cbf46")
server = manager.get_server("009d64ef-31d1-4684-a26b-c86c955cbf46")
assert server.state == "stopped"
data = Mock.mock_server_operation("server/009d64ef-31d1-4684-a26b-c86c955cbf46/start")
server.start()
assert server.state == "started"
示例14: test_restart_server
# 需要导入模块: from conftest import Mock [as 别名]
# 或者: from conftest.Mock import mock_get [as 别名]
def test_restart_server(self, manager):
data = Mock.mock_get('server/00798b85-efdc-41ca-8021-f6ef457b8531')
server = manager.get_server('00798b85-efdc-41ca-8021-f6ef457b8531')
assert server.state == 'started'
data = Mock.mock_server_operation('server/00798b85-efdc-41ca-8021-f6ef457b8531/restart')
server.restart()
assert server.state == 'maintenance'
示例15: test_edit_tag
# 需要导入模块: from conftest import Mock [as 别名]
# 或者: from conftest.Mock import mock_get [as 别名]
def test_edit_tag(self, manager):
Mock.mock_get('tag/TheTestTag')
tag = manager.get_tag('TheTestTag')
responses.add_callback(
responses.PUT,
Mock.base_url + '/tag/TheTestTag',
content_type='application/json',
callback=tag_post_callback
)
tag.name = 'AnotherTestTag'
assert tag._api_name == 'TheTestTag'
tag.save()
assert tag.name == 'AnotherTestTag'
assert tag._api_name == 'AnotherTestTag'