Always pass a project_id
Since v1.1, the `X_PROJECT-ID` became a required header. This patch adds a way to specify the project id regardless of the backend. In order to pass the project id, it's necessary to pass the `os_project_id` option in the `auth_opts` dictionary. For example: auth_opts = {'options': {'os_project_id': 'yadayada'}} Partially-Implements blueprint: api-v1.1 Change-Id: If72b758e634dc1e6bc1e1cc0c63361e8a43861bb
This commit is contained in:
parent
b9e9375d73
commit
434d487773
@ -25,13 +25,25 @@ HREF = '/v1/queue/'
|
|||||||
|
|
||||||
class TestRequest(base.TestBase):
|
class TestRequest(base.TestBase):
|
||||||
|
|
||||||
|
def test_request_project_id(self):
|
||||||
|
auth_opts = {
|
||||||
|
'options': {
|
||||||
|
'os_project_id': 'my-project'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
req = request.prepare_request(auth_opts)
|
||||||
|
self.assertEqual(req.headers['X-Project-Id'],
|
||||||
|
'my-project')
|
||||||
|
|
||||||
def test_prepare_request(self):
|
def test_prepare_request(self):
|
||||||
req = request.prepare_request(self.conf)
|
auth_opts = self.conf.get('auth_opts', {})
|
||||||
|
req = request.prepare_request(auth_opts)
|
||||||
self.assertTrue(isinstance(req, request.Request))
|
self.assertTrue(isinstance(req, request.Request))
|
||||||
self.assertIsNone(req.content)
|
self.assertIsNone(req.content)
|
||||||
|
|
||||||
def test_prepare_request_with_data(self):
|
def test_prepare_request_with_data(self):
|
||||||
|
auth_opts = self.conf.get('auth_opts', {})
|
||||||
data = {"data": "tons of GBs"}
|
data = {"data": "tons of GBs"}
|
||||||
req = request.prepare_request(self.conf, data=data)
|
req = request.prepare_request(auth_opts, data=data)
|
||||||
self.assertTrue(isinstance(req, request.Request))
|
self.assertTrue(isinstance(req, request.Request))
|
||||||
self.assertEqual(req.content, json.dumps(data))
|
self.assertEqual(req.content, json.dumps(data))
|
||||||
|
@ -29,7 +29,13 @@ class TestBase(testtools.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestBase, self).setUp()
|
super(TestBase, self).setUp()
|
||||||
|
|
||||||
self.conf = {}
|
self.conf = {
|
||||||
|
'auth_opts': {
|
||||||
|
'options': {
|
||||||
|
'os_project_id': 'my-project'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
self.useFixture(fixtures.FakeLogger('zaqar'))
|
self.useFixture(fixtures.FakeLogger('zaqar'))
|
||||||
|
|
||||||
# NOTE(kgriffs): Don't monkey-patch stdout since it breaks
|
# NOTE(kgriffs): Don't monkey-patch stdout since it breaks
|
||||||
|
@ -47,6 +47,9 @@ def prepare_request(auth_opts=None, data=None, **kwargs):
|
|||||||
# to get the api_version.
|
# to get the api_version.
|
||||||
req = auth_backend.authenticate(1, req)
|
req = auth_backend.authenticate(1, req)
|
||||||
|
|
||||||
|
req.headers['X-Project-Id'] = auth_opts.get('options',
|
||||||
|
{}).get('os_project_id')
|
||||||
|
|
||||||
if data is not None:
|
if data is not None:
|
||||||
req.content = json.dumps(data)
|
req.content = json.dumps(data)
|
||||||
return req
|
return req
|
||||||
|
Loading…
x
Reference in New Issue
Block a user