def setUp(self):
        jwk = jose.JWKRSA(key=KEY.publickey())

        from letsencrypt.acme.messages import Authorization
        self.msg = Authorization(recovery_token='tok', jwk=jwk,
                                 identifier='example.com')

        self.jmsg = {
            'type': 'authorization',
            'recoveryToken': 'tok',
            'identifier': 'example.com',
            'jwk': jwk,
        }
    def test_json_without_optionals(self):
        del self.jmsg['recoveryToken']
        del self.jmsg['identifier']
        del self.jmsg['jwk']

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

        self.assertTrue(msg.recovery_token is None)
        self.assertTrue(msg.identifier is None)
        self.assertTrue(msg.jwk is None)
        self.assertEqual(self.jmsg, msg.to_json())
    def test_json_without_optionals(self):
        del self.jmsg['recoveryToken']
        del self.jmsg['identifier']
        del self.jmsg['jwk']

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

        self.assertTrue(msg.recovery_token is None)
        self.assertTrue(msg.identifier is None)
        self.assertTrue(msg.jwk is None)
        self.assertEqual(self.jmsg, msg.to_partial_json())
    def setUp(self):
        jwk = jose.JWKRSA(key=KEY.publickey())

        from letsencrypt.acme.messages import Authorization
        self.msg = Authorization(recovery_token='tok', jwk=jwk,
                                 identifier='example.com')

        self.jmsg = {
            'type': 'authorization',
            'recoveryToken': 'tok',
            'identifier': 'example.com',
            'jwk': jwk,
        }
class AuthorizationTest(unittest.TestCase):

    def setUp(self):
        jwk = jose.JWKRSA(key=KEY.publickey())

        from letsencrypt.acme.messages import Authorization
        self.msg = Authorization(recovery_token='tok', jwk=jwk,
                                 identifier='example.com')

        self.jmsg = {
            'type': 'authorization',
            'recoveryToken': 'tok',
            'identifier': 'example.com',
            'jwk': jwk,
        }

    def test_to_json(self):
        self.assertEqual(self.msg.to_json(), self.jmsg)

    def test_from_json(self):
        self.jmsg['jwk'] = self.jmsg['jwk'].to_json()

        from letsencrypt.acme.messages import Authorization
        self.assertEqual(Authorization.from_json(self.jmsg), self.msg)

    def test_json_without_optionals(self):
        del self.jmsg['recoveryToken']
        del self.jmsg['identifier']
        del self.jmsg['jwk']

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

        self.assertTrue(msg.recovery_token is None)
        self.assertTrue(msg.identifier is None)
        self.assertTrue(msg.jwk is None)
        self.assertEqual(self.jmsg, msg.to_json())
class AuthorizationTest(unittest.TestCase):

    def setUp(self):
        jwk = jose.JWKRSA(key=KEY.publickey())

        from letsencrypt.acme.messages import Authorization
        self.msg = Authorization(recovery_token='tok', jwk=jwk,
                                 identifier='example.com')

        self.jmsg = {
            'type': 'authorization',
            'recoveryToken': 'tok',
            'identifier': 'example.com',
            'jwk': jwk,
        }

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

    def test_from_json(self):
        self.jmsg['jwk'] = self.jmsg['jwk'].to_partial_json()

        from letsencrypt.acme.messages import Authorization
        self.assertEqual(Authorization.from_json(self.jmsg), self.msg)

    def test_json_without_optionals(self):
        del self.jmsg['recoveryToken']
        del self.jmsg['identifier']
        del self.jmsg['jwk']

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

        self.assertTrue(msg.recovery_token is None)
        self.assertTrue(msg.identifier is None)
        self.assertTrue(msg.jwk is None)
        self.assertEqual(self.jmsg, msg.to_partial_json())
    def test_from_json(self):
        self.jmsg['jwk'] = self.jmsg['jwk'].to_json()

        from letsencrypt.acme.messages import Authorization
        self.assertEqual(Authorization.from_json(self.jmsg), self.msg)
    def test_from_json(self):
        self.jmsg['jwk'] = self.jmsg['jwk'].to_partial_json()

        from letsencrypt.acme.messages import Authorization
        self.assertEqual(Authorization.from_json(self.jmsg), self.msg)