本文整理汇总了Python中mock.NonCallableMagicMock.configure_mock方法的典型用法代码示例。如果您正苦于以下问题:Python NonCallableMagicMock.configure_mock方法的具体用法?Python NonCallableMagicMock.configure_mock怎么用?Python NonCallableMagicMock.configure_mock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.NonCallableMagicMock
的用法示例。
在下文中一共展示了NonCallableMagicMock.configure_mock方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_listed_users
# 需要导入模块: from mock import NonCallableMagicMock [as 别名]
# 或者: from mock.NonCallableMagicMock import configure_mock [as 别名]
def test_get_listed_users(self):
usr1 = models.CassandraUser(self._get_random_name(1025))
usr2 = models.CassandraUser(self._get_random_name(1025))
usr3 = models.CassandraUser(self._get_random_name(1025))
db1 = models.CassandraSchema('db1')
db2 = models.CassandraSchema('db2')
usr1.databases.append(db1.serialize())
usr3.databases.append(db2.serialize())
rv_1 = NonCallableMagicMock()
rv_1.configure_mock(name=usr1.name, super=False)
rv_2 = NonCallableMagicMock()
rv_2.configure_mock(name=usr2.name, super=False)
rv_3 = NonCallableMagicMock()
rv_3.configure_mock(name=usr3.name, super=True)
with patch.object(self.conn, 'execute', return_value=iter(
[rv_1, rv_2, rv_3])):
with patch.object(self.admin, '_get_acl',
return_value={usr1.name: {db1.name: {'SELECT'},
db2.name: {}},
usr3.name: {db2.name: {'SELECT'}}}
):
usrs = self.manager.list_users(self.context)
self.conn.execute.assert_has_calls([
call(self.__LIST_USR_FORMAT),
], any_order=True)
self.assertIn(usr1.serialize(), usrs[0])
self.assertIn(usr2.serialize(), usrs[0])
self.assertIn(usr3.serialize(), usrs[0])
示例2: DesignateBackendTestCase
# 需要导入模块: from mock import NonCallableMagicMock [as 别名]
# 或者: from mock.NonCallableMagicMock import configure_mock [as 别名]
class DesignateBackendTestCase(tests.TestCase):
def setUp(self):
super(DesignateBackendTestCase, self).setUp()
self.zone = objects.Zone(
id='e2bed4dc-9d01-11e4-89d3-123b93f75cba',
name='example.com.',
email='[email protected]',
)
self.target = {
'id': '4588652b-50e7-46b9-b688-a9bad40a873e',
'type': 'designate',
'masters': [
{'host': '192.0.2.1', 'port': 53},
],
'options': [
{'key': 'username', 'value': 'user'},
{'key': 'password', 'value': 'secret'},
{'key': 'project_name', 'value': 'project'},
{'key': 'project_zone_name', 'value': 'project_zone'},
{'key': 'user_zone_name', 'value': 'user_zone'},
],
}
self.backend = impl_designate.DesignateBackend(
objects.PoolTarget.from_dict(self.target)
)
# Mock client
self.client = NonCallableMagicMock()
zones = NonCallableMagicMock(spec_set=[
'create', 'delete'])
self.client.configure_mock(zones=zones)
def test_create_zone(self):
masters = ["%(host)s:%(port)s" % self.target['masters'][0]]
with patch.object(self.backend, '_get_client',
return_value=self.client):
self.backend.create_zone(self.admin_context, self.zone)
self.client.zones.create.assert_called_once_with(
self.zone.name, 'SECONDARY', masters=masters)
def test_delete_zone(self):
with patch.object(self.backend, '_get_client',
return_value=self.client):
self.backend.delete_zone(self.admin_context, self.zone)
self.client.zones.delete.assert_called_once_with(self.zone.name)
def test_delete_zone_notfound(self):
self.client.delete.side_effect = exceptions.NotFound
with patch.object(self.backend, '_get_client',
return_value=self.client):
self.backend.delete_zone(self.admin_context, self.zone)
self.client.zones.delete.assert_called_once_with(self.zone.name)
def test_delete_zone_exc(self):
self.client.zones.delete.side_effect = Exception
with testtools.ExpectedException(Exception):
with patch.object(self.backend, '_get_client',
return_value=self.client):
self.backend.delete_zone(self.admin_context, self.zone)
self.client.zones.delete.assert_called_once_with(self.zone.name)
示例3: DesignateBackendTest
# 需要导入模块: from mock import NonCallableMagicMock [as 别名]
# 或者: from mock.NonCallableMagicMock import configure_mock [as 别名]
class DesignateBackendTest(oslotest.base.BaseTestCase):
def setUp(self):
super(DesignateBackendTest, self).setUp()
opts = RoObject(
username="user",
password="secret",
project_name="project",
project_domain_name="project_domain",
user_domain_name="user_domain",
)
self.target = RoObject(
{
"id": "4588652b-50e7-46b9-b688-a9bad40a873e",
"type": "dyndns",
"masters": [RoObject({"host": "192.0.2.1", "port": 53})],
"options": opts,
}
)
# Backends blow up when trying to self.admin_context = ... due to
# policy not being initialized
self.admin_context = Mock()
get_context_patcher = patch("designate.context.DesignateContext.get_admin_context")
get_context = get_context_patcher.start()
get_context.return_value = self.admin_context
self.backend = impl_designate.DesignateBackend(self.target)
# Mock client
self.client = NonCallableMagicMock()
zones = NonCallableMagicMock(spec_set=["create", "delete"])
self.client.configure_mock(zones=zones)
def test_create_domain(self):
zone = create_zone()
masters = ["%(host)s:%(port)s" % self.target.masters[0]]
with patch.object(self.backend, "_get_client", return_value=self.client):
self.backend.create_domain(self.admin_context, zone)
self.client.zones.create.assert_called_once_with(zone.name, "SECONDARY", masters=masters)
def test_delete_domain(self):
zone = create_zone()
with patch.object(self.backend, "_get_client", return_value=self.client):
self.backend.delete_domain(self.admin_context, zone)
self.client.zones.delete.assert_called_once_with(zone.name)
def test_delete_domain_notfound(self):
zone = create_zone()
self.client.delete.side_effect = exceptions.NotFound
with patch.object(self.backend, "_get_client", return_value=self.client):
self.backend.delete_domain(self.admin_context, zone)
self.client.zones.delete.assert_called_once_with(zone.name)
def test_delete_domain_exc(self):
class Exc(Exception):
pass
zone = create_zone()
self.client.zones.delete.side_effect = Exc()
with testtools.ExpectedException(Exc):
with patch.object(self.backend, "_get_client", return_value=self.client):
self.backend.delete_domain(self.admin_context, zone)
self.client.zones.delete.assert_called_once_with(zone.name)
示例4: DesignateBackendTest
# 需要导入模块: from mock import NonCallableMagicMock [as 别名]
# 或者: from mock.NonCallableMagicMock import configure_mock [as 别名]
class DesignateBackendTest(oslotest.base.BaseTestCase):
def setUp(self):
super(DesignateBackendTest, self).setUp()
opts = RoObject(
username='user',
password='secret',
project_name='project',
project_zone_name='project_zone',
user_zone_name='user_zone'
)
self.target = RoObject({
'id': '4588652b-50e7-46b9-b688-a9bad40a873e',
'type': 'dyndns',
'masters': [RoObject({'host': '192.0.2.1', 'port': 53})],
'options': opts
})
# Backends blow up when trying to self.admin_context = ... due to
# policy not being initialized
self.admin_context = Mock()
get_context_patcher = patch(
'designate.context.DesignateContext.get_admin_context')
get_context = get_context_patcher.start()
get_context.return_value = self.admin_context
self.backend = impl_designate.DesignateBackend(self.target)
# Mock client
self.client = NonCallableMagicMock()
zones = NonCallableMagicMock(spec_set=[
'create', 'delete'])
self.client.configure_mock(zones=zones)
def test_create_zone(self):
zone = create_zone()
masters = ["%(host)s:%(port)s" % self.target.masters[0]]
with patch.object(
self.backend, '_get_client', return_value=self.client):
self.backend.create_zone(self.admin_context, zone)
self.client.zones.create.assert_called_once_with(
zone.name, 'SECONDARY', masters=masters)
def test_delete_zone(self):
zone = create_zone()
with patch.object(
self.backend, '_get_client', return_value=self.client):
self.backend.delete_zone(self.admin_context, zone)
self.client.zones.delete.assert_called_once_with(zone.name)
def test_delete_zone_notfound(self):
zone = create_zone()
self.client.delete.side_effect = exceptions.NotFound
with patch.object(
self.backend, '_get_client', return_value=self.client):
self.backend.delete_zone(self.admin_context, zone)
self.client.zones.delete.assert_called_once_with(zone.name)
def test_delete_zone_exc(self):
class Exc(Exception):
pass
zone = create_zone()
self.client.zones.delete.side_effect = Exc()
with testtools.ExpectedException(Exc):
with patch.object(
self.backend, '_get_client', return_value=self.client):
self.backend.delete_zone(self.admin_context, zone)
self.client.zones.delete.assert_called_once_with(zone.name)