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


Python conftest.Mock类代码示例

本文整理汇总了Python中conftest.Mock的典型用法代码示例。如果您正苦于以下问题:Python Mock类的具体用法?Python Mock怎么用?Python Mock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Mock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_storage_update

    def test_storage_update(self, manager):

        Mock.mock_put("storage/01d4fcd4-e446-433b-8a9c-551a1284952e")
        storage = manager.modify_storage("01d4fcd4-e446-433b-8a9c-551a1284952e", title="my bigger data collection", size=15)
        assert type(storage).__name__ == "Storage"
        assert storage.size == 15
        assert storage.title == "my bigger data collection"
开发者ID:andersinno,项目名称:upcloud-python-api,代码行数:7,代码来源:test_storage.py

示例2: test_attach_and_detach_storage

  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,代码行数:34,代码来源:test_server.py

示例3: test_add_firewall_rule

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

示例4: test_get_tags

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

示例5: test_get_tag

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

示例6: test_storage_update_oop

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

示例7: test_storage_create

 def test_storage_create(self, manager):
     Mock.mock_post("storage")
     storage = manager.create_storage(666, "maxiops", "My data collection", "fi-hel1")
     assert type(storage).__name__ == "Storage"
     assert storage.size == 666
     assert storage.tier == "maxiops"
     assert storage.title == "My data collection"
     assert storage.zone == "fi-hel1"
开发者ID:andersinno,项目名称:upcloud-python-api,代码行数:8,代码来源:test_storage.py

示例8: test_get_populated_servers

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

示例9: test_list_and_get_firewall_rules

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

示例10: test_restart_server

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

示例11: test_start_server

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

示例12: test_restart_server

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

示例13: test_start_server

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

示例14: test_modify_ip_oop

	def test_modify_ip_oop(self, manager):
		# get ip
		data = Mock.mock_get("ip_address/10.1.0.101")
		ip_addr = manager.get_IP("10.1.0.101")

		# put ip
		data = Mock.mock_put("ip_address/10.1.0.101")
		ip_addr.ptr = "my.ptr.record"
		ip_addr.save()

		assert ip_addr.ptr == "my.ptr.record"
开发者ID:derega,项目名称:upcloud-python-api,代码行数:11,代码来源:test_ip_manager.py

示例15: test_modify_ip_oop

    def test_modify_ip_oop(self, manager):
        # get ip
        data = Mock.mock_get('ip_address/10.1.0.101')
        ip_addr = manager.get_IP('10.1.0.101')

        # put ip
        data = Mock.mock_put('ip_address/10.1.0.101')
        ip_addr.ptr = 'my.ptr.record'
        ip_addr.save()

        assert ip_addr.ptr == 'my.ptr.record'
开发者ID:andersinno,项目名称:upcloud-python-api,代码行数:11,代码来源:test_ip_manager.py


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