vmware-nsx/neutron/tests/unit/oneconvergence/test_plugin_helper.py
Hemanth Ravi b2483ba0ef One Convergence Neutron Plugin Implementation
One Convergence Neutron Plugin implements Neutron API to provide a network
virtualization solution. The plugin works with One Convergence NVSD controller
to provide the functionality. This checkin implements the Neutron core APIs
and the plugin will be extended to support the L3 and service plugin extension
APIs.

Change-Id: Ic8a0dc0f5950d41b9b253c0d61b6812dbfd161c7
Implements: blueprint oc-nvsd-neutron-plugin
2014-03-06 08:10:07 -08:00

61 lines
2.5 KiB
Python

# Copyright 2014 OneConvergence, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# @author: Kedar Kulkarni, One Convergence, Inc.
import mock
import requests
from neutron.openstack.common import jsonutils as json
from neutron.plugins.oneconvergence.lib import config # noqa
from neutron.plugins.oneconvergence.lib import plugin_helper as client
from neutron.tests import base
class TestPluginHelper(base.BaseTestCase):
def setUp(self):
super(TestPluginHelper, self).setUp()
self.nvsdcontroller = client.NVSDController()
def get_response(self, *args, **kwargs):
response = mock.Mock()
response.status_code = requests.codes.ok
response.content = json.dumps({'session_uuid': 'new_auth_token'})
return response
def test_login(self):
login_url = ('http://127.0.0.1:8082/pluginhandler/ocplugin/'
'authmgmt/login')
headers = {'Content-Type': 'application/json'}
data = json.dumps({"user_name": "ocplugin", "passwd": "oc123"})
timeout = 30.0
with mock.patch.object(self.nvsdcontroller, 'do_request',
side_effect=self.get_response) as do_request:
self.nvsdcontroller.login()
do_request.assert_called_once_with('POST', url=login_url,
headers=headers, data=data,
timeout=timeout)
def test_request(self):
with mock.patch.object(self.nvsdcontroller, 'do_request',
side_effect=self.get_response) as do_request:
self.nvsdcontroller.login()
self.nvsdcontroller.request("POST", "/some_url")
self.assertEqual(do_request.call_count, 2)
do_request.assert_called_with(
'POST',
url='http://127.0.0.1:8082/some_url?authToken=new_auth_token',
headers={'Content-Type': 'application/json'}, data='',
timeout=30.0)