Ticket #6166: ticket6166-3.patch

File ticket6166-3.patch, 5.4 KB (added by Can Ibanoglu, 8 years ago)

Tests now use callDeprecated to test deprecations, use .suppress attribute to suppress deprecation warning messages

  • twisted/test/test_sslverify.py

     
    1919    pass
    2020
    2121from twisted.python.compat import nativeString
    22 from twisted.trial import unittest
     22from twisted.trial import unittest, util
    2323from twisted.internet import protocol, defer, reactor
    2424
    2525from twisted.internet.error import CertificateError, ConnectionLost
    2626from twisted.internet import interfaces
     27from twisted.python.versions import Version
    2728
    2829
    2930# A couple of static PEM-format certificates to be used by various tests.
     
    373374        self.assertEqual(opts.fixBrokenPeers, True)
    374375        self.assertEqual(opts.enableSessionTickets, True)
    375376
     377    test_certificateOptionsSerialization.suppress = [util.suppress(
     378        category = DeprecationWarning)]
    376379
     380
    377381    def test_certificateOptionsSessionTickets(self):
    378382        """
    379383        Enabling session tickets should not set the OP_NO_TICKET option.
     
    549553        ctx = opts.getContext()
    550554        self.assertEqual(SSL.OP_NO_SSLv2, ctx.set_options(0) & SSL.OP_NO_SSLv2)
    551555
     556    def test_getstateDeprecation(self):
     557        """
     558        Test deprecation of L{_sslverify.OpenSSLCertificateOptions.__getstate__}.
     559        See #6166 for removal.
     560        """
     561        self.callDeprecated(
     562            (Version("Twisted", 13, 1, 0), "a real persistence system"),
     563            sslverify.OpenSSLCertificateOptions().__getstate__)
    552564
     565    def test_setstateDeprecation(self):
     566        """
     567        Test deprecation of L{_sslverify.OpenSSLCertificateOptions.__setstate__}.
     568        See #6166 for removal.
     569        """
     570        state = sslverify.OpenSSLCertificateOptions().__getstate__()
     571        self.callDeprecated(
     572            (Version("Twisted", 13, 1, 0), "a real persistence system"),
     573            sslverify.OpenSSLCertificateOptions().__setstate__, state)
    553574
     575    test_setstateDeprecation.suppress = [util.suppress(
     576        message = "twisted.internet._sslverify.OpenSSLCertificateOptions.__getstate__ "
     577        "was deprecated in Twisted 13.1.0; please use a real persistence system instead",
     578        category = DeprecationWarning)]
     579
     580
     581
    554582if interfaces.IReactorSSL(reactor, None) is None:
    555583    OpenSSLOptions.skip = "Reactor does not support SSL, cannot run SSL tests"
    556584
     
    648676
    649677if interfaces.IReactorSSL(reactor, None) is None:
    650678    Constructors.skip = "Reactor does not support SSL, cannot run SSL tests"
     679
     680class KeyPair(unittest.TestCase):
     681    sKey = makeCertificate(
     682        O=b"Server Test Certificate",
     683        CN=b"server")[0]
     684
     685    def test_getstateDeprecation(self):
     686        """
     687        Test deprecation of L{_sslverify.KeyPair.__getstate__}.
     688        See #6166 for removal.
     689        """
     690        self.callDeprecated(
     691            (Version("Twisted", 13, 1, 0), "a real persistence system"),
     692            sslverify.KeyPair(self.sKey).__getstate__)
     693
     694    def test_setstateDeprecation(self):
     695        """
     696        Test deprecation of L{_sslverify.KeyPair.__setstate__}.
     697        See #6166 for removal.
     698        """
     699        state = sslverify.KeyPair(self.sKey).__getstate__()
     700        self.callDeprecated(
     701            (Version("Twisted", 13, 1, 0), "a real persistence system"),
     702            sslverify.KeyPair(self.sKey).__setstate__, state)
     703
     704    test_setstateDeprecation.suppress = [util.suppress(
     705        message = "twisted.internet._sslverify.KeyPair.__getstate__ "
     706        "was deprecated in Twisted 13.1.0; please use a real persistence system instead",
     707        category = DeprecationWarning)]
  • twisted/topfiles/6166.removal

     
     1Pickling twisted.internet._sslverify.OptionSSLCertificationOptions and twisted.internet._sslverify.Keypair is no longer supported.
     2__getstate__ and __setstate__ methods of these classes have been deprecated.
  • twisted/internet/_sslverify.py

     
    1414from twisted.python import _reflectpy3 as reflect, util
    1515from twisted.internet.defer import Deferred
    1616from twisted.internet.error import VerifyError, CertificateError
     17from twisted.python.deprecate import deprecated
     18from twisted.python.versions import Version
    1719
    1820def _sessionCounter(counter=itertools.count()):
    1921    """
     
    619621            self.signRequestObject(dn, self.requestObject(dn), serialNumber),
    620622            self)
    621623
     624KeyPair.__getstate__ = deprecated(Version("Twisted", 13, 1, 0),
     625    "a real persistence system")(KeyPair.__getstate__)
     626KeyPair.__setstate__ = deprecated(Version("Twisted", 13, 1, 0),
     627    "a real persistence system")(KeyPair.__setstate__)
    622628
    623629
     630
    624631class OpenSSLCertificateOptions(object):
    625632    """
    626633    A factory for SSL context objects for both SSL servers and clients.
     
    789796            ctx.set_options(self._OP_NO_TICKET)
    790797
    791798        return ctx
     799
     800OpenSSLCertificateOptions.__getstate__ = deprecated(Version("Twisted", 13, 1, 0),
     801    "a real persistence system")(OpenSSLCertificateOptions.__getstate__)
     802OpenSSLCertificateOptions.__setstate__ = deprecated(Version("Twisted", 13, 1, 0),
     803    "a real persistence system")(OpenSSLCertificateOptions.__setstate__)