Commit 3e00d916 authored by Zuul's avatar Zuul Committed by Gerrit Code Review

Merge "Add return-request-id-to-caller function(v3)"

parents 06e36dde d3ea00e6
......@@ -10,12 +10,17 @@
# License for the specific language governing permissions and limitations
# under the License.
import fixtures
import requests
import uuid
from keystoneauth1 import exceptions as ksa_exceptions
from keystoneauth1.identity import v3
from keystoneauth1 import session
from keystoneclient import exceptions as ksc_exceptions
from keystoneclient.tests.unit.v3 import utils
from keystoneclient.v3 import client
from keystoneclient.v3 import projects
......@@ -395,3 +400,71 @@ class ProjectTests(utils.ClientTestCase, utils.CrudTests):
"name": project_id}
]}
return ret
class ProjectsRequestIdTests(utils.TestCase):
url = "/projects"
resp = requests.Response()
TEST_REQUEST_ID = uuid.uuid4().hex
resp.headers['x-openstack-request-id'] = TEST_REQUEST_ID
def setUp(self):
super(ProjectsRequestIdTests, self).setUp()
auth = v3.Token(auth_url='http://127.0.0.1:5000',
token=self.TEST_TOKEN)
session_ = session.Session(auth=auth)
self.client = client.Client(session=session_,
include_metadata='True')._adapter
self.mgr = projects.ProjectManager(self.client)
self.mgr.resource_class = projects.Project
def _mock_request_method(self, method=None, body=None):
return self.useFixture(fixtures.MockPatchObject(
self.client, method, autospec=True,
return_value=(self.resp, body))
).mock
def test_get_project(self):
body = {"project": {"name": "admin"}}
get_mock = self._mock_request_method(method='get', body=body)
response = self.mgr.get(project='admin')
self.assertEqual(response.request_ids[0], self.TEST_REQUEST_ID)
get_mock.assert_called_once_with(self.url + '/admin')
def test_create_project(self):
body = {"project": {"name": "admin", "domain": "admin"}}
post_mock = self._mock_request_method(method='post', body=body)
response = self.mgr.create('admin', 'admin')
self.assertEqual(response.request_ids[0], self.TEST_REQUEST_ID)
post_mock.assert_called_once_with(self.url, body={'project': {
'name': 'admin', 'enabled': True, 'domain_id': 'admin'}})
def test_list_project(self):
body = {"projects": [{"name": "admin"}, {"name": "admin"}]}
get_mock = self._mock_request_method(method='get', body=body)
returned_list = self.mgr.list()
self.assertEqual(returned_list.request_ids[0], self.TEST_REQUEST_ID)
get_mock.assert_called_once_with(self.url + '?')
def test_update_project(self):
body = {"project": {"name": "admin"}}
patch_mock = self._mock_request_method(method='patch', body=body)
put_mock = self._mock_request_method(method='put', body=body)
response = self.mgr.update("admin", domain='demo')
self.assertEqual(response.request_ids[0], self.TEST_REQUEST_ID)
patch_mock.assert_called_once_with(self.url + '/admin', body={
'project': {'domain_id': 'demo'}})
self.assertFalse(put_mock.called)
def test_delete_project(self):
get_mock = self._mock_request_method(method='delete')
_, resp = self.mgr.delete("admin")
self.assertEqual(resp.request_ids[0], self.TEST_REQUEST_ID)
get_mock.assert_called_once_with(self.url + '/admin')
......@@ -136,9 +136,21 @@ class ProjectManager(base.CrudManager):
domain_id=base.getid(domain),
fallback_to_auth=True,
**kwargs)
for p in projects:
base_response = None
list_data = projects
if self.client.include_metadata:
base_response = projects
list_data = projects.data
base_response.data = list_data
for p in list_data:
p.tags = self._encode_tags(getattr(p, 'tags', []))
return projects
if self.client.include_metadata:
base_response.data = list_data
return base_response if self.client.include_metadata else list_data
def _check_not_parents_as_ids_and_parents_as_list(self, parents_as_ids,
parents_as_list):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment