Make tests in barbican.tests.tasks py3 compatible

1. change map to six.moves.map
2. change "/" operator to "//" operator
3. encode some strings to utf-8 wherever required
4. change e.message to six.text_type(e)

Partially-Implements: blueprint barbican-py3

Change-Id: Id619ff95d5fdf343ea6853da21b57f012cb25742
This commit is contained in:
Pradeep Kumar Singh 2015-08-13 10:11:29 +09:00
parent 4f511d2641
commit f2c95c38c1
6 changed files with 14 additions and 10 deletions

View File

@ -59,7 +59,7 @@ class SimpleCryptoPlugin(c.CryptoPluginBase):
def encrypt(self, encrypt_dto, kek_meta_dto, project_id):
kek = self._get_kek(kek_meta_dto)
unencrypted = encrypt_dto.unencrypted
if not isinstance(unencrypted, str):
if not isinstance(unencrypted, six.binary_type):
raise ValueError(
u._(
'Unencrypted data must be a byte type, but was '
@ -91,7 +91,7 @@ class SimpleCryptoPlugin(c.CryptoPluginBase):
return kek_meta_dto
def generate_symmetric(self, generate_dto, kek_meta_dto, project_id):
byte_length = int(generate_dto.bit_length) / 8
byte_length = int(generate_dto.bit_length) // 8
unencrypted = os.urandom(byte_length)
return self.encrypt(c.EncryptDTO(unencrypted),

View File

@ -17,6 +17,8 @@
Barbican defined mime-types
"""
import six
from barbican.common import utils
@ -68,7 +70,7 @@ CTYPES_TO_ENCODINGS = {'text/plain': None,
def normalize_content_type(mime_type):
"""Normalize the supplied content-type to an internal form."""
stripped = map(lambda x: x.strip(), mime_type.split(';'))
stripped = list(six.moves.map(lambda x: x.strip(), mime_type.split(';')))
mime = stripped[0].lower()
if len(stripped) > 1:
# mime type includes charset
@ -77,7 +79,8 @@ def normalize_content_type(mime_type):
# charset is malformed
return mime_type
else:
charset = map(lambda x: x.strip(), charset_type.split('='))[1]
charset = list(six.moves.map(lambda x: x.strip(),
charset_type.split('=')))[1]
if charset not in PLAIN_TEXT_CHARSETS:
# unsupported charset
return mime_type

View File

@ -328,7 +328,7 @@ def _generate_csr_from_private_key(order_model, project_model):
pkey = crypto.load_privatekey(
crypto.FILETYPE_PEM,
private_key,
passphrase
passphrase.encode('utf-8')
)
subject_name = order_model.meta.get('subject_dn')

View File

@ -510,11 +510,11 @@ class WhenIssuingCertificateRequests(BaseCertificateRequestsTestCase):
key_pem = crypto.dump_privatekey(
crypto.FILETYPE_PEM,
pkey,
passphrase=passphrase
passphrase=passphrase.encode('utf-8')
)
self.private_key_value = base64.b64encode(key_pem)
self.public_key_value = "public_key"
self.passphrase_value = base64.b64encode(passphrase)
self.passphrase_value = base64.b64encode(passphrase.encode('utf-8'))
self.store_plugin.get_secret.side_effect = self.stored_key_side_effect
self._test_should_return_waiting_for_ca(
cert_res.issue_certificate_request)
@ -540,7 +540,7 @@ class WhenIssuingCertificateRequests(BaseCertificateRequestsTestCase):
self.private_key_value = base64.b64encode(private_key_pem)
public_key_pem = public_key.exportKey()
self.public_key_value = base64.b64encode(public_key_pem)
self.passphrase_value = base64.b64encode(passphrase)
self.passphrase_value = base64.b64encode(passphrase.encode('utf-8'))
self.store_plugin.get_secret.side_effect = self.stored_key_side_effect
self._test_should_return_waiting_for_ca(

View File

@ -230,7 +230,8 @@ class WhenUsingKeystoneEventConsumerProcessMethod(
# Get secret_store_metadata for related secret
self.assertTrue(len(db_secrets[0].secret_store_metadata) > 0)
secret_metadata_id = db_secrets[0].secret_store_metadata.values()[0].id
secret_metadata_id = list(db_secrets[0].
secret_store_metadata.values())[0].id
self.assertIsNotNone(secret_metadata_id)
# Get db entry for secret_store_metadata by id to make sure its

View File

@ -348,7 +348,7 @@ class WhenUpdatingOrder(BaseOrderTestCase):
self.meta
)
self.assertEqual('Abort!', exception.message)
self.assertEqual('Abort!', six.text_type(exception))
mock_mod_cert.assert_called_once_with(self.order, self.meta)