diff --git a/vmware_nsx/tests/unit/nsx_v3/mocks.py b/vmware_nsx/tests/unit/nsx_v3/mocks.py index 41bb9bb764..461c8a2829 100644 --- a/vmware_nsx/tests/unit/nsx_v3/mocks.py +++ b/vmware_nsx/tests/unit/nsx_v3/mocks.py @@ -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) diff --git a/vmware_nsx/tests/unit/nsx_v3/test_plugin.py b/vmware_nsx/tests/unit/nsx_v3/test_plugin.py index e11ac00faa..cc39affd32 100644 --- a/vmware_nsx/tests/unit/nsx_v3/test_plugin.py +++ b/vmware_nsx/tests/unit/nsx_v3/test_plugin.py @@ -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, diff --git a/vmware_nsx/tests/unit/nsxlib/v3/nsxlib_testcase.py b/vmware_nsx/tests/unit/nsxlib/v3/nsxlib_testcase.py index bab4d3d674..e5d56173c6 100644 --- a/vmware_nsx/tests/unit/nsxlib/v3/nsxlib_testcase.py +++ b/vmware_nsx/tests/unit/nsxlib/v3/nsxlib_testcase.py @@ -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, diff --git a/vmware_nsx/tests/unit/services/l2gateway/test_nsxv3_driver.py b/vmware_nsx/tests/unit/services/l2gateway/test_nsxv3_driver.py index 2957954228..98b94f5d8d 100644 --- a/vmware_nsx/tests/unit/services/l2gateway/test_nsxv3_driver.py +++ b/vmware_nsx/tests/unit/services/l2gateway/test_nsxv3_driver.py @@ -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()