Merge "Ensure the float value of api version could work"
This commit is contained in:
commit
641e12e202
@ -16,6 +16,8 @@
|
||||
|
||||
import json
|
||||
|
||||
from zaqarclient.queues.v1 import api as api_v1
|
||||
from zaqarclient.queues.v2 import api as api_v2
|
||||
from zaqarclient.tests import base
|
||||
from zaqarclient.transport import request
|
||||
|
||||
@ -44,3 +46,25 @@ class TestRequest(base.TestBase):
|
||||
req = request.prepare_request(auth_opts, data=data)
|
||||
self.assertTrue(isinstance(req, request.Request))
|
||||
self.assertEqual(json.dumps(data), req.content)
|
||||
|
||||
def test_request_with_right_version(self):
|
||||
auth_opts = self.conf.get('auth_opts', {})
|
||||
api_version = 1
|
||||
req = request.prepare_request(auth_opts, api=api_version)
|
||||
self.assertTrue(isinstance(req.api, api_v1.V1))
|
||||
|
||||
api_version = 1.0
|
||||
req = request.prepare_request(auth_opts, api=api_version)
|
||||
self.assertTrue(isinstance(req.api, api_v1.V1))
|
||||
|
||||
api_version = 1.1
|
||||
req = request.prepare_request(auth_opts, api=api_version)
|
||||
self.assertTrue(isinstance(req.api, api_v1.V1_1))
|
||||
|
||||
api_version = 2
|
||||
req = request.prepare_request(auth_opts, api=api_version)
|
||||
self.assertTrue(isinstance(req.api, api_v2.V2))
|
||||
|
||||
api_version = 2.0
|
||||
req = request.prepare_request(auth_opts, api=api_version)
|
||||
self.assertTrue(isinstance(req.api, api_v2.V2))
|
||||
|
@ -71,10 +71,9 @@ class Client(object):
|
||||
return (trans or self.transport)
|
||||
|
||||
def _request_and_transport(self):
|
||||
api = 'queues.v' + str(self.api_version)
|
||||
req = request.prepare_request(self.auth_opts,
|
||||
endpoint=self.api_url,
|
||||
api=api)
|
||||
api=self.api_version)
|
||||
|
||||
req.headers['Client-ID'] = self.client_uuid
|
||||
|
||||
|
@ -93,7 +93,12 @@ class Request(object):
|
||||
headers=None, api=None):
|
||||
|
||||
self._api = None
|
||||
self._api_mod = api
|
||||
# ensure that some values like "v1.0" could work as "v1"
|
||||
self._api_mod = None
|
||||
if api and int(api) == api:
|
||||
self._api_mod = 'queues.v' + str(int(api))
|
||||
elif api:
|
||||
self._api_mod = 'queues.v' + str(api)
|
||||
|
||||
self.endpoint = endpoint
|
||||
self.operation = operation
|
||||
|
Loading…
Reference in New Issue
Block a user