Make Resource class's function can be wraped by api_version
api_verson.wraps() function requires the object to have an api_version attribute[1]. This change add api_version attribute to Resource class, so that we can use api_version to wrap functions in Resource class. [1]: https://github.com/openstack/python-cinderclient/blob/master/cinderclient/api_versions.py#L346 Partial-Bug: #1619105 Change-Id: I0fce855768a4a5165ce08274214d4907b4d2fb66
This commit is contained in:
@@ -506,6 +506,10 @@ class Resource(RequestIdMixin):
|
||||
else:
|
||||
return self.__dict__[k]
|
||||
|
||||
@property
|
||||
def api_version(self):
|
||||
return self.manager.api_version
|
||||
|
||||
def get(self):
|
||||
# set_loaded() first ... so if we have to bail, we know we tried.
|
||||
self.set_loaded(True)
|
||||
|
||||
@@ -13,11 +13,14 @@
|
||||
|
||||
from requests import Response
|
||||
|
||||
from cinderclient import api_versions
|
||||
from cinderclient import base
|
||||
from cinderclient.v3 import client
|
||||
from cinderclient import exceptions
|
||||
from cinderclient.openstack.common.apiclient import base as common_base
|
||||
from cinderclient.v1 import volumes
|
||||
from cinderclient.tests.unit import utils
|
||||
from cinderclient.tests.unit import test_utils
|
||||
from cinderclient.tests.unit.v1 import fakes
|
||||
|
||||
|
||||
@@ -87,6 +90,13 @@ class BaseTest(utils.TestCase):
|
||||
r = base.Resource(None, {"name": "1"}, resp=resp_obj)
|
||||
self.assertEqual([REQUEST_ID], r.request_ids)
|
||||
|
||||
def test_api_version(self):
|
||||
version = api_versions.APIVersion('3.1')
|
||||
api = client.Client(api_version=version)
|
||||
manager = test_utils.FakeManagerWithApi(api)
|
||||
r1 = base.Resource(manager, {'id': 1})
|
||||
self.assertEqual(version, r1.api_version)
|
||||
|
||||
|
||||
class ListWithMetaTest(utils.TestCase):
|
||||
def test_list_with_meta(self):
|
||||
|
||||
Reference in New Issue
Block a user