Debian Codegraph @

tests/unit/transport/test_request.py

raw
1 # Copyright (c) 2013 Rackspace, Inc.
2 # Copyright (c) 2013 Red Hat, Inc.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 # implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 import json
18
19 from zaqarclient.queues.v2 import api as api_v2
20 from zaqarclient.tests import base
21 from zaqarclient.transport import request
22
23
24 class TestRequest(base.TestBase):
25
26 def test_request_project_id(self):
27 auth_opts = {
28 'options': {
29 'os_project_id': 'my-project'
30 }
31 }
32 auth_opts.update({'backend': 'noauth'})
33 req = request.prepare_request(auth_opts)
34 self.assertEqual('my-project', req.headers['X-Project-Id'])
35
36 def test_prepare_request(self):
37 auth_opts = self.conf.get('auth_opts', {})
38 req = request.prepare_request(auth_opts)
39 self.assertIsInstance(req, request.Request)
40 self.assertIsNone(req.content)
41
42 def test_prepare_request_with_data(self):
43 auth_opts = self.conf.get('auth_opts', {})
44 data = {"data": "tons of GBs"}
45 req = request.prepare_request(auth_opts, data=data)
46 self.assertIsInstance(req, request.Request)
47 self.assertEqual(json.dumps(data), req.content)
48
49 def test_request_with_right_version(self):
50 auth_opts = self.conf.get('auth_opts', {})
51 api_version = 2
52 req = request.prepare_request(auth_opts, api=api_version)
53 self.assertIsInstance(req.api, api_v2.V2)
54
55 api_version = 2.0
56 req = request.prepare_request(auth_opts, api=api_version)
57 self.assertIsInstance(req.api, api_v2.V2)