本文整理汇总了Python中mock.Mock.environ方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.environ方法的具体用法?Python Mock.environ怎么用?Python Mock.environ使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.Mock
的用法示例。
在下文中一共展示了Mock.environ方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_controller_action_multi_action
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import environ [as 别名]
def test_controller_action_multi_action(self, mock_cluster_load):
body = {"do_stuff": {}, "do_stuff2": {}}
tenant_id = Mock()
context = trove_testtools.TroveTestContext(self)
cluster_id = Mock()
req = Mock()
req.environ = MagicMock()
req.environ.get = Mock(return_value=context)
cluster = Mock()
cluster.instances_without_server = [Mock()]
cluster.datastore_version.manager = "test_dsv"
mock_cluster_load.return_value = cluster
self.assertRaisesRegexp(
exception.TroveError,
"should have exactly one action specified",
self.controller.action,
req,
body,
tenant_id,
cluster_id,
)
示例2: test_create_clusters_disabled
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import environ [as 别名]
def test_create_clusters_disabled(self,
mock_cluster_create,
mock_get_datastore_version):
cfg.CONF.set_override('cluster_support', False, group='redis',
enforce_type=True)
body = self.cluster
tenant_id = Mock()
context = trove_testtools.TroveTestContext(self)
req = Mock()
req.environ = MagicMock()
req.environ.get = Mock(return_value=context)
datastore_version = Mock()
datastore_version.manager = 'redis'
mock_get_datastore_version.return_value = (Mock(), datastore_version)
self.assertRaisesRegexp(exception.TroveError,
"Clusters not supported for",
self.controller.create,
req,
body,
tenant_id)
示例3: test_controller_action_found
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import environ [as 别名]
def test_controller_action_found(self,
mock_cluster_load,
mock_cluster_api_strategy):
body = {'do_stuff': {}}
tenant_id = Mock()
context = Mock()
id = Mock()
req = Mock()
req.environ = MagicMock()
req.environ.get = Mock(return_value=context)
cluster = Mock()
cluster.datastore_version.manager = 'mongodb'
mock_cluster_load.return_value = cluster
strat = Mock()
do_stuff_func = Mock()
strat.cluster_controller_actions = \
{'do_stuff': do_stuff_func}
mock_cluster_api_strategy.return_value = strat
self.controller.action(req, body, tenant_id, id)
self.assertEqual(1, do_stuff_func.call_count)
示例4: test_create_clusters
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import environ [as 别名]
def test_create_clusters(self,
mock_get_datastore_version,
mock_id_from_href,
mock_cluster_create):
body = self.cluster
tenant_id = Mock()
context = Mock()
req = Mock()
req.environ = Mock()
req.environ.__getitem__ = Mock(return_value=context)
datastore_version = Mock()
datastore_version.manager = 'vertica'
datastore = Mock()
mock_get_datastore_version.return_value = (datastore,
datastore_version)
instances = [{'volume_size': 1, 'flavor_id': '1234'},
{'volume_size': 1, 'flavor_id': '1234'},
{'volume_size': 1, 'flavor_id': '1234'}]
mock_id_from_href.return_value = '1234'
mock_cluster = Mock()
mock_cluster.instances = []
mock_cluster.instances_without_server = []
mock_cluster.datastore_version.manager = 'vertica'
mock_cluster_create.return_value = mock_cluster
self.controller.create(req, body, tenant_id)
mock_cluster_create.assert_called_with(context, 'products',
datastore, datastore_version,
instances)
示例5: test_controller_with_empty_metadata
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import environ [as 别名]
def test_controller_with_empty_metadata(self):
"""
Test the mock controller with metadata
"""
tenant_id = '77889991010'
instance_id = '27e25b73-88a1-4526-b2b9-919a28b8b33f'
context = Mock()
req = Mock()
req.environ = MagicMock()
req.environ.get = Mock(return_value=context)
send = Mock()
UpgradeMessageSender.create = Mock(return_value=send)
# append the body w/ empty metadata
self.body["upgrade"]["metadata"] = {}
resp = self.controller.create(req, self.body, tenant_id, instance_id)
instance_version = self.body["upgrade"]['instance_version']
location = self.body["upgrade"]["location"]
metadata = self.body["upgrade"]["metadata"]
UpgradeMessageSender.create.assert_called_once_with(
context, instance_id, instance_version, location, metadata)
self.assertEqual(202, resp.status)
示例6: test_create_clusters
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import environ [as 别名]
def test_create_clusters(self, mock_get_datastore_version, mock_id_from_href, mock_cluster_create):
body = self.cluster
tenant_id = Mock()
context = trove_testtools.TroveTestContext(self)
req = Mock()
req.environ = Mock()
req.environ.__getitem__ = Mock(return_value=context)
datastore_version = Mock()
datastore_version.manager = "mongodb"
datastore = Mock()
mock_get_datastore_version.return_value = (datastore, datastore_version)
instances = [
{
"volume_size": 1,
"volume_type": None,
"flavor_id": "1234",
"availability_zone": "az",
"modules": None,
"region_name": None,
"nics": [{"net-id": "e89aa5fd-6b0a-436d-a75c-1545d34d5331"}],
}
] * 5
mock_id_from_href.return_value = "1234"
mock_cluster = Mock()
mock_cluster.instances = []
mock_cluster.instances_without_server = []
mock_cluster.datastore_version.manager = "mongodb"
mock_cluster_create.return_value = mock_cluster
self.controller.create(req, body, tenant_id)
mock_cluster_create.assert_called_with(
context, "products", datastore, datastore_version, instances, {}, self.locality
)
示例7: test_instance_root_index
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import environ [as 别名]
def test_instance_root_index(self, mock_cluster_root_load):
req = Mock()
req.environ = {'trove.context': self.context}
tenant_id = Mock()
instance_id = utils.generate_uuid()
self.controller.instance_root_index(req, tenant_id, instance_id)
mock_cluster_root_load.assert_called_with(self.context, instance_id)
示例8: test_controller_with_metadata
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import environ [as 别名]
def test_controller_with_metadata(self):
"""
Test the mock controller with metadata
"""
tenant_id = '77889991010'
instance_id = '27e25b73-88a1-4526-b2b9-919a28b8b33f'
context = Mock()
req = Mock()
req.environ = MagicMock()
req.environ.get = Mock(return_value=context)
# append the body w/ metadata
self.body["upgrade"]["metadata"] = {
"config_location": "swift://my.conf.location",
"is_public": True,
"is_encypted": True}
resp = self.controller.create(req, self.body, tenant_id, instance_id)
instance_version = self.body["upgrade"]["instance_version"]
location = self.body["upgrade"]["location"]
metadata = self.body["upgrade"]["metadata"]
UpgradeMessageSender.create.assert_called_once_with(
context, instance_id, instance_version, location, metadata)
self.assertEqual(202, resp.status)
示例9: test_create_clusters
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import environ [as 别名]
def test_create_clusters(self,
mock_get_datastore_version,
mock_id_from_href,
mock_cluster_create):
body = self.cluster
tenant_id = Mock()
context = Mock()
req = Mock()
req.environ = Mock()
req.environ.__getitem__ = Mock(return_value=context)
datastore_version = Mock()
datastore_version.manager = 'redis'
datastore = Mock()
mock_get_datastore_version.return_value = (datastore,
datastore_version)
instances = [
{
"volume_size": None,
'volume_type': None,
"flavor_id": "1234",
"availability_zone": "az",
"nics": [
{"net-id": "e89aa5fd-6b0a-436d-a75c-1545d34d5331"}
]
},
{
"volume_size": None,
'volume_type': None,
"flavor_id": "1234",
"availability_zone": "az",
"nics": [
{"net-id": "e89aa5fd-6b0a-436d-a75c-1545d34d5331"}
]
},
{
"volume_size": None,
'volume_type': None,
"flavor_id": "1234",
"availability_zone": "az",
"nics": [
{"net-id": "e89aa5fd-6b0a-436d-a75c-1545d34d5331"}
]
}
]
mock_id_from_href.return_value = '1234'
mock_cluster = Mock()
mock_cluster.instances = []
mock_cluster.instances_without_server = []
mock_cluster.datastore_version.manager = 'redis'
mock_cluster_create.return_value = mock_cluster
self.controller.create(req, body, tenant_id)
mock_cluster_create.assert_called_with(context, 'products',
datastore, datastore_version,
instances, {})
示例10: test_instance_root_index
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import environ [as 别名]
def test_instance_root_index(self, mock_cluster_root_load):
context = Mock()
req = Mock()
req.environ = Mock()
req.environ.__getitem__ = Mock(return_value=context)
tenant_id = Mock()
instance_id = utils.generate_uuid()
self.controller.instance_root_index(req, tenant_id, instance_id)
mock_cluster_root_load.assert_called_with(context, instance_id)
示例11: test_root_index
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import environ [as 别名]
def test_root_index(self, root_load):
context = Mock()
req = Mock()
req.environ = Mock()
req.environ.__getitem__ = Mock(return_value=context)
tenant_id = Mock()
uuid = utils.generate_uuid()
is_cluster = False
self.controller.root_index(req, tenant_id, uuid, is_cluster)
root_load.assert_called_with(context, uuid)
示例12: test_instance_root_index_exception
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import environ [as 别名]
def test_instance_root_index_exception(self, mock_cluster_root_load):
req = Mock()
req.environ = {'trove.context': self.context}
tenant_id = Mock()
instance_id = utils.generate_uuid()
self.assertRaises(
exception.UnprocessableEntity,
self.controller.instance_root_index,
req, tenant_id, instance_id
)
mock_cluster_root_load.assert_called_with(self.context, instance_id)
示例13: test_show_cluster_instance
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import environ [as 别名]
def test_show_cluster_instance(self, mock_cluster_load_instance, mock_cluster_load):
tenant_id = Mock()
cluster_id = Mock()
instance_id = Mock()
context = trove_testtools.TroveTestContext(self)
req = Mock()
req.environ = Mock()
req.environ.__getitem__ = Mock(return_value=context)
cluster = Mock()
mock_cluster_load.return_value = cluster
cluster.id = cluster_id
self.controller.show_instance(req, tenant_id, cluster_id, instance_id)
mock_cluster_load_instance.assert_called_with(context, cluster.id, instance_id)
示例14: test_instance_root_index_exception
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import environ [as 别名]
def test_instance_root_index_exception(self, mock_cluster_root_load):
context = Mock()
req = Mock()
req.environ = Mock()
req.environ.__getitem__ = Mock(return_value=context)
tenant_id = Mock()
instance_id = utils.generate_uuid()
self.assertRaises(
exception.UnprocessableEntity,
self.controller.instance_root_index,
req, tenant_id, instance_id
)
mock_cluster_root_load.assert_called_with(context, instance_id)
示例15: test_create_clusters_disabled
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import environ [as 别名]
def test_create_clusters_disabled(self, mock_get_datastore_version, mock_cluster_create):
body = self.cluster
tenant_id = Mock()
context = trove_testtools.TroveTestContext(self)
req = Mock()
req.environ = MagicMock()
req.environ.get = Mock(return_value=context)
datastore_version = Mock()
datastore_version.manager = "mysql"
mock_get_datastore_version.return_value = (Mock(), datastore_version)
self.assertRaises(exception.ClusterDatastoreNotSupported, self.controller.create, req, body, tenant_id)