Get all tests to use tests.base.TestCase

part of bug 1177924

Change-Id: If8124e2ca21bf9766adf770e30a630437c6fcd95
This commit is contained in:
Angus Salkeld
2013-05-09 14:46:36 +10:00
committed by Doug Hellmann
parent 65a83066f0
commit 06093adfaf
13 changed files with 38 additions and 33 deletions

View File

@@ -19,18 +19,19 @@
""" """
import os import os
import tempfile import tempfile
import unittest
from oslo.config import cfg from oslo.config import cfg
from ceilometer.api.v1 import app from ceilometer.api.v1 import app
from ceilometer.api import acl from ceilometer.api import acl
from ceilometer import service from ceilometer import service
from ceilometer.tests import base
class TestApp(unittest.TestCase): class TestApp(base.TestCase):
def tearDown(self): def tearDown(self):
super(TestApp, self).tearDown()
cfg.CONF.reset() cfg.CONF.reset()
def test_keystone_middleware_conf(self): def test_keystone_middleware_conf(self):

View File

@@ -19,19 +19,20 @@
""" """
import os import os
import tempfile import tempfile
import unittest
from oslo.config import cfg from oslo.config import cfg
from ceilometer.api import app from ceilometer.api import app
from ceilometer.api import acl from ceilometer.api import acl
from ceilometer import service from ceilometer import service
from ceilometer.tests import base
from .base import FunctionalTest from .base import FunctionalTest
class TestApp(unittest.TestCase): class TestApp(base.TestCase):
def tearDown(self): def tearDown(self):
super(TestApp, self).tearDown()
cfg.CONF.reset() cfg.CONF.reset()
def test_keystone_middleware_conf(self): def test_keystone_middleware_conf(self):

View File

@@ -20,14 +20,15 @@
import datetime import datetime
import logging import logging
import unittest
from ceilometer.api.controllers import v2 from ceilometer.api.controllers import v2
from ceilometer.tests import base
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
class TestStatisticsDuration(unittest.TestCase): class TestStatisticsDuration(base.TestCase):
def setUp(self): def setUp(self):
super(TestStatisticsDuration, self).setUp() super(TestStatisticsDuration, self).setUp()

View File

@@ -18,12 +18,11 @@
"""Tests for ceilometer.compute.instance """Tests for ceilometer.compute.instance
""" """
import unittest
import mock import mock
from ceilometer.compute import instance from ceilometer.compute import instance
from ceilometer.compute import manager from ceilometer.compute import manager
from ceilometer.tests import base
class FauxInstance(object): class FauxInstance(object):
@@ -42,7 +41,7 @@ class FauxInstance(object):
return default return default
class TestLocationMetadata(unittest.TestCase): class TestLocationMetadata(base.TestCase):
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock()) @mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
def setUp(self): def setUp(self):

View File

@@ -19,8 +19,7 @@
notification events. notification events.
""" """
import unittest from ceilometer.tests import base
from ceilometer.compute import notifications from ceilometer.compute import notifications
from ceilometer import counter from ceilometer import counter
@@ -352,7 +351,7 @@ INSTANCE_DELETE_SAMPLES = {
} }
class TestNotifications(unittest.TestCase): class TestNotifications(base.TestCase):
def test_process_notification(self): def test_process_notification(self):
info = notifications.Instance().process_notification( info = notifications.Instance().process_notification(

View File

@@ -18,10 +18,10 @@
# under the License. # under the License.
from datetime import datetime from datetime import datetime
import unittest
from ceilometer.image import notifications from ceilometer.image import notifications
from ceilometer import counter from ceilometer import counter
from ceilometer.tests import base
def fake_uuid(x): def fake_uuid(x):
@@ -89,7 +89,7 @@ NOTIFICATION_DELETE = {"message_id": "0c65cb9c-018c-11e2-bc91-5453ed1bbb5f",
"timestamp": NOW} "timestamp": NOW}
class TestNotification(unittest.TestCase): class TestNotification(base.TestCase):
def _verify_common_counter(self, c, name, volume): def _verify_common_counter(self, c, name, volume):
self.assertFalse(c is None) self.assertFalse(c is None)

View File

@@ -18,9 +18,8 @@
"""Tests for ceilometer.network.notifications """Tests for ceilometer.network.notifications
""" """
import unittest
from ceilometer.network import notifications from ceilometer.network import notifications
from ceilometer.tests import base
NOTIFICATION_NETWORK_CREATE = { NOTIFICATION_NETWORK_CREATE = {
u'_context_roles': [u'anotherrole', u'_context_roles': [u'anotherrole',
@@ -204,7 +203,7 @@ NOTIFICATION_FLOATINGIP_EXISTS = {
u'message_id': u'9e839576-cc47-4c60-a7d8-5743681213b1'} u'message_id': u'9e839576-cc47-4c60-a7d8-5743681213b1'}
class TestNotifications(unittest.TestCase): class TestNotifications(base.TestCase):
def test_network_create(self): def test_network_create(self):
v = notifications.Network() v = notifications.Network()
counters = list(v.process_notification(NOTIFICATION_NETWORK_CREATE)) counters = list(v.process_notification(NOTIFICATION_NETWORK_CREATE))
@@ -246,7 +245,7 @@ class TestNotifications(unittest.TestCase):
self.assertEqual(counters[0].name, "ip.floating") self.assertEqual(counters[0].name, "ip.floating")
class TestEventTypes(unittest.TestCase): class TestEventTypes(base.TestCase):
def test_network(self): def test_network(self):
v = notifications.Network() v = notifications.Network()

View File

@@ -17,12 +17,12 @@
# under the License. # under the License.
import datetime import datetime
import math import math
import unittest
from ceilometer.storage import base from ceilometer.storage import base
from ceilometer.tests import base as test_base
class BaseTest(unittest.TestCase): class BaseTest(test_base.TestCase):
def test_iter_period(self): def test_iter_period(self):
times = list(base.iter_period( times = list(base.iter_period(

View File

@@ -16,9 +16,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import unittest
from ceilometer.storage import models from ceilometer.storage import models
from ceilometer.tests import base
class FakeModel(models.Model): class FakeModel(models.Model):
@@ -26,7 +25,7 @@ class FakeModel(models.Model):
models.Model.__init__(self, arg1=arg1, arg2=arg2) models.Model.__init__(self, arg1=arg1, arg2=arg2)
class ModelTest(unittest.TestCase): class ModelTest(base.TestCase):
def test_create_attributes(self): def test_create_attributes(self):
m = FakeModel(1, 2) m = FakeModel(1, 2)

View File

@@ -25,11 +25,13 @@ import socket
import subprocess import subprocess
import tempfile import tempfile
import time import time
import unittest
from ceilometer.tests import base
class BinDbsyncTestCase(unittest.TestCase): class BinDbsyncTestCase(base.TestCase):
def setUp(self): def setUp(self):
super(BinDbsyncTestCase, self).setUp()
self.tempfile = tempfile.mktemp() self.tempfile = tempfile.mktemp()
with open(self.tempfile, 'w') as tmp: with open(self.tempfile, 'w') as tmp:
tmp.write("[DEFAULT]\n") tmp.write("[DEFAULT]\n")
@@ -41,11 +43,13 @@ class BinDbsyncTestCase(unittest.TestCase):
self.assertEqual(subp.wait(), 0) self.assertEqual(subp.wait(), 0)
def tearDown(self): def tearDown(self):
super(BinDbsyncTestCase, self).tearDown()
os.unlink(self.tempfile) os.unlink(self.tempfile)
class BinSendCounterTestCase(unittest.TestCase): class BinSendCounterTestCase(base.TestCase):
def setUp(self): def setUp(self):
super(BinSendCounterTestCase, self).setUp()
self.tempfile = tempfile.mktemp() self.tempfile = tempfile.mktemp()
with open(self.tempfile, 'w') as tmp: with open(self.tempfile, 'w') as tmp:
tmp.write("[DEFAULT]\n") tmp.write("[DEFAULT]\n")
@@ -62,12 +66,14 @@ class BinSendCounterTestCase(unittest.TestCase):
self.assertEqual(subp.wait(), 0) self.assertEqual(subp.wait(), 0)
def tearDown(self): def tearDown(self):
super(BinSendCounterTestCase, self).tearDown()
os.unlink(self.tempfile) os.unlink(self.tempfile)
class BinApiTestCase(unittest.TestCase): class BinApiTestCase(base.TestCase):
def setUp(self): def setUp(self):
super(BinApiTestCase, self).setUp()
self.api_port = random.randint(10000, 11000) self.api_port = random.randint(10000, 11000)
self.http = httplib2.Http() self.http = httplib2.Http()
self.tempfile = tempfile.mktemp() self.tempfile = tempfile.mktemp()
@@ -88,6 +94,7 @@ class BinApiTestCase(unittest.TestCase):
"--config-file=%s" % self.tempfile]) "--config-file=%s" % self.tempfile])
def tearDown(self): def tearDown(self):
super(BinApiTestCase, self).tearDown()
os.unlink(self.tempfile) os.unlink(self.tempfile)
self.subp.kill() self.subp.kill()
self.subp.wait() self.subp.wait()

View File

@@ -34,6 +34,7 @@ class TestPolicy(base.TestCase):
policy._POLICY_CACHE = {} policy._POLICY_CACHE = {}
def tearDown(self): def tearDown(self):
super(TestPolicy, self).tearDown()
try: try:
os.unlink(cfg.CONF.policy_file) os.unlink(cfg.CONF.policy_file)
except OSError: except OSError:

View File

@@ -17,11 +17,10 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import unittest
from ceilometer import service from ceilometer import service
from ceilometer.tests import base
class ServiceTestCase(unittest.TestCase): class ServiceTestCase(base.TestCase):
def test_prepare_service(self): def test_prepare_service(self):
service.prepare_service() service.prepare_service()

View File

@@ -1,6 +1,5 @@
import unittest
from ceilometer.volume import notifications from ceilometer.volume import notifications
from ceilometer.tests import base
NOTIFICATION_VOLUME_EXISTS = { NOTIFICATION_VOLUME_EXISTS = {
u'_context_roles': [u'admin'], u'_context_roles': [u'admin'],
@@ -61,7 +60,7 @@ NOTIFICATION_VOLUME_DELETE = {
u'priority': u'INFO'} u'priority': u'INFO'}
class TestNotifications(unittest.TestCase): class TestNotifications(base.TestCase):
def _verify_common_counter(self, c, name, notification): def _verify_common_counter(self, c, name, notification):
self.assertFalse(c is None) self.assertFalse(c is None)