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


Python Error.to_json方法代码示例

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


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

示例1: ErrorTest

# 需要导入模块: from acme.messages import Error [as 别名]
# 或者: from acme.messages.Error import to_json [as 别名]
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,代码行数:31,代码来源:messages_test.py

示例2: ErrorTest

# 需要导入模块: from acme.messages import Error [as 别名]
# 或者: from acme.messages.Error import to_json [as 别名]
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,代码行数:59,代码来源:messages_test.py

示例3: ErrorTest

# 需要导入模块: from acme.messages import Error [as 别名]
# 或者: from acme.messages.Error import to_json [as 别名]
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,代码行数:56,代码来源:messages_test.py

示例4: ErrorTest

# 需要导入模块: from acme.messages import Error [as 别名]
# 或者: from acme.messages.Error import to_json [as 别名]
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,代码行数:42,代码来源:messages_test.py


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