summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Stanek <dstanek@dstanek.com>2013-10-31 00:27:28 +0000
committerDirk Mueller <dirk@dmllr.de>2014-01-30 13:29:53 +0100
commit9983fbeaf35a81b6bd3085238b42f3fc42f47d01 (patch)
treea7c16444be149f7c9bd5736738db9dae563958ce
parent0d83e7eee20a50a75863a9d3c75aee7030518229 (diff)
downloadkeystone-9983fbeaf35a81b6bd3085238b42f3fc42f47d01.tar.gz
Adds fixture package from oslo
The mock library is added to test-requirements.txt since the mockpatch fixture requires it. Change-Id: I1b5b0c75f256382a685fceb2117db6d5b18d8c4f (cherry picked from commit 07aa0a91a120c1b07cbfe800ec0f78abb81a7271)
-rw-r--r--keystone/openstack/common/fixture/__init__.py0
-rw-r--r--keystone/openstack/common/fixture/config.py46
-rw-r--r--keystone/openstack/common/fixture/lockutils.py53
-rw-r--r--keystone/openstack/common/fixture/mockpatch.py51
-rw-r--r--keystone/openstack/common/fixture/moxstubout.py34
-rw-r--r--openstack-common.conf1
-rw-r--r--test-requirements.txt2
7 files changed, 187 insertions, 0 deletions
diff --git a/keystone/openstack/common/fixture/__init__.py b/keystone/openstack/common/fixture/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/keystone/openstack/common/fixture/__init__.py
diff --git a/keystone/openstack/common/fixture/config.py b/keystone/openstack/common/fixture/config.py
new file mode 100644
index 000000000..7b044ef74
--- /dev/null
+++ b/keystone/openstack/common/fixture/config.py
@@ -0,0 +1,46 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+#
+# Copyright 2013 Mirantis, Inc.
+# Copyright 2013 OpenStack Foundation
+# 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.
+import fixtures
+from oslo.config import cfg
+import six
+
+
+class Config(fixtures.Fixture):
+ """Override some configuration values.
+
+ The keyword arguments are the names of configuration options to
+ override and their values.
+
+ If a group argument is supplied, the overrides are applied to
+ the specified configuration option group.
+
+ All overrides are automatically cleared at the end of the current
+ test by the reset() method, which is registred by addCleanup().
+ """
+
+ def __init__(self, conf=cfg.CONF):
+ self.conf = conf
+
+ def setUp(self):
+ super(Config, self).setUp()
+ self.addCleanup(self.conf.reset)
+
+ def config(self, **kw):
+ group = kw.pop('group', None)
+ for k, v in six.iteritems(kw):
+ self.conf.set_override(k, v, group)
diff --git a/keystone/openstack/common/fixture/lockutils.py b/keystone/openstack/common/fixture/lockutils.py
new file mode 100644
index 000000000..3a194e75a
--- /dev/null
+++ b/keystone/openstack/common/fixture/lockutils.py
@@ -0,0 +1,53 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2011 OpenStack Foundation.
+# 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.
+
+import fixtures
+
+from keystone.openstack.common.lockutils import lock
+
+
+class LockFixture(fixtures.Fixture):
+ """External locking fixture.
+
+ This fixture is basically an alternative to the synchronized decorator with
+ the external flag so that tearDowns and addCleanups will be included in
+ the lock context for locking between tests. The fixture is recommended to
+ be the first line in a test method, like so::
+
+ def test_method(self):
+ self.useFixture(LockFixture)
+ ...
+
+ or the first line in setUp if all the test methods in the class are
+ required to be serialized. Something like::
+
+ class TestCase(testtools.testcase):
+ def setUp(self):
+ self.useFixture(LockFixture)
+ super(TestCase, self).setUp()
+ ...
+
+ This is because addCleanups are put on a LIFO queue that gets run after the
+ test method exits. (either by completing or raising an exception)
+ """
+ def __init__(self, name, lock_file_prefix=None):
+ self.mgr = lock(name, lock_file_prefix, True)
+
+ def setUp(self):
+ super(LockFixture, self).setUp()
+ self.addCleanup(self.mgr.__exit__, None, None, None)
+ self.mgr.__enter__()
diff --git a/keystone/openstack/common/fixture/mockpatch.py b/keystone/openstack/common/fixture/mockpatch.py
new file mode 100644
index 000000000..cd0d6ca6b
--- /dev/null
+++ b/keystone/openstack/common/fixture/mockpatch.py
@@ -0,0 +1,51 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2010 United States Government as represented by the
+# Administrator of the National Aeronautics and Space Administration.
+# Copyright 2013 Hewlett-Packard Development Company, L.P.
+# 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.
+
+import fixtures
+import mock
+
+
+class PatchObject(fixtures.Fixture):
+ """Deal with code around mock."""
+
+ def __init__(self, obj, attr, **kwargs):
+ self.obj = obj
+ self.attr = attr
+ self.kwargs = kwargs
+
+ def setUp(self):
+ super(PatchObject, self).setUp()
+ _p = mock.patch.object(self.obj, self.attr, **self.kwargs)
+ self.mock = _p.start()
+ self.addCleanup(_p.stop)
+
+
+class Patch(fixtures.Fixture):
+
+ """Deal with code around mock.patch."""
+
+ def __init__(self, obj, **kwargs):
+ self.obj = obj
+ self.kwargs = kwargs
+
+ def setUp(self):
+ super(Patch, self).setUp()
+ _p = mock.patch(self.obj, **self.kwargs)
+ self.mock = _p.start()
+ self.addCleanup(_p.stop)
diff --git a/keystone/openstack/common/fixture/moxstubout.py b/keystone/openstack/common/fixture/moxstubout.py
new file mode 100644
index 000000000..a0e74fd11
--- /dev/null
+++ b/keystone/openstack/common/fixture/moxstubout.py
@@ -0,0 +1,34 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2010 United States Government as represented by the
+# Administrator of the National Aeronautics and Space Administration.
+# Copyright 2013 Hewlett-Packard Development Company, L.P.
+# 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.
+
+import fixtures
+import mox
+
+
+class MoxStubout(fixtures.Fixture):
+ """Deal with code around mox and stubout as a fixture."""
+
+ def setUp(self):
+ super(MoxStubout, self).setUp()
+ # emulate some of the mox stuff, we can't use the metaclass
+ # because it screws with our generators
+ self.mox = mox.Mox()
+ self.stubs = self.mox.stubs
+ self.addCleanup(self.mox.UnsetStubs)
+ self.addCleanup(self.mox.VerifyAll)
diff --git a/openstack-common.conf b/openstack-common.conf
index e36745c7b..b5d95d602 100644
--- a/openstack-common.conf
+++ b/openstack-common.conf
@@ -4,6 +4,7 @@
module=db
module=db.sqlalchemy
module=crypto
+module=fixture
module=importutils
module=install_venv_common
module=jsonutils
diff --git a/test-requirements.txt b/test-requirements.txt
index 757a5eadb..fac44b1a1 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -15,6 +15,8 @@ python-ldap==2.3.13
coverage>=3.6
# mock object framework
mox>=0.5.3
+mock>=1.0
+fixtures>=0.3.14
# for test discovery and console feedback
nose
nosexcover