nsx v3 ut cleanup

a few minor clean-ups in the nsx v3 UTs.
most updates are as per comments in the review
of patch 229640. no functional or non test changes.

Change-Id: Ie3268d058bcb049816975038849e6c4905930a96
This commit is contained in:
Boden R 2015-10-08 13:53:38 -06:00 committed by Roey Chen
parent b14eb0a026
commit 7cb530727d
4 changed files with 13 additions and 20 deletions

View File

@ -14,7 +14,6 @@
# limitations under the License.
import requests
import urlparse
import uuid
from oslo_serialization import jsonutils
from oslo_utils import uuidutils
@ -98,13 +97,6 @@ class MockRequestSessionApi(object):
def __init__(self):
self._store = {}
def _is_uuid(self, item):
try:
uuid.UUID(item, version=4)
except ValueError:
return False
return True
def _format_uri(self, uri):
uri = urlparse.urlparse(uri).path
while uri.endswith('/'):
@ -116,7 +108,8 @@ class MockRequestSessionApi(object):
return uri
def _is_uuid_uri(self, uri):
return self._is_uuid(urlparse.urlparse(uri).path.split('/')[-1])
return uuidutils.is_uuid_like(
urlparse.urlparse(uri).path.split('/')[-1])
def _query(self, search_key, copy=True):
items = []
@ -163,7 +156,7 @@ class MockRequestSessionApi(object):
url, content=self._query(url), status=requests.codes.ok, **kwargs)
def _create(self, url, content, **kwargs):
resource_id = content.get('id', None)
resource_id = content.get('id')
if resource_id and self._store.get("%s%s" % (url, resource_id)):
return self._build_response(
url, content=None, status=requests.codes.bad, **kwargs)
@ -182,7 +175,7 @@ class MockRequestSessionApi(object):
url = self._format_uri(url)
if self._is_uuid_uri(url):
if self._store.get(url, None) is None:
if self._store.get(url) is None:
return self._build_response(
url, content=None, status=requests.codes.bad, **kwargs)
@ -193,10 +186,11 @@ class MockRequestSessionApi(object):
response_content = None
if parsed_url.query and parsed_url.query == 'action=create_multiple':
url_queries = urlparse.parse_qs(parsed_url.query)
if 'create_multiple' in url_queries.get('action', []):
response_content = {}
for resource_name, resource_body in body.items():
for new_resource in body[resource_name]:
for new_resource in resource_body:
created_resource = self._create(
url, new_resource, **kwargs)
if response_content.get(resource_name, None) is None:
@ -206,7 +200,8 @@ class MockRequestSessionApi(object):
response_content = self._create(url, body, **kwargs)
return self._build_response(
url, content=response_content, status=requests.codes.ok, **kwargs)
url, content=response_content,
status=requests.codes.created, **kwargs)
def put(self, url, **kwargs):
url = self._format_uri(url)

View File

@ -218,7 +218,6 @@ class L3NatTest(test_l3_plugin.L3BaseForIntTests, NsxV3PluginTestCaseMixin):
class TestL3NatTestCase(L3NatTest,
test_l3_plugin.L3NatDBIntTestCase,
NsxV3PluginTestCaseMixin,
test_ext_route.ExtraRouteDBTestCaseBase):
def setUp(self, plugin=PLUGIN_NAME,

View File

@ -94,10 +94,10 @@ class NsxClientTestCase(NsxLibTestCase):
@contextlib.contextmanager
def mocked_client(self, client, mock_validate=True):
session = client._session
with mock.patch.object(session, 'get')as _get:
with mock.patch.object(session, 'post')as _post:
with mock.patch.object(session, 'delete')as _delete:
with mock.patch.object(session, 'put')as _put:
with mock.patch.object(session, 'get') as _get:
with mock.patch.object(session, 'post') as _post:
with mock.patch.object(session, 'delete') as _delete:
with mock.patch.object(session, 'put') as _put:
rep = {
'get': _get,
'put': _put,

View File

@ -50,7 +50,6 @@ class TestNsxV3L2GatewayDriver(test_l2gw_db.L2GWTestCase,
self.core_plugin._nsx_client = self.client
self.core_plugin._port_client._client._session = self.mock_api
self.maxDiff = None
self.driver = nsx_v3_driver.NsxV3Driver()
self.l2gw_plugin = l2gw_plugin.NsxL2GatewayPlugin()
self.context = context.get_admin_context()