Blackify openstack.key_manager

Black used with the '-l 79 -S' flags.

A future change will ignore this commit in git-blame history by adding a
'git-blame-ignore-revs' file.

Change-Id: Ief5e4e9fa2675c7e74b77feb54776c692deaf33f
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2023-05-05 11:00:35 +01:00
parent 3d2511f980
commit 93d8f41713
9 changed files with 91 additions and 59 deletions

View File

@ -16,7 +16,6 @@ from openstack import format
class HREFToUUID(format.Formatter):
@classmethod
def deserialize(cls, value):
"""Convert a HREF to the UUID portion"""

View File

@ -49,8 +49,9 @@ class Proxy(proxy.Proxy):
:returns: ``None``
"""
self._delete(_container.Container, container,
ignore_missing=ignore_missing)
self._delete(
_container.Container, container, ignore_missing=ignore_missing
)
def find_container(self, name_or_id, ignore_missing=True):
"""Find a single container
@ -64,8 +65,9 @@ class Proxy(proxy.Proxy):
:returns: One :class:`~openstack.key_manager.v1.container.Container`
or None
"""
return self._find(_container.Container, name_or_id,
ignore_missing=ignore_missing)
return self._find(
_container.Container, name_or_id, ignore_missing=ignore_missing
)
def get_container(self, container):
"""Get a single container
@ -143,8 +145,9 @@ class Proxy(proxy.Proxy):
attempting to find a nonexistent resource.
:returns: One :class:`~openstack.key_manager.v1.order.Order` or None
"""
return self._find(_order.Order, name_or_id,
ignore_missing=ignore_missing)
return self._find(
_order.Order, name_or_id, ignore_missing=ignore_missing
)
def get_order(self, order):
"""Get a single order
@ -223,8 +226,9 @@ class Proxy(proxy.Proxy):
:returns: One :class:`~openstack.key_manager.v1.secret.Secret` or
None
"""
return self._find(_secret.Secret, name_or_id,
ignore_missing=ignore_missing)
return self._find(
_secret.Secret, name_or_id, ignore_missing=ignore_missing
)
def get_secret(self, secret):
"""Get a single secret

View File

@ -30,8 +30,8 @@ class Container(resource.Resource):
container_ref = resource.Body('container_ref')
#: The ID for this container
container_id = resource.Body(
'container_ref', alternate_id=True,
type=_format.HREFToUUID)
'container_ref', alternate_id=True, type=_format.HREFToUUID
)
#: The timestamp when this container was created.
created_at = resource.Body('created')
#: The name of this container

View File

@ -36,7 +36,8 @@ class Order(resource.Resource):
order_ref = resource.Body('order_ref')
#: The ID of this order
order_id = resource.Body(
'order_ref', alternate_id=True, type=_format.HREFToUUID)
'order_ref', alternate_id=True, type=_format.HREFToUUID
)
#: Secret href associated with the order
secret_ref = resource.Body('secret_ref')
#: Secret ID associated with the order

View File

@ -27,11 +27,17 @@ class Secret(resource.Resource):
allow_list = True
_query_mapping = resource.QueryParameters(
"name", "mode", "bits",
"secret_type", "acl_only",
"created", "updated",
"expiration", "sort",
algorithm="alg")
"name",
"mode",
"bits",
"secret_type",
"acl_only",
"created",
"updated",
"expiration",
"sort",
algorithm="alg",
)
# Properties
#: Metadata provided by a user or system for informational purposes
@ -59,7 +65,8 @@ class Secret(resource.Resource):
# in all of OpenStack because of the departure from using actual IDs
# that even this service can't even use itself.
secret_id = resource.Body(
'secret_ref', alternate_id=True, type=_format.HREFToUUID)
'secret_ref', alternate_id=True, type=_format.HREFToUUID
)
#: Used to indicate the type of secret being stored.
secret_type = resource.Body('secret_type')
#: The status of this secret
@ -77,10 +84,17 @@ class Secret(resource.Resource):
#: (required if payload is encoded)
payload_content_encoding = resource.Body('payload_content_encoding')
def fetch(self, session, requires_id=True,
base_path=None, error_message=None, skip_cache=False):
request = self._prepare_request(requires_id=requires_id,
base_path=base_path)
def fetch(
self,
session,
requires_id=True,
base_path=None,
error_message=None,
skip_cache=False,
):
request = self._prepare_request(
requires_id=requires_id, base_path=base_path
)
response = session.get(request.url).json()
@ -96,7 +110,8 @@ class Secret(resource.Resource):
payload = session.get(
utils.urljoin(request.url, "payload"),
headers={"Accept": content_type},
skip_cache=skip_cache)
skip_cache=skip_cache,
)
response["payload"] = payload.text
# We already have the JSON here so don't call into _translate_response

View File

@ -24,12 +24,11 @@ EXAMPLE = {
'status': '5',
'type': '6',
'updated': '2015-03-09T12:15:57.233772',
'consumers': ['7']
'consumers': ['7'],
}
class TestContainer(base.TestCase):
def test_basic(self):
sot = container.Container()
self.assertIsNone(sot.resource_key)

View File

@ -27,12 +27,11 @@ EXAMPLE = {
'sub_status': '7',
'sub_status_message': '8',
'type': '9',
'updated': '10'
'updated': '10',
}
class TestOrder(base.TestCase):
def test_basic(self):
sot = order.Order()
self.assertIsNone(sot.resource_key)

View File

@ -28,12 +28,14 @@ class TestKeyManagerContainer(TestKeyManagerProxy):
self.verify_create(self.proxy.create_container, container.Container)
def test_container_delete(self):
self.verify_delete(self.proxy.delete_container,
container.Container, False)
self.verify_delete(
self.proxy.delete_container, container.Container, False
)
def test_container_delete_ignore(self):
self.verify_delete(self.proxy.delete_container,
container.Container, True)
self.verify_delete(
self.proxy.delete_container, container.Container, True
)
def test_container_find(self):
self.verify_find(self.proxy.find_container, container.Container)
@ -87,8 +89,8 @@ class TestKeyManagerSecret(TestKeyManagerProxy):
def test_secret_get(self):
self.verify_get(self.proxy.get_secret, secret.Secret)
self.verify_get_overrided(
self.proxy, secret.Secret,
'openstack.key_manager.v1.secret.Secret')
self.proxy, secret.Secret, 'openstack.key_manager.v1.secret.Secret'
)
def test_secrets(self):
self.verify_list(self.proxy.secrets, secret.Secret)

View File

@ -31,12 +31,11 @@ EXAMPLE = {
'secret_type': '9',
'payload': '10',
'payload_content_type': '11',
'payload_content_encoding': '12'
'payload_content_encoding': '12',
}
class TestSecret(base.TestCase):
def test_basic(self):
sot = secret.Secret()
self.assertIsNone(sot.resource_key)
@ -48,19 +47,23 @@ class TestSecret(base.TestCase):
self.assertTrue(sot.allow_delete)
self.assertTrue(sot.allow_list)
self.assertDictEqual({"name": "name",
"mode": "mode",
"bits": "bits",
"secret_type": "secret_type",
"acl_only": "acl_only",
"created": "created",
"updated": "updated",
"expiration": "expiration",
"sort": "sort",
"algorithm": "alg",
"limit": "limit",
"marker": "marker"},
sot._query_mapping._mapping)
self.assertDictEqual(
{
"name": "name",
"mode": "mode",
"bits": "bits",
"secret_type": "secret_type",
"acl_only": "acl_only",
"created": "created",
"updated": "updated",
"expiration": "expiration",
"sort": "sort",
"algorithm": "alg",
"limit": "limit",
"marker": "marker",
},
sot._query_mapping._mapping,
)
def test_make_it(self):
sot = secret.Secret(**EXAMPLE)
@ -77,10 +80,12 @@ class TestSecret(base.TestCase):
self.assertEqual(EXAMPLE['updated'], sot.updated_at)
self.assertEqual(EXAMPLE['secret_type'], sot.secret_type)
self.assertEqual(EXAMPLE['payload'], sot.payload)
self.assertEqual(EXAMPLE['payload_content_type'],
sot.payload_content_type)
self.assertEqual(EXAMPLE['payload_content_encoding'],
sot.payload_content_encoding)
self.assertEqual(
EXAMPLE['payload_content_type'], sot.payload_content_type
)
self.assertEqual(
EXAMPLE['payload_content_encoding'], sot.payload_content_encoding
)
def test_get_no_payload(self):
sot = secret.Secret(id="id")
@ -112,11 +117,17 @@ class TestSecret(base.TestCase):
rv = sot.fetch(sess)
sess.get.assert_has_calls(
[mock.call("secrets/id",),
mock.call(
"secrets/id/payload",
headers={"Accept": content_type},
skip_cache=False)])
[
mock.call(
"secrets/id",
),
mock.call(
"secrets/id/payload",
headers={"Accept": content_type},
skip_cache=False,
),
]
)
self.assertEqual(rv.payload, payload)
self.assertEqual(rv.status, metadata["status"])
@ -129,7 +140,9 @@ class TestSecret(base.TestCase):
def test_get_with_payload_from_content_types(self):
content_type = "some/type"
metadata = {"status": "fine",
"content_types": {"default": content_type}}
metadata = {
"status": "fine",
"content_types": {"default": content_type},
}
sot = secret.Secret(id="id")
self._test_payload(sot, metadata, content_type)