Exemplo n.º 1
0
 def test_setOpenIDNamespace_deprecated(self):
     message = Message()
     warning_msg = "Method 'setOpenIDNamespace' is deprecated. Pass namespace to Message constructor instead."
     with ShouldWarn(DeprecationWarning(warning_msg)):
         warnings.simplefilter('always')
         message.setOpenIDNamespace(OPENID2_NS, False)
     self.assertEqual(message.getOpenIDNamespace(), OPENID2_NS)
Exemplo n.º 2
0
 def test_public(self):
     dh = DiffieHellman.fromDefaults()
     self.setup_keys(dh, self.server_public_key, self.server_private_key)
     warning_msg = "Attribute 'public' is deprecated. Use 'public_key' instead."
     with ShouldWarn(DeprecationWarning(warning_msg)):
         warnings.simplefilter('always')
         self.assertEqual(dh.public, base64ToLong(self.server_public_key))
Exemplo n.º 3
0
 def test_version(self):
     warning_msg = "Module 'openid.extensions.draft.pape5' is deprecated in favor of 'openid.extensions.pape'."
     with ShouldWarn(DeprecationWarning(warning_msg)):
         warnings.simplefilter('always')
         from openid.extensions.draft import pape5
     self.assertEqual(pape.Request, pape5.Request)
     self.assertEqual(pape.Response, pape5.Response)
Exemplo n.º 4
0
 def test_normalized(self):
     self.assertEqual(urinorm('http://example.com/'), 'http://example.com/')
     warning_msg = "Binary input for urinorm is deprecated. Use text input instead."
     with ShouldWarn(DeprecationWarning(warning_msg)):
         warnings.simplefilter('always')
         self.assertEqual(urinorm(b'http://example.com/'),
                          'http://example.com/')
Exemplo n.º 5
0
 def test_no_warn_not_expected(self):
     with ShouldAssert("sequence not as expected:\n\n"
                       "same:\n[]\n\n"
                       "expected:\n[<C:" + warn_module +
                       ".UserWarning>args: ('foo',)</>]"
                       "\n\nactual:\n[]"):
         with ShouldWarn(UserWarning('foo')):
             pass
Exemplo n.º 6
0
 def test_multiple_warnings(self):
     with ShouldRaise(AssertionError) as s:
         with ShouldWarn(UserWarning('foo')):
             warnings.warn('foo')
             warnings.warn('bar')
     content = str(s.raised)
     self.assertTrue('foo' in content)
     self.assertTrue('bar' in content)
Exemplo n.º 7
0
    def test_binary_input(self):
        warning_msg = 'Conversion warning'
        with ShouldWarn(DeprecationWarning(warning_msg)):
            warnings.simplefilter('always')
            result = string_to_text('ěščřž'.encode('utf-8'), warning_msg)

        self.assertIsInstance(result, six.text_type)
        self.assertEqual(result, 'ěščřž')
Exemplo n.º 8
0
 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')
Exemplo n.º 9
0
 def test_minimal_bad(self):
     with ShouldAssert("sequence not as expected:\n\n"
                       "same:\n[]\n\n"
                       "expected:\n"
                       "[<C:" + warn_module +
                       ".DeprecationWarning(failed)>wrong type</>]\n\n"
                       "actual:\n[UserWarning('foo'" + comma + ")]"):
         with ShouldWarn(DeprecationWarning):
             warnings.warn('foo')
 def test_init_no_confirmation_method(self):
     with ShouldWarn(
             DeprecationWarning(
                 "Argument confirmation_method will be required.")):
         warnings.simplefilter('always')
         public_response = PublicResponse(sentinel.object_type,
                                          sentinel.public_request_id,
                                          sentinel.request_type,
                                          sentinel.handle)
     self.assertIsNone(public_response.confirmation_method)
Exemplo n.º 11
0
 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')
Exemplo n.º 12
0
 def test_no_warn_not_expected(self):
     with ShouldRaise(
             AssertionError("sequence not as expected:\n\n"
                            "same:\n[]\n\n"
                            "expected:\n[\n  <C:" + warn_module +
                            ".UserWarning>\n"
                            "  args:('foo',)\n  </C>]"
                            "\n\nactual:\n[]")):
         with ShouldWarn(UserWarning('foo')):
             pass
Exemplo n.º 13
0
 def test_minimal_bad(self):
     with ShouldRaise(
             AssertionError("sequence not as expected:\n\n"
                            "same:\n[]\n\n"
                            "expected:\n"
                            "[<C(failed):" + warn_module +
                            ".DeprecationWarning>wrong type</C>]\n\n"
                            "actual:\n[UserWarning('foo',)]")):
         with ShouldWarn(DeprecationWarning):
             warnings.warn('foo')
Exemplo n.º 14
0
 def test_getSharedSecret(self):
     # Test the deprecated method
     consumer_dh = DiffieHellman.fromDefaults()
     self.setup_keys(consumer_dh, self.consumer_public_key,
                     self.consumer_private_key)
     warning_msg = "Method 'getSharedSecret' is deprecated in favor of '_get_shared_secret'."
     with ShouldWarn(DeprecationWarning(warning_msg)):
         warnings.simplefilter('always')
         self.assertEqual(
             consumer_dh.getSharedSecret(self.server_public_key),
             base64ToLong(self.shared_secret))
Exemplo n.º 15
0
 def test_modulus(self):
     dh = DiffieHellman.fromDefaults()
     modulus = int(
         '155172898181473697471232257763715539915724801966915404479707795314057629378541917580651227423698'
         '188993727816152646631438561595825688188889951272158842675419950341258706556549803580104870537681'
         '476726513255747040765857479291291572334510643245094715007229621094194349783925984760375594985848'
         '253359305585439638443')
     warning_msg = "Modulus property will return base64 encoded string."
     with ShouldWarn(DeprecationWarning(warning_msg)):
         warnings.simplefilter('always')
         self.assertEqual(dh.modulus, modulus)
Exemplo n.º 16
0
 def test_maximal_bad(self):
     with ShouldAssert(
             "sequence not as expected:\n\n"
             "same:\n[]\n\n"
             "expected:\n[\n"
             "<C(failed):" + warn_module + ".DeprecationWarning>\n"
             "attributes differ:\n"
             "'args': ('bar',) (Comparison) != ('foo',) (actual)\n</C>]\n\n"
             "actual:\n[DeprecationWarning('foo'" + comma + ")]"):
         with ShouldWarn(DeprecationWarning('bar')):
             warnings.warn_explicit('foo', DeprecationWarning, 'bar.py', 42,
                                    'bar_module')
Exemplo n.º 17
0
 def test_maximal_bad(self):
     with ShouldRaise(
             AssertionError("sequence not as expected:\n\n"
                            "same:\n[]\n\n"
                            "expected:\n[\n"
                            "  <C(failed):" + warn_module +
                            ".DeprecationWarning>\n"
                            "  args:('bar',) != ('foo',)"
                            "\n  </C>]\n\n"
                            "actual:\n[DeprecationWarning('foo',)]")):
         with ShouldWarn(DeprecationWarning('bar')):
             warnings.warn_explicit('foo', DeprecationWarning, 'bar.py', 42,
                                    'bar_module')
Exemplo n.º 18
0
 def test_filter_missing(self):
     if PY3:
         type_repr = 'builtins.DeprecationWarning'
     else:
         type_repr = 'exceptions.DeprecationWarning'
     with ShouldAssert("sequence not as expected:\n\n"
                       "same:\n[]\n\n"
                       "expected:\n[<C:{}>]\n\n"
                       "actual:\n[]".format(type_repr)):
         with ShouldWarn(DeprecationWarning,
                         message="This function is deprecated."):
             warnings.warn("This utility is deprecated.",
                           DeprecationWarning)
Exemplo n.º 19
0
 def test_maximal_explore(self):
     with ShouldWarn() as recorded:
         warnings.warn_explicit('foo', DeprecationWarning, 'bar.py', 42,
                                'bar_module')
     compare(len(recorded), expected=1)
     compare(
         C(warnings.WarningMessage,
           _category_name='DeprecationWarning',
           category=DeprecationWarning,
           file=None,
           filename='bar.py',
           line=None,
           lineno=42,
           message=C(DeprecationWarning('foo'))), recorded[0])
Exemplo n.º 20
0
    def test_xorSecret(self):
        # Test key exchange - deprecated method
        server_dh = DiffieHellman.fromDefaults()
        self.setup_keys(server_dh, self.server_public_key,
                        self.server_private_key)

        def sha256(value):
            digest = hashes.Hash(hashes.SHA256(), backend=default_backend())
            digest.update(value)
            return digest.finalize()

        warning_msg = "Method 'xorSecret' is deprecated, use 'xor_secret' instead."
        with ShouldWarn(DeprecationWarning(warning_msg)):
            warnings.simplefilter('always')
            secret = server_dh.xorSecret(
                base64ToLong(self.consumer_public_key),
                base64.b64decode(self.secret), sha256)
            self.assertEqual(secret, base64.b64decode(self.mac_key))
Exemplo n.º 21
0
    def test_maximal_explore(self):
        with ShouldWarn() as recorded:
            warnings.warn_explicit('foo', DeprecationWarning, 'bar.py', 42,
                                   'bar_module')
        compare(len(recorded), expected=1)

        expected_attrs = dict(
            _category_name='DeprecationWarning',
            category=DeprecationWarning,
            file=None,
            filename='bar.py',
            line=None,
            lineno=42,
            message=C(DeprecationWarning('foo')),
        )

        if PY_36_PLUS:
            expected_attrs['source'] = None

        compare(expected=C(warnings.WarningMessage, **expected_attrs),
                actual=recorded[0])
Exemplo n.º 22
0
    def test_registrars_old_context(self):
        # Test deprecated `_registrar_row` works correctly
        registrar = make_registrar()
        WHOIS.get_registrars.return_value = [registrar]
        WHOIS.get_registrar_groups.return_value = []
        WHOIS.get_registrar_certification_list.return_value = []

        warn_msg = (
            "Method 'RegistrarListView._registrar_row' is deprecated in favor of "
            "'RegistrarListView.get_registrar_context'.")
        with ShouldWarn(DeprecationWarning(warn_msg)):
            warnings.simplefilter('always')
            response = self.client.get(reverse('registrars_custom'))

        self.assertContains(response, "List of registrars")
        self.assertEqual(len(response.context['registrars']), 1)
        self.assertTrue(response.context['registrars'][0]['custom'])
        self.assertEqual(WHOIS.mock_calls, [
            call.get_registrars(),
            call.get_registrar_certification_list(),
            call.get_registrar_groups()
        ])
Exemplo n.º 23
0
 def test_corba_get_object_text(self):
     corba_obj = CorbaNameServiceClient()
     with patch('pyfco.name_service.installTransientExceptionHandler', autospec=True), \
             patch('pyfco.name_service.CORBA.ORB_init', autospec=True) as init_mock, \
             patch.object(CosNaming, "NameComponent") as mock_name_component, \
             ShouldWarn(DeprecationWarning("Passing 'name' as six.binary_type is deprecated. "
                                           "Please pass six.text_type.")):
         corba_obj.get_object(b"Logger", "ccRegTest.Logger")
     if six.PY2:  # pragma: no cover
         name_calls = [call('fred'.encode(), 'context'.encode()),
                       call('Logger'.encode(), 'Object'.encode())]
         init_calls = [call(['-ORBnativeCharCodeSet'.encode(), 'UTF-8'.encode()])]
     else:  # pragma: no cover
         name_calls = [call('fred', 'context'),
                       call('Logger', 'Object')]
         init_calls = [call(['-ORBnativeCharCodeSet', 'UTF-8'])]
     self.assertEqual(mock_name_component.mock_calls, name_calls)
     init_calls.extend([call().string_to_object('corbaname::localhost'),
                        call().string_to_object()._narrow(CosNaming.NamingContext),
                        call().string_to_object()._narrow().resolve([mock_name_component(), mock_name_component()]),
                        call().string_to_object()._narrow().resolve()._narrow('ccRegTest.Logger')])
     self.assertEqual(init_mock.mock_calls, init_calls)
Exemplo n.º 24
0
    def test_openid_namespace_invalid(self):
        invalid_things = [
            # Empty string is not okay here.
            '',
            # Good guess!  But wrong.
            'http://openid.net/signon/2.0',
            # What?
            'http://specs%\\\r2Eopenid.net/auth/2.0',
            # Too much escapings!
            'http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0',
            # This is a Type URI, not a openid.ns value.
            'http://specs.openid.net/auth/2.0/signon',
        ]
        warning_msg = "Method 'setOpenIDNamespace' is deprecated. Pass namespace to Message constructor instead."

        for x in invalid_things:
            self.assertRaises(InvalidOpenIDNamespace, Message, x, False)
            # Test also deprecated setOpenIDNamespace
            message = Message()
            with ShouldWarn(DeprecationWarning(warning_msg)):
                warnings.simplefilter('always')
                self.assertRaises(InvalidOpenIDNamespace, message.setOpenIDNamespace, x, False)
Exemplo n.º 25
0
 def test_maximal_ok(self):
     with ShouldWarn(DeprecationWarning('foo')):
         warnings.warn_explicit('foo', DeprecationWarning, 'bar.py', 42,
                                'bar_module')
Exemplo n.º 26
0
 def test_minimal_ok(self):
     with ShouldWarn(UserWarning):
         warnings.warn('foo')
Exemplo n.º 27
0
 def test_filters_removed(self):
     with warnings.catch_warnings():
         warnings.simplefilter("ignore")
         with ShouldWarn(UserWarning("foo")):
             warnings.warn('foo')
Exemplo n.º 28
0
 def test_init_host_port_bytes(self):
     with ShouldWarn(DeprecationWarning("Passing 'host_port' as six.binary_type is deprecated. "
                                        "Please pass six.text_type.")):
         corba_obj = CorbaNameServiceClient(host_port=b'test')
     self.assertIsInstance(corba_obj.host_port, six.text_type)
Exemplo n.º 29
0
 def test_warn_expected(self):
     with warnings.catch_warnings(record=True) as backstop:
         with ShouldWarn(UserWarning('foo')):
             warnings.warn('foo')
     compare(len(backstop), expected=0)
Exemplo n.º 30
0
 def test_filter_present(self):
     with ShouldWarn(DeprecationWarning,
                     message="This function is deprecated."):
         warnings.warn("This utility is deprecated.", DeprecationWarning)
         warnings.warn("This function is deprecated.", DeprecationWarning)