コード例 #1
0
 def test_isOpenID2(self):
     ns = 'http://specs.openid.net/auth/2.0'
     m = Message(ns)
     self.assertTrue(m.isOpenID2())
     self.assertFalse(m.namespaces.isImplicit(NULL_NAMESPACE))
     self.assertEqual(m.getOpenIDNamespace(), ns)
コード例 #2
0
class EmptyMessageTest(unittest.TestCase):
    def setUp(self):
        self.msg = Message()

    def test_toPostArgs(self):
        self.assertEqual(self.msg.toPostArgs(), {})

    def test_toArgs(self):
        self.assertEqual(self.msg.toArgs(), {})

    def test_toKVForm(self):
        self.assertEqual(self.msg.toKVForm(), '')

    def test_toURLEncoded(self):
        self.assertEqual(self.msg.toURLEncoded(), '')

    def test_toURL(self):
        base_url = 'http://base.url/'
        self.assertEqual(self.msg.toURL(base_url), base_url)

    def test_getOpenID(self):
        self.assertIsNone(self.msg.getOpenIDNamespace())

    def test_getKeyOpenID(self):
        # Could reasonably return None instead of raising an
        # exception. I'm not sure which one is more right, since this
        # case should only happen when you're building a message from
        # scratch and so have no default namespace.
        warning_msg = "UndefinedOpenIDNamespace exception is deprecated."
        with ShouldWarn(DeprecationWarning(warning_msg)):
            warnings.simplefilter('always')
            self.assertRaises(UndefinedOpenIDNamespace, self.msg.getKey, OPENID_NS, 'foo')

    def test_getKeyBARE(self):
        self.assertEqual(self.msg.getKey(BARE_NS, 'foo'), 'foo')

    def test_getKeyNS1(self):
        self.assertIsNone(self.msg.getKey(OPENID1_NS, 'foo'))

    def test_getKeyNS2(self):
        self.assertIsNone(self.msg.getKey(OPENID2_NS, 'foo'))

    def test_getKeyNS3(self):
        self.assertIsNone(self.msg.getKey('urn:nothing-significant', 'foo'))

    def test_hasKey(self):
        # Could reasonably return False instead of raising an
        # exception. I'm not sure which one is more right, since this
        # case should only happen when you're building a message from
        # scratch and so have no default namespace.
        warning_msg = "UndefinedOpenIDNamespace exception is deprecated."
        with ShouldWarn(DeprecationWarning(warning_msg)):
            warnings.simplefilter('always')
            self.assertRaises(UndefinedOpenIDNamespace, self.msg.hasKey, OPENID_NS, 'foo')

    def test_hasKeyBARE(self):
        self.assertFalse(self.msg.hasKey(BARE_NS, 'foo'))

    def test_hasKeyNS1(self):
        self.assertFalse(self.msg.hasKey(OPENID1_NS, 'foo'))

    def test_hasKeyNS2(self):
        self.assertFalse(self.msg.hasKey(OPENID2_NS, 'foo'))

    def test_hasKeyNS3(self):
        self.assertFalse(self.msg.hasKey('urn:nothing-significant', 'foo'))

    def test_getAliasedArgSuccess(self):
        msg = Message.fromPostArgs({'openid.ns.test': 'urn://foo', 'openid.test.flub': 'bogus'})
        actual_uri = msg.getAliasedArg('ns.test', no_default)
        self.assertEqual("urn://foo", actual_uri)

    def test_getAliasedArgFailure(self):
        msg = Message.fromPostArgs({'openid.test.flub': 'bogus'})
        self.assertRaises(KeyError, msg.getAliasedArg, 'ns.test', no_default)

    def test_getArg(self):
        # Could reasonably return None instead of raising an
        # exception. I'm not sure which one is more right, since this
        # case should only happen when you're building a message from
        # scratch and so have no default namespace.
        warning_msg = "UndefinedOpenIDNamespace exception is deprecated."
        with ShouldWarn(DeprecationWarning(warning_msg)):
            warnings.simplefilter('always')
            self.assertRaises(UndefinedOpenIDNamespace, self.msg.getArg, OPENID_NS, 'foo')

    test_getArgBARE = mkGetArgTest(BARE_NS, 'foo')
    test_getArgNS1 = mkGetArgTest(OPENID1_NS, 'foo')
    test_getArgNS2 = mkGetArgTest(OPENID2_NS, 'foo')
    test_getArgNS3 = mkGetArgTest('urn:nothing-significant', 'foo')

    def test_getArgs(self):
        # Could reasonably return {} instead of raising an
        # exception. I'm not sure which one is more right, since this
        # case should only happen when you're building a message from
        # scratch and so have no default namespace.
        warning_msg = "UndefinedOpenIDNamespace exception is deprecated."
        with ShouldWarn(DeprecationWarning(warning_msg)):
            warnings.simplefilter('always')
            self.assertRaises(UndefinedOpenIDNamespace, self.msg.getArgs, OPENID_NS)

    def test_getArgsBARE(self):
        self.assertEqual(self.msg.getArgs(BARE_NS), {})

    def test_getArgsNS1(self):
        self.assertEqual(self.msg.getArgs(OPENID1_NS), {})

    def test_getArgsNS2(self):
        self.assertEqual(self.msg.getArgs(OPENID2_NS), {})

    def test_getArgsNS3(self):
        self.assertEqual(self.msg.getArgs('urn:nothing-significant'), {})

    def test_updateArgs(self):
        warning_msg = "UndefinedOpenIDNamespace exception is deprecated."
        with ShouldWarn(DeprecationWarning(warning_msg)):
            warnings.simplefilter('always')
            self.assertRaises(UndefinedOpenIDNamespace, self.msg.updateArgs, OPENID_NS, {'does not': 'matter'})

    def _test_updateArgsNS(self, ns):
        update_args = {
            'Camper van Beethoven': 'David Lowery',
            'Magnolia Electric Co.': 'Jason Molina',
        }

        self.assertEqual(self.msg.getArgs(ns), {})
        self.msg.updateArgs(ns, update_args)
        self.assertEqual(self.msg.getArgs(ns), update_args)

    def test_updateArgsBARE(self):
        self._test_updateArgsNS(BARE_NS)

    def test_updateArgsNS1(self):
        self._test_updateArgsNS(OPENID1_NS)

    def test_updateArgsNS2(self):
        self._test_updateArgsNS(OPENID2_NS)

    def test_updateArgsNS3(self):
        self._test_updateArgsNS('urn:nothing-significant')

    def test_setArg(self):
        warning_msg = "UndefinedOpenIDNamespace exception is deprecated."
        with ShouldWarn(DeprecationWarning(warning_msg)):
            warnings.simplefilter('always')
            self.assertRaises(UndefinedOpenIDNamespace, self.msg.setArg, OPENID_NS, 'does not', 'matter')

    def _test_setArgNS(self, ns):
        key = 'Camper van Beethoven'
        value = 'David Lowery'
        self.assertIsNone(self.msg.getArg(ns, key))
        self.msg.setArg(ns, key, value)
        self.assertEqual(self.msg.getArg(ns, key), value)

    def test_setArgBARE(self):
        self._test_setArgNS(BARE_NS)

    def test_setArgNS1(self):
        self._test_setArgNS(OPENID1_NS)

    def test_setArgNS2(self):
        self._test_setArgNS(OPENID2_NS)

    def test_setArgNS3(self):
        self._test_setArgNS('urn:nothing-significant')

    def test_setArgToNone(self):
        self.assertRaises(AssertionError, self.msg.setArg, OPENID1_NS, 'op_endpoint', None)

    def test_delArg(self):
        # Could reasonably raise KeyError instead of raising
        # UndefinedOpenIDNamespace. I'm not sure which one is more
        # right, since this case should only happen when you're
        # building a message from scratch and so have no default
        # namespace.
        warning_msg = "UndefinedOpenIDNamespace exception is deprecated."
        with ShouldWarn(DeprecationWarning(warning_msg)):
            warnings.simplefilter('always')
            self.assertRaises(UndefinedOpenIDNamespace, self.msg.delArg, OPENID_NS, 'key')

    def _test_delArgNS(self, ns):
        key = 'Camper van Beethoven'
        self.assertRaises(KeyError, self.msg.delArg, ns, key)

    def test_delArgBARE(self):
        self._test_delArgNS(BARE_NS)

    def test_delArgNS1(self):
        self._test_delArgNS(OPENID1_NS)

    def test_delArgNS2(self):
        self._test_delArgNS(OPENID2_NS)

    def test_delArgNS3(self):
        self._test_delArgNS('urn:nothing-significant')

    def test_isOpenID1(self):
        self.assertFalse(self.msg.isOpenID1())

    def test_isOpenID2(self):
        self.assertFalse(self.msg.isOpenID2())