Merge "Update managed object __eq__ and __ne__"

This commit is contained in:
Jenkins 2015-11-30 14:22:40 +00:00 committed by Gerrit Code Review
commit 0c877d424e
8 changed files with 124 additions and 22 deletions

View File

@ -58,6 +58,7 @@ class PrivateKey(key.Key):
def __eq__(self, other):
if isinstance(other, PrivateKey):
return (self._alg == other._alg and
self._bit_length == other._bit_length and
self._key == other._key and
self._name == other._name)
else:

View File

@ -59,6 +59,7 @@ class PublicKey(key.Key):
def __eq__(self, other):
if isinstance(other, PublicKey):
return (self._alg == other._alg and
self._bit_length == other._bit_length and
self._key == other._key and
self._name == other._name)
else:

View File

@ -44,17 +44,23 @@ class OpaqueDataTestCase(base.TestCase):
def test___eq__(self):
self.assertTrue(self.opaque_data == self.opaque_data)
self.assertTrue(self.opaque_data is self.opaque_data)
self.assertFalse(self.opaque_data is None)
self.assertFalse(None == self.opaque_data)
def test___ne__(self):
self.assertFalse(self.opaque_data != self.opaque_data)
self.assertFalse(self.name != self.name)
other_opaque_data = opaque_data.OpaqueData(self.data, self.name)
self.assertTrue(self.opaque_data == other_opaque_data)
self.assertFalse(self.opaque_data is other_opaque_data)
def test___ne___none(self):
self.assertTrue(self.opaque_data is not None)
self.assertTrue(None != self.opaque_data)
def test___ne__name(self):
def test___ne___data(self):
other_opaque = opaque_data.OpaqueData(b'other data', self.name)
self.assertTrue(self.opaque_data != other_opaque)
def test___ne___name(self):
other_opaque = opaque_data.OpaqueData(self.data, "other opaque")
self.assertTrue(self.opaque_data != other_opaque)

View File

@ -45,18 +45,25 @@ class PassphraseTestCase(base.TestCase):
def test___eq__(self):
self.assertTrue(self.passphrase == self.passphrase)
self.assertTrue(self.passphrase is self.passphrase)
self.assertFalse(self.passphrase is None)
self.assertFalse(None == self.passphrase)
def test___ne__(self):
self.assertFalse(self.passphrase != self.passphrase)
self.assertFalse(self.name != self.name)
other_passphrase = passphrase.Passphrase(self.passphrase_data,
self.name)
self.assertTrue(self.passphrase == other_passphrase)
self.assertFalse(self.passphrase is other_passphrase)
def test___ne___none(self):
self.assertTrue(self.passphrase is not None)
self.assertTrue(None != self.passphrase)
def test___ne___data(self):
other_phrase = passphrase.Passphrase(b"other passphrase", self.name)
self.assertTrue(self.passphrase != other_phrase)
def test___ne__name(self):
other_phrase = passphrase.Passphrase(self.passphrase_data,
"other phrase")
self.assertTrue(self.passphrase_data != other_phrase)
self.assertTrue(self.passphrase != other_phrase)

View File

@ -55,18 +55,45 @@ class PrivateKeyTestCase(base.KeyTestCase):
def test___eq__(self):
self.assertTrue(self.key == self.key)
self.assertTrue(self.key is self.key)
self.assertFalse(self.key is None)
self.assertFalse(None == self.key)
def test___ne__(self):
self.assertFalse(self.key != self.key)
self.assertFalse(self.name != self.name)
other_key = private_key.PrivateKey(self.algorithm,
self.length,
self.encoded,
self.name)
self.assertTrue(self.key == other_key)
self.assertFalse(self.key is other_key)
def test___ne___none(self):
self.assertTrue(self.key is not None)
self.assertTrue(None != self.key)
def test___ne__name(self):
def test___ne___algorithm(self):
other_key = private_key.PrivateKey('DSA',
self.length,
self.encoded,
self.name)
self.assertTrue(self.key != other_key)
def test___ne___length(self):
other_key = private_key.PrivateKey(self.algorithm,
4096,
self.encoded,
self.name)
self.assertTrue(self.key != other_key)
def test___ne___encoded(self):
different_encoded = bytes(utils.get_private_key_der()) + b'\x00'
other_key = private_key.PrivateKey(self.algorithm,
self.length,
different_encoded,
self.name)
self.assertTrue(self.key != other_key)
def test___ne___name(self):
other_key = private_key.PrivateKey(self.algorithm,
self.length,
self.encoded,

View File

@ -55,17 +55,44 @@ class PublicKeyTestCase(base.KeyTestCase):
def test___eq__(self):
self.assertTrue(self.key == self.key)
self.assertTrue(self.key is self.key)
self.assertFalse(self.key is None)
self.assertFalse(None == self.key)
def test___ne__(self):
self.assertFalse(self.key != self.key)
self.assertFalse(self.name != self.name)
other_key = public_key.PublicKey(self.algorithm,
self.length,
self.encoded,
self.name)
self.assertTrue(self.key == other_key)
self.assertFalse(self.key is other_key)
def test___ne___none(self):
self.assertTrue(self.key is not None)
self.assertTrue(None != self.key)
def test___ne___algorithm(self):
other_key = public_key.PublicKey('DSA',
self.length,
self.encoded,
self.name)
self.assertTrue(self.key != other_key)
def test___ne___length(self):
other_key = public_key.PublicKey(self.algorithm,
4096,
self.encoded,
self.name)
self.assertTrue(self.key != other_key)
def test___ne___encoded(self):
different_encoded = bytes(utils.get_public_key_der()) + b'\x00'
other_key = public_key.PublicKey(self.algorithm,
self.length,
different_encoded,
self.name)
self.assertTrue(self.key != other_key)
def test___ne__name(self):
other_key = public_key.PublicKey(self.algorithm,
self.length,

View File

@ -54,18 +54,45 @@ class SymmetricKeyTestCase(base.KeyTestCase):
def test___eq__(self):
self.assertTrue(self.key == self.key)
self.assertTrue(self.key is self.key)
self.assertFalse(self.key is None)
self.assertFalse(None == self.key)
def test___ne__(self):
self.assertFalse(self.key != self.key)
self.assertFalse(self.name != self.name)
other_key = sym_key.SymmetricKey(self.algorithm,
self.bit_length,
self.encoded,
self.name)
self.assertTrue(self.key == other_key)
self.assertFalse(self.key is other_key)
def test___ne___none(self):
self.assertTrue(self.key is not None)
self.assertTrue(None != self.key)
def test___ne__name(self):
def test___ne___algorithm(self):
other_key = sym_key.SymmetricKey('DES',
self.bit_length,
self.encoded,
self.name)
self.assertTrue(self.key != other_key)
def test___ne___length(self):
other_key = sym_key.SymmetricKey(self.algorithm,
self.bit_length * 2,
self.encoded,
self.name)
self.assertTrue(self.key != other_key)
def test___ne___encoded(self):
different_encoded = self.encoded * 2
other_key = sym_key.SymmetricKey(self.algorithm,
self.bit_length,
different_encoded,
self.name)
self.assertTrue(self.key != other_key)
def test___ne___name(self):
other_key = sym_key.SymmetricKey(self.algorithm,
self.bit_length,
self.encoded,

View File

@ -44,17 +44,23 @@ class X509TestCase(base.CertificateTestCase):
def test___eq__(self):
self.assertTrue(self.cert == self.cert)
self.assertTrue(self.cert is self.cert)
self.assertFalse(self.cert is None)
self.assertFalse(None == self.cert)
def test___ne__(self):
self.assertFalse(self.cert != self.cert)
self.assertFalse(self.name != self.name)
other_x_509 = x_509.X509(self.data, self.name)
self.assertTrue(self.cert == other_x_509)
self.assertFalse(self.cert is other_x_509)
def test___ne___none(self):
self.assertTrue(self.cert is not None)
self.assertTrue(None != self.cert)
def test___ne___data(self):
other_x509 = x_509.X509(b'\x00\x00\x00', self.name)
self.assertTrue(self.cert != other_x509)
def test___ne__name(self):
other_x509 = x_509.X509(self.data, "other x509")
self.assertTrue(self.cert != other_x509)