Use fixtures in the tests
TempDir() makes sure all files created under it are deleted at the end of the tests. FakeLogger() hides logs when the test passes and displays logs for failed tests. part of bug 1177924 Change-Id: I07acb66daa1932d7864a5431f1b64570b747ce5a
This commit is contained in:
parent
dea1ceb45a
commit
6693c9fb04
@ -18,8 +18,10 @@
|
||||
# under the License.
|
||||
"""Test base classes.
|
||||
"""
|
||||
import fixtures
|
||||
import mox
|
||||
from oslo.config import cfg
|
||||
import os.path
|
||||
import stubout
|
||||
import testtools
|
||||
|
||||
@ -32,6 +34,9 @@ class TestCase(testtools.TestCase):
|
||||
super(TestCase, self).setUp()
|
||||
self.mox = mox.Mox()
|
||||
self.stubs = stubout.StubOutForTesting()
|
||||
self.tempdir = self.useFixture(fixtures.TempDir())
|
||||
self.useFixture(fixtures.FakeLogger())
|
||||
|
||||
# Set a default location for the pipeline config file so the
|
||||
# tests work even if ceilometer is not installed globally on
|
||||
# the system.
|
||||
@ -40,6 +45,9 @@ class TestCase(testtools.TestCase):
|
||||
'../etc/ceilometer/pipeline.yaml',
|
||||
)
|
||||
|
||||
def temp_config_file_path(self, name='ceilometer.conf'):
|
||||
return os.path.join(self.tempdir.path, name)
|
||||
|
||||
def tearDown(self):
|
||||
self.mox.UnsetStubs()
|
||||
self.stubs.UnsetAll()
|
||||
|
@ -18,7 +18,6 @@
|
||||
"""Test basic ceilometer-api app
|
||||
"""
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
@ -42,7 +41,7 @@ class TestApp(base.TestCase):
|
||||
self.assertEqual(api_app.wsgi_app.auth_protocol, 'foottp')
|
||||
|
||||
def test_keystone_middleware_parse_conffile(self):
|
||||
tmpfile = tempfile.mktemp()
|
||||
tmpfile = self.temp_config_file_path()
|
||||
with open(tmpfile, "w") as f:
|
||||
f.write("[%s]\nauth_protocol = barttp" % acl.OPT_GROUP_NAME)
|
||||
f.write("\nauth_version = v2.0")
|
||||
|
@ -18,7 +18,6 @@
|
||||
"""Test basic ceilometer-api app
|
||||
"""
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
@ -46,7 +45,7 @@ class TestApp(base.TestCase):
|
||||
self.assertEqual(api_app.auth_protocol, 'foottp')
|
||||
|
||||
def test_keystone_middleware_parse_conffile(self):
|
||||
tmpfile = tempfile.mktemp()
|
||||
tmpfile = self.temp_config_file_path()
|
||||
with open(tmpfile, "w") as f:
|
||||
f.write("[DEFAULT]\n")
|
||||
f.write("pipeline_cfg_file = ../etc/ceilometer/pipeline.yaml\n")
|
||||
|
@ -19,11 +19,9 @@
|
||||
|
||||
import httplib2
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
import socket
|
||||
import subprocess
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
from ceilometer.tests import base
|
||||
@ -32,7 +30,7 @@ from ceilometer.tests import base
|
||||
class BinDbsyncTestCase(base.TestCase):
|
||||
def setUp(self):
|
||||
super(BinDbsyncTestCase, self).setUp()
|
||||
self.tempfile = tempfile.mktemp()
|
||||
self.tempfile = self.temp_config_file_path()
|
||||
with open(self.tempfile, 'w') as tmp:
|
||||
tmp.write("[DEFAULT]\n")
|
||||
tmp.write("database_connection=log://localhost\n")
|
||||
@ -42,15 +40,11 @@ class BinDbsyncTestCase(base.TestCase):
|
||||
"--config-file=%s" % self.tempfile])
|
||||
self.assertEqual(subp.wait(), 0)
|
||||
|
||||
def tearDown(self):
|
||||
super(BinDbsyncTestCase, self).tearDown()
|
||||
os.unlink(self.tempfile)
|
||||
|
||||
|
||||
class BinSendCounterTestCase(base.TestCase):
|
||||
def setUp(self):
|
||||
super(BinSendCounterTestCase, self).setUp()
|
||||
self.tempfile = tempfile.mktemp()
|
||||
self.tempfile = self.temp_config_file_path()
|
||||
with open(self.tempfile, 'w') as tmp:
|
||||
tmp.write("[DEFAULT]\n")
|
||||
tmp.write(
|
||||
@ -65,10 +59,6 @@ class BinSendCounterTestCase(base.TestCase):
|
||||
"--counter-name=mycounter"])
|
||||
self.assertEqual(subp.wait(), 0)
|
||||
|
||||
def tearDown(self):
|
||||
super(BinSendCounterTestCase, self).tearDown()
|
||||
os.unlink(self.tempfile)
|
||||
|
||||
|
||||
class BinApiTestCase(base.TestCase):
|
||||
|
||||
@ -76,7 +66,7 @@ class BinApiTestCase(base.TestCase):
|
||||
super(BinApiTestCase, self).setUp()
|
||||
self.api_port = random.randint(10000, 11000)
|
||||
self.http = httplib2.Http()
|
||||
self.tempfile = tempfile.mktemp()
|
||||
self.tempfile = self.temp_config_file_path()
|
||||
with open(self.tempfile, 'w') as tmp:
|
||||
tmp.write("[DEFAULT]\n")
|
||||
tmp.write(
|
||||
@ -95,7 +85,6 @@ class BinApiTestCase(base.TestCase):
|
||||
|
||||
def tearDown(self):
|
||||
super(BinApiTestCase, self).tearDown()
|
||||
os.unlink(self.tempfile)
|
||||
self.subp.kill()
|
||||
self.subp.wait()
|
||||
|
||||
|
@ -2,6 +2,7 @@ nose
|
||||
coverage
|
||||
mock
|
||||
mox
|
||||
fixtures>=0.3.12
|
||||
Babel>=0.9.6
|
||||
# NOTE(dhellmann): Ming is necessary to provide the Mongo-in-memory
|
||||
# implementation of MongoDB.
|
||||
|
Loading…
Reference in New Issue
Block a user