Convert test_role_assignments to requests mock

Stop mocking keystoneclient objects directly.

Change-Id: Ibb441ba7a3de50201e96310b9aca5bea628fae01
This commit is contained in:
Morgan Fainberg 2017-03-21 16:58:29 -07:00
parent f3d3e45c64
commit 17ab75b0a3
3 changed files with 2750 additions and 689 deletions

View File

@ -1795,8 +1795,7 @@ class OperatorCloud(openstackcloud.OpenStackCloud):
data['tenant'] = data.pop('project')
self.manager.submit_task(_tasks.RoleRemoveUser(**data))
else:
if data.get('project') is None \
and data.get('domain') is None:
if data.get('project') is None and data.get('domain') is None:
raise OpenStackCloudException(
'Must specify either a domain or project')
self.manager.submit_task(_tasks.RoleRevokeUser(**data))

View File

@ -24,6 +24,7 @@ import os
import os_client_config as occ
from requests import structures
from requests_mock.contrib import fixture as rm_fixture
from six.moves import urllib
import tempfile
import shade.openstackcloud
@ -244,9 +245,10 @@ class RequestsMockTestCase(BaseTestCase):
return project_list
def _get_project_data(self, project_name=None, enabled=None,
domain_id=None, description=None, v3=True):
domain_id=None, description=None, v3=True,
project_id=None):
project_name = project_name or self.getUniqueString('projectName')
project_id = uuid.uuid4().hex
project_id = uuid.UUID(project_id or uuid.uuid4().hex).hex
response = {'id': project_id, 'name': project_name}
request = {'name': project_name}
domain_id = (domain_id or uuid.uuid4().hex) if v3 else None
@ -271,7 +273,7 @@ class RequestsMockTestCase(BaseTestCase):
def _get_group_data(self, name=None, domain_id=None, description=None):
group_id = uuid.uuid4().hex
name or self.getUniqueString('groupname')
name = name or self.getUniqueString('groupname')
domain_id = uuid.UUID(domain_id or uuid.uuid4().hex).hex
response = {'id': group_id, 'name': name, 'domain_id': domain_id}
request = {'name': name}
@ -570,9 +572,27 @@ class RequestsMockTestCase(BaseTestCase):
if stop_after and x > stop_after:
break
call_uri_parts = urllib.parse.urlparse(call['url'])
history_uri_parts = urllib.parse.urlparse(history.url)
self.assertEqual(
(call['method'], call['url']), (history.method, history.url),
'REST mismatch on call {index}'.format(index=x))
(call['method'], call_uri_parts.scheme, call_uri_parts.netloc,
call_uri_parts.path, call_uri_parts.params,
urllib.parse.parse_qs(call_uri_parts.query)),
(history.method, history_uri_parts.scheme,
history_uri_parts.netloc, history_uri_parts.path,
history_uri_parts.params,
urllib.parse.parse_qs(history_uri_parts.query)),
('REST mismatch on call %(index)d. Expected %(call)r. '
'Got %(history)r). '
'NOTE: query string order differences wont cause mismatch' %
{
'index': x,
'call': '{method} {url}'.format(method=call['method'],
url=call['url']),
'history': '{method} {url}'.format(
method=history.method,
url=history.url)})
)
if 'json' in call:
self.assertEqual(
call['json'], history.json(),

File diff suppressed because it is too large Load Diff