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


Python MagicMock.env方法代码示例

本文整理汇总了Python中mock.MagicMock.env方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.env方法的具体用法?Python MagicMock.env怎么用?Python MagicMock.env使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mock.MagicMock的用法示例。


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

示例1: test_hypervisorCheckIn

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import env [as 别名]
    def test_hypervisorCheckIn(self, server):
        options = MagicMock()
        server.return_value.registration.new_system_user_pass.return_value = {
            'system_id': '123'
        }

        config = Config('test', 'libvirt', sat_server='localhost')
        manager = Manager.fromOptions(self.logger, options, config)
        options.env = "ENV"
        options.owner = "OWNER"
        manager.hypervisorCheckIn(self.host_guest_report, options)
        manager.server.registration.virt_notify.assert_called_with(ANY, [
            [0, "exists", "system", {"identity": "host", "uuid": "0000000000000000"}],
            [0, "crawl_began", "system", {}],
            [0, "exists", "domain", {
                "memory_size": 0,
                "name": "VM 9c927368-e888-43b4-9cdb-91b10431b258 from libvirt hypervisor ad58b739-5288-4cbc-a984-bd771612d670",
                "state": "running",
                "uuid": "9c927368e88843b49cdb91b10431b258",
                "vcpus": 1,
                "virt_type": "fully_virtualized"
            }],
            [0, "exists", "domain", {
                "memory_size": 0,
                "name": "VM d5ffceb5-f79d-41be-a4c1-204f836e144a from libvirt hypervisor ad58b739-5288-4cbc-a984-bd771612d670",
                "state": "shutoff",
                "uuid": "d5ffceb5f79d41bea4c1204f836e144a",
                "vcpus": 1,
                "virt_type": "fully_virtualized"
            }],
            [0, "crawl_ended", "system", {}]
        ])
开发者ID:mtulio,项目名称:virt-who,代码行数:34,代码来源:test_manager.py

示例2: test_hypervisorCheckIn

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import env [as 别名]
    def test_hypervisorCheckIn(self, server):
        options = MagicMock()
        options.smType = self.smType

        manager = Manager.fromOptions(self.logger, options)
        options.env = "ENV"
        options.owner = "OWNER"
        manager.hypervisorCheckIn(options, self.mapping, 'ABC')
        manager.server.registration.virt_notify.assert_called_with(ANY, [
            [
                0, 'exists', 'system', {'uuid': '0000000000000000', 'identity': 'host'}
            ], [
                0, 'crawl_began', 'system', {}
            ], [
                0, 'exists', 'domain', {
                    'state': 'running',
                    'memory_size': 0,
                    'name': 'VM from ABC hypervisor ad58b739-5288-4cbc-a984-bd771612d670',
                    'virt_type': 'fully_virtualized',
                    'vcpus': 1,
                    'uuid': '2147647e6f064ac0982d6902c259f9d6'
                }
            ], [
                0, 'exists', 'domain', {
                    'state': 'running',
                    'memory_size': 0,
                    'name': 'VM from ABC hypervisor ad58b739-5288-4cbc-a984-bd771612d670',
                    'virt_type': 'fully_virtualized',
                    'vcpus': 1,
                    'uuid': 'd5ffceb5f79d41bea4c1204f836e144a'
                }
            ], [
                0, 'crawl_ended', 'system', {}
            ]
        ])
开发者ID:patrobinson,项目名称:virt-who,代码行数:37,代码来源:test_manager.py

示例3: test_hypervisorCheckIn

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import env [as 别名]
    def test_hypervisorCheckIn(self, server):
        options = MagicMock()
        options.smType = self.smType

        manager = Manager.fromOptions(self.logger, options)
        options.env = "ENV"
        options.owner = "OWNER"
        manager.hypervisorCheckIn(options, self.mapping, 'ABC')
        manager.server.registration.virt_notify.assert_called_with(ANY, [
            [0, "exists", "system", {"identity": "host", "uuid": "0000000000000000"}],
            [0, "crawl_began", "system", {}],
            [0, "exists", "domain", {
                "memory_size": 0,
                "name": "VM from ABC hypervisor ad58b739-5288-4cbc-a984-bd771612d670",
                "running": "running",
                "uuid": "9c927368e88843b49cdb91b10431b258",
                "vcpus": 1,
                "virt_type": "fully_virtualized"
            }],
            [0, "exists", "domain", {
                "memory_size": 0,
                "name": "VM from ABC hypervisor ad58b739-5288-4cbc-a984-bd771612d670",
                "running": "shutoff",
                "uuid": "d5ffceb5f79d41bea4c1204f836e144a",
                "vcpus": 1,
                "virt_type": "fully_virtualized"
            }],
            [0, "crawl_ended", "system", {}]
        ])
开发者ID:eko-index,项目名称:virt-who,代码行数:31,代码来源:test_manager.py

示例4: test_format_request_id

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import env [as 别名]
    def test_format_request_id(self):
        req = MagicMock()
        req.env = {'REQUEST_ID': '123456'}
        resp = MagicMock()

        hook_format(req, resp)

        resp.set_header.assert_called_with('X-Compute-Request-Id', '123456')
开发者ID:ajiang38740,项目名称:jumpgate,代码行数:10,代码来源:test_hooks.py

示例5: test_upstream_xauth

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import env [as 别名]
 def test_upstream_xauth(self):
     req = MagicMock()
     req.headers = {}
     req.method = 'GET'
     req.path = '/v2/servers'
     req.env = {'REMOTE_USER': 'jsmith'}
     resp = MagicMock()
     validate_token(req, resp, {})
     self.assertIsNone(req.env.get('auth'))
开发者ID:ajiang38740,项目名称:jumpgate,代码行数:11,代码来源:test_hooks.py

示例6: test_upstream_admin

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import env [as 别名]
 def test_upstream_admin(self):
     req = MagicMock()
     req.headers = {}
     req.method = 'GET'
     req.path = '/v2/servers'
     req.env = {'is_admin': True}
     resp = MagicMock()
     validate_token(req, resp, {})
     self.assertIsNone(req.env.get('auth'))
开发者ID:ajiang38740,项目名称:jumpgate,代码行数:11,代码来源:test_hooks.py

示例7: test_invalid_auth

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import env [as 别名]
 def test_invalid_auth(self):
     req = MagicMock()
     req.headers = {'X-AUTH-TOKEN': 'IAMBAD'}
     req.method = 'GET'
     req.path = '/v2/servers'
     req.env = {}
     resp = MagicMock()
     with self.assertRaises(InvalidTokenError):
         validate_token(req, resp, {})
     self.assertIsNone(req.env.get('auth'))
开发者ID:ajiang38740,项目名称:jumpgate,代码行数:12,代码来源:test_hooks.py

示例8: test_upstream_preauth

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import env [as 别名]
 def test_upstream_preauth(self):
     req = MagicMock()
     auth = {'user': 'jsmith'}
     req.headers = {}
     req.method = 'GET'
     req.path = '/v2/servers'
     req.env = {'auth': auth}
     resp = MagicMock()
     validate_token(req, resp, {})
     self.assertEquals(req.env.get('auth'), auth)
开发者ID:ajiang38740,项目名称:jumpgate,代码行数:12,代码来源:test_hooks.py

示例9: test_build_base_url

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import env [as 别名]
def test_build_base_url(url_format, pretty_urls, uri, expected):
    app = MagicMock()
    app.env = MagicMock()
    app.env.base_asset_url_format = url_format
    app.config = {
            'site/root': '/',
            'site/pretty_urls': pretty_urls}
    assets_path = 'foo/bar-assets'
    actual = build_base_url(app, uri, assets_path)
    assert actual == expected
开发者ID:thhgcn,项目名称:PieCrust2,代码行数:12,代码来源:test_data_assetor.py

示例10: test_set_uuid

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import env [as 别名]
    def test_set_uuid(self):
        req = MagicMock()
        resp = MagicMock()
        req.env = {}

        hook_set_uuid(req, resp, {})

        self.assertEquals(len(req.env), 1)
        self.assertEquals(list(req.env.keys()), ['REQUEST_ID'])
        self.assertIsNotNone(req.env['REQUEST_ID'])
        self.assertTrue(req.env['REQUEST_ID'].startswith('req-'))
开发者ID:ajiang38740,项目名称:jumpgate,代码行数:13,代码来源:test_hooks.py

示例11: test_unprotected

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import env [as 别名]
 def test_unprotected(self):
     for api in ['GET:/v2', 'GET:/v2/', 'GET:/v3.0', 'GET:/v3.0/',
                 'GET:/v10.22', 'POST:/v2/tokens', 'POST:/v2.1/tokens',
                 'GET:/v2/tokens/a8Vs7bS', 'GET:/v2.0/tokens/a8Vs7bS']:
         req = MagicMock()
         req.headers = {'X-AUTH-TOKEN': None}
         req.method = api.split(':')[0]
         req.path = api.split(':')[1]
         req.env = {}
         resp = MagicMock()
         validate_token(req, resp, {})
         self.assertIsNone(req.env.get('auth'))
开发者ID:ajiang38740,项目名称:jumpgate,代码行数:14,代码来源:test_hooks.py

示例12: test_get_endpoint_path

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import env [as 别名]
    def test_get_endpoint_path(self):
        req = MagicMock()
        req.env = {'tenant_id': '1234'}

        path = self.disp.get_endpoint_path(req, 'user_page')

        self.assertEquals(path, '/path/to/1234')

        path = self.disp.get_endpoint_path(
            req, 'instance_detail', instance_id='9876')

        self.assertEquals(path, '/path/to/1234/9876')
开发者ID:LiuZhiyan,项目名称:jumpgate,代码行数:14,代码来源:test_dispatcher.py

示例13: test_admin_token

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import env [as 别名]
    def test_admin_token(self, cfg):
        req = MagicMock()
        req.headers = {'X-AUTH-TOKEN': 'ADMIN'}
        resp = MagicMock()
        cfg.CONF = {'DEFAULT': {'admin_token': 'ADMIN'}}

        admin_token(req, resp, {})
        self.assertTrue(req.env['is_admin'])

        req.headers = {'X-AUTH-TOKEN': 'ABC'}
        req.env = {}
        admin_token(req, resp, {})
        self.assertIsNone(req.env.get('is_admin'))
开发者ID:ajiang38740,项目名称:jumpgate,代码行数:15,代码来源:test_hooks.py

示例14: test_log_request

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import env [as 别名]
    def test_log_request(self, log):
        req = MagicMock()
        req.method = 'GET'
        req.path = '/'
        req.query_string = 'something=value'
        req.env = {'REQUEST_ID': '123456'}
        resp = MagicMock()
        resp.status = '200 OK'
        log_request(req, resp)

        log.info.assert_called_with(
            '%s %s %s %s [ReqId: %s]',
            'GET', '/', 'something=value', '200 OK', '123456')
开发者ID:ajiang38740,项目名称:jumpgate,代码行数:15,代码来源:test_hooks.py

示例15: test_get_endpoint_url

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import env [as 别名]
    def test_get_endpoint_url(self):
        disp = Dispatcher()
        disp.add_endpoint('user_page0', '/path0/to/{tenant_id}')
        self.app.add_dispatcher('SERVICE', disp)

        req = MagicMock()
        req.env = {'tenant_id': '1234'}
        req.protocol = 'http'
        req.get_header.return_value = 'some_host'
        req.app = ''

        url = self.app.get_endpoint_url('SERVICE', req, 'user_page0')
        self.assertEqual(url, 'http://some_host/path0/to/1234')
开发者ID:BillArnold,项目名称:barnoldjg,代码行数:15,代码来源:test_jumpgate.py


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