Replace usage of unittest module with manila.test

test modules
manila.tests.api.v1.test_share_networks
manila.tests.network.neutron.test_neutron_api
manila.tests.network.neutron.test_neutron_plugin

inherit unittest.TestCase, but all test classes
should inherit manila.test.TestCase

Also moved all predefines from __init__ to setUp

Change-Id: I07de752e6ca8cd206daeb966a75113239c6d411c
This commit is contained in:
Valeriy Ponomaryov 2014-06-20 10:22:49 -04:00
parent bc6783c4db
commit e3928ed16b
3 changed files with 15 additions and 15 deletions

View File

@ -14,7 +14,6 @@
# under the License.
import mock
import unittest
from webob import exc as webob_exc
from manila.api.v1 import share_networks
@ -23,6 +22,7 @@ from manila.db import api as db_api
from manila import exception
from manila import policy
from manila import quota
from manila import test
from manila.tests.api import fakes
@ -52,14 +52,14 @@ fake_share_network_shortened = {
QUOTAS = quota.QUOTAS
class ShareNetworkAPITest(unittest.TestCase):
class ShareNetworkAPITest(test.TestCase):
def __init__(self, *args, **kwargs):
super(ShareNetworkAPITest, self).__init__(*args, **kwargs)
def setUp(self):
super(ShareNetworkAPITest, self).setUp()
self.controller = share_networks.ShareNetworkController()
self.req = fakes.HTTPRequest.blank('/share-networks')
self.context = self.req.environ['manila.context']
self.body = {share_networks.RESOURCE_NAME: {'name': 'fake name'}}
self.context = self.req.environ['manila.context']
def _check_share_network_view_shortened(self, view, share_nw):
self.assertEqual(view['id'], share_nw['id'])
@ -174,7 +174,8 @@ class ShareNetworkAPITest(unittest.TestCase):
def test_show_not_found(self):
share_nw = 'fake network id'
test_exception = exception.ShareNetworkNotFound()
test_exception = exception.ShareNetworkNotFound(
share_network_id=share_nw)
with mock.patch.object(db_api,
'share_network_get',
mock.Mock(side_effect=test_exception)):

View File

@ -12,14 +12,11 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# vim: tabstop=4 shiftwidth=4 softtabstop=4
import mock
from neutronclient.common import exceptions as neutron_client_exc
from neutronclient.v2_0 import client as clientv20
from oslo.config import cfg
import unittest
from manila import context
from manila.db import base
@ -27,6 +24,7 @@ from manila import exception
from manila.network import neutron
from manila.network.neutron import api as neutron_api
from manila.network.neutron import constants as neutron_constants
from manila import test
from manila.tests.db import fakes
CONF = cfg.CONF
@ -83,7 +81,7 @@ class FakeNeutronClient(object):
pass
class NeutronApiTest(unittest.TestCase):
class NeutronApiTest(test.TestCase):
def setUp(self):
super(NeutronApiTest, self).setUp()
@ -430,7 +428,7 @@ class NeutronApiTest(unittest.TestCase):
neutron_api.LOG.exception.assert_called_once()
class TestNeutronClient(unittest.TestCase):
class TestNeutronClient(test.TestCase):
@mock.patch.object(clientv20.Client, '__init__',
mock.Mock(return_value=None))

View File

@ -12,8 +12,8 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
import unittest
from manila.common import constants
from manila import context
@ -21,6 +21,7 @@ from manila.db import api as db_api
from manila import exception
from manila.network.neutron import constants as neutron_constants
from manila.network.neutron import neutron_network_plugin as plugin
from manila import test
fake_neutron_port = {
"status": "test_port_status",
@ -64,10 +65,10 @@ fake_network_allocation = \
'status': constants.STATUS_ACTIVE}
class NeutronNetworkPluginTest(unittest.TestCase):
def __init__(self, *args, **kwargs):
super(NeutronNetworkPluginTest, self).__init__(*args, **kwargs)
class NeutronNetworkPluginTest(test.TestCase):
def setUp(self):
super(NeutronNetworkPluginTest, self).setUp()
self.plugin = plugin.NeutronNetworkPlugin()
self.plugin.db = db_api
self.fake_context = context.RequestContext(user_id='fake user',