python 3 support
Change-Id: If4bc02d103ed0daa54ba411199cdb0bac6ba3712
This commit is contained in:
@@ -233,7 +233,7 @@ class Barbican:
|
||||
args.bit_length,
|
||||
args.mode,
|
||||
args.expiration)
|
||||
print secret
|
||||
print(secret)
|
||||
else:
|
||||
self.parser.exit(status=1, message='ERROR: store is only supported'
|
||||
' for secrets\n')
|
||||
@@ -246,7 +246,7 @@ class Barbican:
|
||||
args.bit_length,
|
||||
args.mode,
|
||||
args.expiration)
|
||||
print order
|
||||
print(order)
|
||||
else:
|
||||
self.parser.exit(status=1, message='ERROR: create is only '
|
||||
'supported for orders\n')
|
||||
@@ -266,14 +266,14 @@ class Barbican:
|
||||
def get(self, args):
|
||||
if args.command == 'secret':
|
||||
if args.decrypt:
|
||||
print self.client.secrets.decrypt(args.URI,
|
||||
args.payload_content_type)
|
||||
print(self.client.secrets.decrypt(args.URI,
|
||||
args.payload_content_type))
|
||||
else:
|
||||
print self.client.secrets.get(args.URI)
|
||||
print(self.client.secrets.get(args.URI))
|
||||
elif args.command == 'verification':
|
||||
print self.client.verifications.get(args.URI)
|
||||
print(self.client.verifications.get(args.URI))
|
||||
elif args.command == 'order':
|
||||
print self.client.orders.get(args.URI)
|
||||
print(self.client.orders.get(args.URI))
|
||||
else:
|
||||
self.parser.exit(status=1, message='ERROR: get is only '
|
||||
'supported for secrets, '
|
||||
@@ -296,9 +296,9 @@ class Barbican:
|
||||
'supported for secrets, '
|
||||
'orders or verifications\n')
|
||||
for obj in ls:
|
||||
print obj
|
||||
print '{0}s displayed: {1} - offset: {2}'.format(args.command, len(ls),
|
||||
args.offset)
|
||||
print(obj)
|
||||
print('{0}s displayed: {1} - offset: {2}'.format(args.command, len(ls),
|
||||
args.offset))
|
||||
|
||||
def verify(self, args):
|
||||
if args.command == 'verification':
|
||||
@@ -307,7 +307,7 @@ class Barbican:
|
||||
resource_ref=args.ref,
|
||||
resource_action=args.action,
|
||||
impersonation_allowed=args.impersonation)
|
||||
print verify
|
||||
print(verify)
|
||||
else:
|
||||
self.parser.exit(status=1, message='ERROR: verify is only '
|
||||
'supported for verifications\n')
|
||||
|
||||
@@ -23,7 +23,8 @@ class BaseEntityManager(object):
|
||||
self.entity = entity
|
||||
|
||||
def _remove_empty_keys(self, dictionary):
|
||||
for k in dictionary.keys():
|
||||
copied_dict = dictionary.copy()
|
||||
for k in copied_dict.keys():
|
||||
if dictionary[k] is None:
|
||||
dictionary.pop(k)
|
||||
|
||||
|
||||
@@ -126,7 +126,6 @@ class RackspaceAuthV2(AuthPluginBase):
|
||||
payload = self._authenticate_with_password()
|
||||
|
||||
r = requests.post(auth_url, data=json.dumps(payload), headers=headers)
|
||||
|
||||
try:
|
||||
r.raise_for_status()
|
||||
except requests.HTTPError:
|
||||
|
||||
@@ -13,9 +13,10 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
import logging
|
||||
import urlparse
|
||||
import re
|
||||
|
||||
import six
|
||||
|
||||
from barbicanclient import base
|
||||
from barbicanclient.openstack.common.timeutils import parse_isotime
|
||||
|
||||
@@ -129,7 +130,7 @@ class SecretManager(base.BaseEntityManager):
|
||||
if not secret_ref:
|
||||
raise ValueError('secret_ref is required.')
|
||||
try:
|
||||
url = urlparse.urlparse(secret_ref)
|
||||
url = six.moves.urllib.parse.urlparse(secret_ref)
|
||||
parts = url.path.rstrip('/').split('/')
|
||||
reuuid = re.compile(r'[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-'
|
||||
'[0-9a-f]{4}-[0-9a-f]{12}', re.I)
|
||||
|
||||
@@ -79,7 +79,7 @@ class WhenTestingRackspaceAuthentication(testtools.TestCase):
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}).encode("ascii")
|
||||
|
||||
patcher = mock.patch('barbicanclient.common.auth.requests.post')
|
||||
self._mock_post = patcher.start()
|
||||
@@ -99,6 +99,7 @@ class WhenTestingRackspaceAuthentication(testtools.TestCase):
|
||||
api_key=self._api_key)
|
||||
|
||||
def test_tokens_is_appended_to_auth_url(self):
|
||||
self._response.status_code = 200
|
||||
identity = auth.RackspaceAuthV2(self._auth_url,
|
||||
self._username,
|
||||
api_key=self._api_key)
|
||||
@@ -108,6 +109,7 @@ class WhenTestingRackspaceAuthentication(testtools.TestCase):
|
||||
headers=mock.ANY)
|
||||
|
||||
def test_authenticate_with_api_key(self):
|
||||
self._response.status_code = 200
|
||||
with mock.patch(
|
||||
'barbicanclient.common.auth.RackspaceAuthV2.'
|
||||
'_authenticate_with_api_key'
|
||||
@@ -119,6 +121,7 @@ class WhenTestingRackspaceAuthentication(testtools.TestCase):
|
||||
mock_authenticate.assert_called_once_with()
|
||||
|
||||
def test_authenticate_with_password(self):
|
||||
self._response.status_code = 200
|
||||
with mock.patch(
|
||||
'barbicanclient.common.auth.RackspaceAuthV2.'
|
||||
'_authenticate_with_password'
|
||||
@@ -137,19 +140,22 @@ class WhenTestingRackspaceAuthentication(testtools.TestCase):
|
||||
api_key=self._api_key)
|
||||
|
||||
def test_error_raised_for_bad_response_from_server(self):
|
||||
self._response._content = 'Not JSON'
|
||||
self._response._content = b'Not JSON'
|
||||
self._response.status_code = 200
|
||||
with testtools.ExpectedException(auth.AuthException):
|
||||
auth.RackspaceAuthV2(self._auth_url,
|
||||
self._username,
|
||||
api_key=self._api_key)
|
||||
|
||||
def test_auth_token_is_set(self):
|
||||
self._response.status_code = 200
|
||||
identity = auth.RackspaceAuthV2(self._auth_url,
|
||||
self._username,
|
||||
api_key=self._api_key)
|
||||
self.assertEqual(identity.auth_token, self._auth_token)
|
||||
|
||||
def test_tenant_id_is_set(self):
|
||||
self._response.status_code = 200
|
||||
identity = auth.RackspaceAuthV2(self._auth_url,
|
||||
self._username,
|
||||
api_key=self._api_key)
|
||||
|
||||
@@ -13,9 +13,10 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import cStringIO
|
||||
import os
|
||||
import sys
|
||||
|
||||
import six
|
||||
import testtools
|
||||
|
||||
import barbicanclient.barbican
|
||||
@@ -28,7 +29,7 @@ class TestBarbican(testtools.TestCase):
|
||||
clean_env = {}
|
||||
_old_env, os.environ = os.environ, clean_env.copy()
|
||||
try:
|
||||
sys.stdout = cStringIO.StringIO()
|
||||
sys.stdout = six.StringIO()
|
||||
_barbican = barbicanclient.barbican.Barbican()
|
||||
_barbican.execute(argv=argstr.split())
|
||||
except SystemExit:
|
||||
|
||||
@@ -64,7 +64,7 @@ class WhenTestingClientInit(testtools.TestCase):
|
||||
|
||||
def _mock_response(self, content=None, status_code=200):
|
||||
resp = requests.Response()
|
||||
resp._content = content or '{"title": {"generic mocked response"}}'
|
||||
resp._content = content or b'{"title": "generic mocked response"}'
|
||||
resp.status_code = status_code
|
||||
return resp
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ class WhenTestingOrders(test_client.BaseEntityResource):
|
||||
def test_should_get_list(self):
|
||||
order_resp = self.order.get_dict(self.entity_href)
|
||||
self.api.get.return_value = {"orders":
|
||||
[order_resp for v in xrange(3)]}
|
||||
[order_resp for v in range(3)]}
|
||||
|
||||
orders_list = self.manager.list(limit=10, offset=5)
|
||||
self.assertTrue(len(orders_list) == 3)
|
||||
|
||||
@@ -145,7 +145,7 @@ class WhenTestingSecrets(test_client.BaseEntityResource):
|
||||
def test_should_get_list(self):
|
||||
secret_resp = self.secret.get_dict(self.entity_href)
|
||||
self.api.get.return_value = {"secrets":
|
||||
[secret_resp for v in xrange(3)]}
|
||||
[secret_resp for v in range(3)]}
|
||||
|
||||
secrets_list = self.manager.list(limit=10, offset=5)
|
||||
self.assertTrue(len(secrets_list) == 3)
|
||||
|
||||
@@ -109,7 +109,7 @@ class WhenTestingVerifications(test_client.BaseEntityResource):
|
||||
def test_should_get_list(self):
|
||||
verify_resp = self.verify.get_dict(self.entity_href)
|
||||
self.api.get.return_value = {"verifications":
|
||||
[verify_resp for v in xrange(3)]}
|
||||
[verify_resp for v in range(3)]}
|
||||
|
||||
verifies = self.manager.list(limit=10, offset=5)
|
||||
self.assertTrue(len(verifies) == 3)
|
||||
|
||||
@@ -2,4 +2,5 @@ pbr>=0.5.21,<1.0
|
||||
|
||||
argparse
|
||||
requests>=1.2.3
|
||||
six>=1.5.2
|
||||
python-keystoneclient>=0.3.2
|
||||
|
||||
Reference in New Issue
Block a user