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


Python messages.Error类代码示例

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


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

示例1: ErrorTest

class ErrorTest(unittest.TestCase):
    """Tests for acme.messages.Error."""

    def setUp(self):
        from acme.messages import Error
        self.error = Error(
            detail='foo', typ='urn:acme:error:malformed', title='title')
        self.jobj = {
            'detail': 'foo',
            'title': 'some title',
            'type': 'urn:acme:error:malformed',
        }
        self.error_custom = Error(typ='custom', detail='bar')
        self.jobj_cusom = {'type': 'custom', 'detail': 'bar'}

    def test_from_json_hashable(self):
        from acme.messages import Error
        hash(Error.from_json(self.error.to_json()))

    def test_description(self):
        self.assertEqual(
            'The request message was malformed', self.error.description)
        self.assertTrue(self.error_custom.description is None)

    def test_str(self):
        self.assertEqual(
            'urn:acme:error:malformed :: The request message was '
            'malformed :: foo :: title', str(self.error))
        self.assertEqual('custom :: bar', str(self.error_custom))
开发者ID:HenryKamg,项目名称:letsencrypt,代码行数:29,代码来源:messages_test.py

示例2: ErrorTest

class ErrorTest(unittest.TestCase):

    def setUp(self):
        from acme.messages import Error
        self.msg = Error(
            error='badCSR', message='RSA keys must be at least 2048 bits long',
            more_info='https://ca.example.com/documentation/csr-requirements')

        self.jmsg = {
            'type': 'error',
            'error': 'badCSR',
            'message':'RSA keys must be at least 2048 bits long',
            'moreInfo': 'https://ca.example.com/documentation/csr-requirements',
        }

    def test_to_partial_json(self):
        self.assertEqual(self.msg.to_partial_json(), self.jmsg)

    def test_from_json(self):
        from acme.messages import Error
        self.assertEqual(Error.from_json(self.jmsg), self.msg)

    def test_json_without_optionals(self):
        del self.jmsg['message']
        del self.jmsg['moreInfo']

        from acme.messages import Error
        msg = Error.from_json(self.jmsg)

        self.assertTrue(msg.message is None)
        self.assertTrue(msg.more_info is None)
        self.assertEqual(self.jmsg, msg.to_partial_json())
开发者ID:QuantumGhost,项目名称:lets-encrypt-preview,代码行数:32,代码来源:messages_test.py

示例3: ErrorTest

class ErrorTest(unittest.TestCase):
    """Tests for acme.messages.Error."""

    def setUp(self):
        from acme.messages import Error, ERROR_PREFIX
        self.error = Error(
            detail='foo', typ=ERROR_PREFIX + 'malformed', title='title')
        self.jobj = {
            'detail': 'foo',
            'title': 'some title',
            'type': ERROR_PREFIX + 'malformed',
        }
        self.error_custom = Error(typ='custom', detail='bar')
        self.empty_error = Error()
        self.jobj_custom = {'type': 'custom', 'detail': 'bar'}

    def test_default_typ(self):
        from acme.messages import Error
        self.assertEqual(Error().typ, 'about:blank')

    def test_from_json_empty(self):
        from acme.messages import Error
        self.assertEqual(Error(), Error.from_json('{}'))

    def test_from_json_hashable(self):
        from acme.messages import Error
        hash(Error.from_json(self.error.to_json()))

    def test_description(self):
        self.assertEqual(
            'The request message was malformed', self.error.description)
        self.assertTrue(self.error_custom.description is None)

    def test_code(self):
        from acme.messages import Error
        self.assertEqual('malformed', self.error.code)
        self.assertEqual(None, self.error_custom.code)
        self.assertEqual(None, Error().code)

    def test_is_acme_error(self):
        from acme.messages import is_acme_error
        self.assertTrue(is_acme_error(self.error))
        self.assertFalse(is_acme_error(self.error_custom))
        self.assertFalse(is_acme_error(self.empty_error))
        self.assertFalse(is_acme_error("must pet all the {dogs|rabbits}"))

    def test_unicode_error(self):
        from acme.messages import Error, ERROR_PREFIX, is_acme_error
        arabic_error = Error(
                detail=u'\u0639\u062f\u0627\u0644\u0629', typ=ERROR_PREFIX + 'malformed',
            title='title')
        self.assertTrue(is_acme_error(arabic_error))

    def test_with_code(self):
        from acme.messages import Error, is_acme_error
        self.assertTrue(is_acme_error(Error.with_code('badCSR')))
        self.assertRaises(ValueError, Error.with_code, 'not an ACME error code')
开发者ID:pombredanne,项目名称:certbot,代码行数:57,代码来源:messages_test.py

示例4: test_json_without_optionals

    def test_json_without_optionals(self):
        del self.jmsg['message']
        del self.jmsg['moreInfo']

        from acme.messages import Error
        msg = Error.from_json(self.jmsg)

        self.assertTrue(msg.message is None)
        self.assertTrue(msg.more_info is None)
        self.assertEqual(self.jmsg, msg.to_partial_json())
开发者ID:QuantumGhost,项目名称:lets-encrypt-preview,代码行数:10,代码来源:messages_test.py

示例5: setUp

 def setUp(self):
     from acme.messages import Error, ERROR_PREFIX
     self.error = Error(
         detail='foo', typ=ERROR_PREFIX + 'malformed', title='title')
     self.jobj = {
         'detail': 'foo',
         'title': 'some title',
         'type': ERROR_PREFIX + 'malformed',
     }
     self.error_custom = Error(typ='custom', detail='bar')
     self.jobj_custom = {'type': 'custom', 'detail': 'bar'}
开发者ID:MichalMMac,项目名称:certbot,代码行数:11,代码来源:messages_test.py

示例6: ErrorTest

class ErrorTest(unittest.TestCase):
    """Tests for acme.messages.Error."""

    def setUp(self):
        from acme.messages import Error, ERROR_PREFIX
        self.error = Error(
            detail='foo', typ=ERROR_PREFIX + 'malformed', title='title')
        self.jobj = {
            'detail': 'foo',
            'title': 'some title',
            'type': ERROR_PREFIX + 'malformed',
        }
        self.error_custom = Error(typ='custom', detail='bar')
        self.jobj_custom = {'type': 'custom', 'detail': 'bar'}

    def test_default_typ(self):
        from acme.messages import Error
        self.assertEqual(Error().typ, 'about:blank')

    def test_from_json_empty(self):
        from acme.messages import Error
        self.assertEqual(Error(), Error.from_json('{}'))

    def test_from_json_hashable(self):
        from acme.messages import Error
        hash(Error.from_json(self.error.to_json()))

    def test_description(self):
        self.assertEqual(
            'The request message was malformed', self.error.description)
        self.assertTrue(self.error_custom.description is None)

    def test_str(self):
        self.assertEqual(
            'urn:ietf:params:acme:error:malformed :: The request message was '
            'malformed :: foo :: title', str(self.error))
        self.assertEqual('custom :: bar', str(self.error_custom))

    def test_code(self):
        from acme.messages import Error
        self.assertEqual('malformed', self.error.code)
        self.assertEqual(None, self.error_custom.code)
        self.assertEqual(None, Error().code)

    def test_is_acme_error(self):
        from acme.messages import is_acme_error
        self.assertTrue(is_acme_error(self.error))
        self.assertTrue(is_acme_error(str(self.error)))
        self.assertFalse(is_acme_error(self.error_custom))

    def test_with_code(self):
        from acme.messages import Error, is_acme_error
        self.assertTrue(is_acme_error(Error.with_code('badCSR')))
        self.assertRaises(ValueError, Error.with_code, 'not an ACME error code')
开发者ID:MichalMMac,项目名称:certbot,代码行数:54,代码来源:messages_test.py

示例7: setUp

 def setUp(self):
     from acme.messages import Error
     self.error = Error(
         detail='foo', typ='urn:acme:error:malformed', title='title')
     self.jobj = {
         'detail': 'foo',
         'title': 'some title',
         'type': 'urn:acme:error:malformed',
     }
     self.error_custom = Error(typ='custom', detail='bar')
     self.jobj_cusom = {'type': 'custom', 'detail': 'bar'}
开发者ID:AndyGWood1,项目名称:certbot,代码行数:11,代码来源:messages_test.py

示例8: setUp

    def setUp(self):
        from acme.messages import Error
        self.msg = Error(
            error='badCSR', message='RSA keys must be at least 2048 bits long',
            more_info='https://ca.example.com/documentation/csr-requirements')

        self.jmsg = {
            'type': 'error',
            'error': 'badCSR',
            'message':'RSA keys must be at least 2048 bits long',
            'moreInfo': 'https://ca.example.com/documentation/csr-requirements',
        }
开发者ID:QuantumGhost,项目名称:lets-encrypt-preview,代码行数:12,代码来源:messages_test.py

示例9: ErrorTest

class ErrorTest(unittest.TestCase):
    """Tests for acme.messages.Error."""

    def setUp(self):
        from acme.messages import Error
        self.error = Error(detail='foo', typ='malformed', title='title')
        self.jobj = {'detail': 'foo', 'title': 'some title'}

    def test_typ_prefix(self):
        self.assertEqual('malformed', self.error.typ)
        self.assertEqual(
            'urn:acme:error:malformed', self.error.to_partial_json()['type'])
        self.assertEqual(
            'malformed', self.error.from_json(self.error.to_partial_json()).typ)

    def test_typ_decoder_missing_prefix(self):
        from acme.messages import Error
        self.jobj['type'] = 'malformed'
        self.assertRaises(jose.DeserializationError, Error.from_json, self.jobj)
        self.jobj['type'] = 'not valid bare type'
        self.assertRaises(jose.DeserializationError, Error.from_json, self.jobj)

    def test_typ_decoder_not_recognized(self):
        from acme.messages import Error
        self.jobj['type'] = 'urn:acme:error:baz'
        self.assertRaises(jose.DeserializationError, Error.from_json, self.jobj)

    def test_description(self):
        self.assertEqual(
            'The request message was malformed', self.error.description)

    def test_from_json_hashable(self):
        from acme.messages import Error
        hash(Error.from_json(self.error.to_json()))

    def test_str(self):
        self.assertEqual(
            'malformed :: The request message was malformed :: foo',
            str(self.error))
        self.assertEqual('foo', str(self.error.update(typ=None)))
开发者ID:g1franc,项目名称:lets-encrypt-preview,代码行数:40,代码来源:messages_test.py

示例10: test_from_json_hashable

 def test_from_json_hashable(self):
     from acme.messages import Error
     hash(Error.from_json(self.error.to_json()))
开发者ID:g1franc,项目名称:lets-encrypt-preview,代码行数:3,代码来源:messages_test.py

示例11: setUp

 def setUp(self):
     from acme.messages import Error
     self.error = Error(detail='foo', typ='malformed', title='title')
     self.jobj = {'detail': 'foo', 'title': 'some title'}
开发者ID:g1franc,项目名称:lets-encrypt-preview,代码行数:4,代码来源:messages_test.py

示例12: test_with_code

 def test_with_code(self):
     from acme.messages import Error, is_acme_error
     self.assertTrue(is_acme_error(Error.with_code('badCSR')))
     self.assertRaises(ValueError, Error.with_code, 'not an ACME error code')
开发者ID:MichalMMac,项目名称:certbot,代码行数:4,代码来源:messages_test.py

示例13: test_from_json_empty

 def test_from_json_empty(self):
     from acme.messages import Error
     self.assertEqual(Error(), Error.from_json('{}'))
开发者ID:MichalMMac,项目名称:certbot,代码行数:3,代码来源:messages_test.py

示例14: test_from_json

 def test_from_json(self):
     from acme.messages import Error
     self.assertEqual(Error.from_json(self.jmsg), self.msg)
开发者ID:QuantumGhost,项目名称:lets-encrypt-preview,代码行数:3,代码来源:messages_test.py


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