当前位置: 首页>>代码示例>>Python>>正文


Python Mock.read_from_file方法代码示例

本文整理汇总了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'
开发者ID:andersinno,项目名称:upcloud-python-api,代码行数:36,代码来源:test_server.py

示例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"
开发者ID:derega,项目名称:upcloud-python-api,代码行数:28,代码来源:test_server_creation.py

示例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'
开发者ID:andersinno,项目名称:upcloud-python-api,代码行数:37,代码来源:test_server_creation.py

示例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'
开发者ID:andersinno,项目名称:upcloud-python-api,代码行数:38,代码来源:test_server_creation.py


注:本文中的conftest.Mock.read_from_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。