diff options
author | Jamie Lennox <jamielennox@gmail.com> | 2016-06-24 16:56:09 +1000 |
---|---|---|
committer | Steve Martinelli <s.martinelli@gmail.com> | 2016-06-24 14:18:31 +0000 |
commit | b49449ff0b2ff21f9e6a0548b6e8e41fa3720bab (patch) | |
tree | 52dbb60b448b177e4858a12262fc6126e6d902ce | |
parent | 9c67feedb655b858450437cd0fce099393dde276 (diff) | |
download | keystonemiddleware-b49449ff0b2ff21f9e6a0548b6e8e41fa3720bab.tar.gz |
Use createfile fixture in audit test
Use the createfile fixture from oslotest rather than mkstemp in audit
middleware testing.
Change-Id: I1ce557c1d81e344bdaa10af65daf89f64f6011f0
-rw-r--r-- | keystonemiddleware/tests/unit/audit/test_audit_middleware.py | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/keystonemiddleware/tests/unit/audit/test_audit_middleware.py b/keystonemiddleware/tests/unit/audit/test_audit_middleware.py index e7d2a0b..acdb7fd 100644 --- a/keystonemiddleware/tests/unit/audit/test_audit_middleware.py +++ b/keystonemiddleware/tests/unit/audit/test_audit_middleware.py @@ -11,12 +11,11 @@ # License for the specific language governing permissions and limitations # under the License. -import os -import tempfile import uuid import mock from oslo_config import fixture as cfg_fixture +from oslotest import createfile from pycadf import cadftaxonomy as taxonomy from testtools import matchers import webob @@ -40,25 +39,31 @@ class FakeFailingApp(object): raise Exception('It happens!') +audit_map_content = """ +[custom_actions] +reboot = start/reboot +os-migrations/get = read + +[path_keywords] +action = None +os-hosts = host +os-migrations = None +reboot = None +servers = server + +[service_endpoints] +compute = service/compute +""" + + class BaseAuditMiddlewareTest(utils.BaseTestCase): PROJECT_NAME = 'keystonemiddleware' def setUp(self): super(BaseAuditMiddlewareTest, self).setUp() - self.fd, self.audit_map = tempfile.mkstemp() - with open(self.audit_map, "w") as f: - f.write("[custom_actions]\n") - f.write("reboot = start/reboot\n") - f.write("os-migrations/get = read\n\n") - f.write("[path_keywords]\n") - f.write("action = None\n") - f.write("os-hosts = host\n") - f.write("os-migrations = None\n") - f.write("reboot = None\n") - f.write("servers = server\n\n") - f.write("[service_endpoints]\n") - f.write("compute = service/compute") + self.audit_map_file_fixture = self.useFixture( + createfile.CreateFileWithContent('audit', audit_map_content)) self.cfg = self.useFixture(cfg_fixture.Config()) self.cfg.conf([], project=self.PROJECT_NAME) @@ -67,7 +72,9 @@ class BaseAuditMiddlewareTest(utils.BaseTestCase): FakeApp(), audit_map_file=self.audit_map, service_name='pycadf') - self.addCleanup(lambda: os.close(self.fd)) + @property + def audit_map(self): + return self.audit_map_file_fixture.path @staticmethod def get_environ_header(req_type): |