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


Python testtools.ExpectedException方法代码示例

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


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

示例1: test_get_ssh_connection_timeout

# 需要导入模块: import testtools [as 别名]
# 或者: from testtools import ExpectedException [as 别名]
def test_get_ssh_connection_timeout(self):
        c_mock, aa_mock, client_mock = self._set_ssh_connection_mocks()

        c_mock.return_value = client_mock
        client_mock.connect.side_effect = [
            socket.error,
            socket.error,
            socket.error,
        ]

        client = ssh.Client('localhost', 'root', timeout=2)
        start_time = int(time.time())
        with testtools.ExpectedException(exceptions.SSHTimeout):
            client._get_ssh_connection()
        end_time = int(time.time())
        self.assertLess((end_time - start_time), 5)
        self.assertGreaterEqual((end_time - start_time), 2) 
开发者ID:openstack,项目名称:tempest-lib,代码行数:19,代码来源:test_ssh.py

示例2: test_is_valid_ttl

# 需要导入模块: import testtools [as 别名]
# 或者: from testtools import ExpectedException [as 别名]
def test_is_valid_ttl(self):
        self.CONF.set_override('min_ttl', 10, 'service:central')
        self.service._is_valid_ttl(self.context, 20)

        # policy.check() not to raise: the user is allowed to create low TTLs
        designate.central.service.policy.check = mock.Mock(return_value=None)
        self.service._is_valid_ttl(self.context, None)
        self.service._is_valid_ttl(self.context, 1)

        # policy.check() to raise
        designate.central.service.policy.check = mock.Mock(
            side_effect=exceptions.Forbidden
        )

        with testtools.ExpectedException(exceptions.InvalidTTL):
            self.service._is_valid_ttl(self.context, 3) 
开发者ID:openstack,项目名称:designate,代码行数:18,代码来源:test_basic.py

示例3: test_is_valid_recordset_placement_failing_2

# 需要导入模块: import testtools [as 别名]
# 或者: from testtools import ExpectedException [as 别名]
def test_is_valid_recordset_placement_failing_2(self):
        zone = RoObject(name='example.org.', id=CentralZoneTestCase.zone__id)
        self.service.storage.find_recordsets.return_value = [
            RoObject(),
            RoObject()
        ]
        with testtools.ExpectedException(
                exceptions.InvalidRecordSetLocation) as e:
            self.service._is_valid_recordset_placement(
                self.context,
                zone,
                'example.org.',
                'A',
            )
            self.assertEqual(
                'CNAME recordsets may not share a name with any other records',
                six.text_type(e)) 
开发者ID:openstack,项目名称:designate,代码行数:19,代码来源:test_basic.py

示例4: test_update_recordset_action_fail_on_managed

# 需要导入模块: import testtools [as 别名]
# 或者: from testtools import ExpectedException [as 别名]
def test_update_recordset_action_fail_on_managed(self):
        self.service.storage.get_zone.return_value = RoObject(
            type='foo',
            name='example.org.',
            tenant_id='2',
            action='bogus',
        )
        recordset = mock.Mock()
        recordset.obj_get_changes.return_value = ['foo']
        recordset.managed = True
        self.context = mock.Mock()
        self.context.edit_managed_records = False

        exc = self.assertRaises(rpc_dispatcher.ExpectedException,
                                self.service.update_recordset,
                                self.context,
                                recordset)

        self.assertEqual(exceptions.BadRequest, exc.exc_info[0]) 
开发者ID:openstack,项目名称:designate,代码行数:21,代码来源:test_basic.py

示例5: test_delete_recordset_not_found

# 需要导入模块: import testtools [as 别名]
# 或者: from testtools import ExpectedException [as 别名]
def test_delete_recordset_not_found(self):
        self.service.storage.get_zone.return_value = RoObject(
            action='bogus',
            id=CentralZoneTestCase.zone__id_2,
            name='example.org.',
            tenant_id='2',
            type='foo',
        )
        self.service.storage.get_recordset.return_value = RoObject(
            zone_id=CentralZoneTestCase.zone__id,
            id=CentralZoneTestCase.recordset__id,
            managed=False,
        )
        self.context = mock.Mock()
        self.context.edit_managed_records = False

        exc = self.assertRaises(rpc_dispatcher.ExpectedException,
                                self.service.delete_recordset,
                                self.context,
                                CentralZoneTestCase.zone__id_2,
                                CentralZoneTestCase.recordset__id)

        self.assertEqual(exceptions.RecordSetNotFound, exc.exc_info[0]) 
开发者ID:openstack,项目名称:designate,代码行数:25,代码来源:test_basic.py

示例6: test_delete_recordset_action_delete

# 需要导入模块: import testtools [as 别名]
# 或者: from testtools import ExpectedException [as 别名]
def test_delete_recordset_action_delete(self):
        self.service.storage.get_zone.return_value = RoObject(
            action='DELETE',
            id=CentralZoneTestCase.zone__id_2,
            name='example.org.',
            tenant_id='2',
            type='foo',
        )
        self.service.storage.get_recordset.return_value = RoObject(
            zone_id=CentralZoneTestCase.zone__id_2,
            id=CentralZoneTestCase.recordset__id,
            managed=False,
        )
        self.context = mock.Mock()
        self.context.edit_managed_records = False

        exc = self.assertRaises(rpc_dispatcher.ExpectedException,
                                self.service.delete_recordset,
                                self.context,
                                CentralZoneTestCase.zone__id_2,
                                CentralZoneTestCase.recordset__id)

        self.assertEqual(exceptions.BadRequest, exc.exc_info[0]) 
开发者ID:openstack,项目名称:designate,代码行数:25,代码来源:test_basic.py

示例7: test_create_record_fail_on_delete

# 需要导入模块: import testtools [as 别名]
# 或者: from testtools import ExpectedException [as 别名]
def test_create_record_fail_on_delete(self):
        self.service.storage.get_zone.return_value = RoObject(
            action='DELETE',
            id=CentralZoneTestCase.zone__id_2,
            name='example.org.',
            tenant_id='2',
            type='foo',
        )
        exc = self.assertRaises(rpc_dispatcher.ExpectedException,
                                self.service.create_record,
                                self.context,
                                CentralZoneTestCase.zone__id,
                                CentralZoneTestCase.recordset__id,
                                RoObject())

        self.assertEqual(exceptions.BadRequest, exc.exc_info[0]) 
开发者ID:openstack,项目名称:designate,代码行数:18,代码来源:test_basic.py

示例8: test_get_record_not_found

# 需要导入模块: import testtools [as 别名]
# 或者: from testtools import ExpectedException [as 别名]
def test_get_record_not_found(self):
        self.service.storage.get_zone.return_value = RoObject(
            id=CentralZoneTestCase.zone__id_2,
        )
        self.service.storage.get_recordset.return_value = RoObject(
            zone_id=CentralZoneTestCase.recordset__id
        )

        exc = self.assertRaises(rpc_dispatcher.ExpectedException,
                                self.service.get_record,
                                self.context,
                                CentralZoneTestCase.zone__id_2,
                                CentralZoneTestCase.recordset__id,
                                CentralZoneTestCase.record__id)

        self.assertEqual(exceptions.RecordNotFound, exc.exc_info[0]) 
开发者ID:openstack,项目名称:designate,代码行数:18,代码来源:test_basic.py

示例9: test_get_record_not_found_2

# 需要导入模块: import testtools [as 别名]
# 或者: from testtools import ExpectedException [as 别名]
def test_get_record_not_found_2(self):
        self.service.storage.get_zone.return_value = RoObject(
            id=CentralZoneTestCase.zone__id_2,
            name='example.org.',
            tenant_id=2,
        )
        self.service.storage.get_recordset.return_value = RoObject(
            zone_id=CentralZoneTestCase.zone__id_2,
            id=999,  # not matching record.recordset_id
            name='foo'
        )
        self.service.storage.get_record.return_value = RoObject(
            id=CentralZoneTestCase.record__id,
            zone_id=CentralZoneTestCase.zone__id_2,
            recordset_id=CentralZoneTestCase.recordset__id
        )

        exc = self.assertRaises(rpc_dispatcher.ExpectedException,
                                self.service.get_record,
                                self.context,
                                CentralZoneTestCase.zone__id_2,
                                CentralZoneTestCase.recordset__id,
                                CentralZoneTestCase.record__id)

        self.assertEqual(exceptions.RecordNotFound, exc.exc_info[0]) 
开发者ID:openstack,项目名称:designate,代码行数:27,代码来源:test_basic.py

示例10: test_is_valid_zone_name

# 需要导入模块: import testtools [as 别名]
# 或者: from testtools import ExpectedException [as 别名]
def test_is_valid_zone_name(self):
        self.config(max_zone_name_len=10,
                    group='service:central')

        context = self.get_context()

        self.central_service._is_valid_zone_name(context, 'valid.org.')

        with testtools.ExpectedException(exceptions.InvalidZoneName):
            self.central_service._is_valid_zone_name(context, 'example.org.')

        with testtools.ExpectedException(exceptions.InvalidZoneName):
            self.central_service._is_valid_zone_name(context, 'example.tld.')

        with testtools.ExpectedException(exceptions.InvalidZoneName):
            self.central_service._is_valid_zone_name(context, 'tld.') 
开发者ID:openstack,项目名称:designate,代码行数:18,代码来源:test_service.py

示例11: test_is_valid_zone_name_with_tlds

# 需要导入模块: import testtools [as 别名]
# 或者: from testtools import ExpectedException [as 别名]
def test_is_valid_zone_name_with_tlds(self):
        # Stop Service
        self.central_service.stop()
        list = objects.TldList()
        list.append(objects.Tld(name='com'))
        list.append(objects.Tld(name='biz'))
        list.append(objects.Tld(name='z'))

        with mock.patch.object(self.central_service.storage, 'find_tlds',
                return_value=list):
            self.central_service.start()

        context = self.get_context()
        with mock.patch.object(self.central_service.storage, 'find_tld',
                return_value=objects.Tld(name='biz')):
            with testtools.ExpectedException(exceptions.InvalidZoneName):
                self.central_service._is_valid_zone_name(context, 'biz.') 
开发者ID:openstack,项目名称:designate,代码行数:19,代码来源:test_service.py

示例12: test_create_blacklisted_zone_fail

# 需要导入模块: import testtools [as 别名]
# 或者: from testtools import ExpectedException [as 别名]
def test_create_blacklisted_zone_fail(self):
        self.create_blacklist()

        # Set the policy to reject the authz
        self.policy({'use_blacklisted_zone': '!'})

        values = dict(
            name='blacklisted.com.',
            email='info@blacklisted.com'
        )

        exc = self.assertRaises(rpc_dispatcher.ExpectedException,
                                self.central_service.create_zone,
                                self.admin_context,
                                objects.Zone.from_dict(values))

        self.assertEqual(exceptions.InvalidZoneName, exc.exc_info[0]) 
开发者ID:openstack,项目名称:designate,代码行数:19,代码来源:test_service.py

示例13: test_create_invalid_recordset_location_cname_at_apex

# 需要导入模块: import testtools [as 别名]
# 或者: from testtools import ExpectedException [as 别名]
def test_create_invalid_recordset_location_cname_at_apex(self):
        zone = self.create_zone()

        values = dict(
            name=zone['name'],
            type='CNAME'
        )

        # Attempt to create a CNAME record at the apex
        exc = self.assertRaises(rpc_dispatcher.ExpectedException,
                                self.central_service.create_recordset,
                                self.admin_context,
                                zone['id'],
                                recordset=objects.RecordSet.from_dict(values))

        self.assertEqual(exceptions.InvalidRecordSetLocation, exc.exc_info[0]) 
开发者ID:openstack,项目名称:designate,代码行数:18,代码来源:test_service.py

示例14: test_create_invalid_recordset_location_cname_sharing

# 需要导入模块: import testtools [as 别名]
# 或者: from testtools import ExpectedException [as 别名]
def test_create_invalid_recordset_location_cname_sharing(self):
        zone = self.create_zone()
        expected = self.create_recordset(zone)

        values = dict(
            name=expected['name'],
            type='CNAME'
        )

        # Attempt to create a CNAME record alongside another record
        exc = self.assertRaises(rpc_dispatcher.ExpectedException,
                                self.central_service.create_recordset,
                                self.admin_context,
                                zone['id'],
                                recordset=objects.RecordSet.from_dict(values))

        self.assertEqual(exceptions.InvalidRecordSetLocation, exc.exc_info[0]) 
开发者ID:openstack,项目名称:designate,代码行数:19,代码来源:test_service.py

示例15: test_create_invalid_recordset_location_wrong_zone

# 需要导入模块: import testtools [as 别名]
# 或者: from testtools import ExpectedException [as 别名]
def test_create_invalid_recordset_location_wrong_zone(self):
        zone = self.create_zone()
        other_zone = self.create_zone(fixture=1)

        values = dict(
            name=other_zone['name'],
            type='A'
        )

        # Attempt to create a record in the incorrect zone
        exc = self.assertRaises(rpc_dispatcher.ExpectedException,
                                self.central_service.create_recordset,
                                self.admin_context,
                                zone['id'],
                                recordset=objects.RecordSet.from_dict(values))

        self.assertEqual(exceptions.InvalidRecordSetLocation, exc.exc_info[0]) 
开发者ID:openstack,项目名称:designate,代码行数:19,代码来源:test_service.py


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