Merge "Uses fixtures for mox and stubs"

This commit is contained in:
Jenkins 2013-10-31 19:03:05 +00:00 committed by Gerrit Code Review
commit 5a93bd50d5
6 changed files with 34 additions and 11 deletions

View File

@ -24,9 +24,7 @@ import sys
import time
from lxml import etree
import mox
from paste import deploy
import stubout
import testtools
@ -82,6 +80,7 @@ TMPDIR = os.path.join(TESTSDIR, 'tmp')
CONF = config.CONF
cd = os.chdir
exception._FATAL_EXCEPTION_FORMAT_ERRORS = True
def rootdir(*p):
@ -259,10 +258,7 @@ class TestCase(testtools.TestCase):
testsdir('test_overrides.conf')])
# ensure the cache region instance is setup
cache.configure_cache_region(cache.REGION)
self.mox = mox.Mox()
self.opt(policy_file=etcdir('policy.json'))
self.stubs = stubout.StubOutForTesting()
self.stubs.Set(exception, '_FATAL_EXCEPTION_FORMAT_ERRORS', True)
def config(self, config_files):
CONF(args=[], project='keystone', default_config_files=config_files)
@ -270,10 +266,6 @@ class TestCase(testtools.TestCase):
def tearDown(self):
try:
timeutils.clear_time_override()
self.mox.UnsetStubs()
self.stubs.UnsetAll()
self.stubs.SmartUnsetAll()
self.mox.VerifyAll()
# NOTE(morganfainberg): The only way to reconfigure the
# CacheRegion object on each setUp() call is to remove the
# .backend property.

View File

@ -27,6 +27,7 @@ from keystone.common import sql
from keystone import config
from keystone import exception
from keystone import identity
from keystone.openstack.common.fixture import moxstubout
from keystone import tests
from keystone.tests import default_fixtures
from keystone.tests import fakeldap
@ -359,6 +360,10 @@ class LDAPIdentity(tests.TestCase, BaseLDAPIdentity):
self.load_backends()
self.load_fixtures(default_fixtures)
fixture = self.useFixture(moxstubout.MoxStubout())
self.mox = fixture.mox
self.stubs = fixture.stubs
def test_configurable_allowed_project_actions(self):
tenant = {'id': 'fake1', 'name': 'fake1', 'enabled': True}
self.assignment_api.create_project('fake1', tenant)

View File

@ -17,6 +17,7 @@
import uuid
from keystone import notifications
from keystone.openstack.common.fixture import moxstubout
from keystone.openstack.common.notifier import api as notifier_api
from keystone import tests
from keystone.tests import test_v3
@ -45,6 +46,9 @@ class NotificationsWrapperTestCase(tests.TestCase):
self.assertEqual(self.exp_host, host)
self.send_notification_called = True
fixture = self.useFixture(moxstubout.MoxStubout())
self.stubs = fixture.stubs
self.stubs.Set(notifications, '_send_notification', fake_notify)
@notifications.created(EXP_RESOURCE_TYPE)
@ -118,6 +122,11 @@ class NotificationsWrapperTestCase(tests.TestCase):
class NotificationsTestCase(tests.TestCase):
def setUp(self):
super(NotificationsTestCase, self).setUp()
fixture = self.useFixture(moxstubout.MoxStubout())
self.stubs = fixture.stubs
def test_send_notification(self):
"""Test the private method _send_notification to ensure event_type,
payload, and context are built and passed properly.
@ -163,6 +172,9 @@ class NotificationsForEntities(test_v3.RestfulTestCase):
self.exp_resource_type = resource_type
self.send_notification_called = True
fixture = self.useFixture(moxstubout.MoxStubout())
self.stubs = fixture.stubs
self.stubs.Set(notifications, '_send_notification', fake_notify)
def _assertLastNotify(self, resource_id, operation, resource_type):

View File

@ -21,6 +21,7 @@ import urllib2
from keystone import config
from keystone import exception
from keystone.openstack.common.fixture import moxstubout
from keystone.openstack.common import policy as common_policy
from keystone.policy.backends import rules
from keystone import tests
@ -81,6 +82,9 @@ class PolicyTestCase(tests.TestCase):
self.credentials = {}
self.target = {}
fixture = self.useFixture(moxstubout.MoxStubout())
self.stubs = fixture.stubs
def _set_rules(self):
these_rules = common_policy.Rules(
dict((k, common_policy.parse_rule(v))

View File

@ -15,11 +15,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from keystone import tests
from keystone import config
from keystone import controllers
from keystone.openstack.common.fixture import moxstubout
from keystone.openstack.common import jsonutils
from keystone import tests
CONF = config.CONF
@ -120,6 +120,9 @@ class VersionTestCase(tests.TestCase):
self.public_server = self.serveapp('keystone', name='main')
self.admin_server = self.serveapp('keystone', name='admin')
fixture = self.useFixture(moxstubout.MoxStubout())
self.stubs = fixture.stubs
def _paste_in_port(self, response, port):
for link in response['links']:
if link['rel'] == 'self':
@ -327,6 +330,9 @@ vnd.openstack.identity-v3+xml"/>
self.public_server = self.serveapp('keystone', name='main')
self.admin_server = self.serveapp('keystone', name='admin')
fixture = self.useFixture(moxstubout.MoxStubout())
self.stubs = fixture.stubs
def test_public_versions(self):
client = self.client(self.public_app)
resp = client.get('/', headers=self.REQUEST_HEADERS)

View File

@ -21,6 +21,7 @@ import gettext
from keystone.common import wsgi
from keystone import exception
from keystone.openstack.common.fixture import moxstubout
from keystone.openstack.common import gettextutils
from keystone.openstack.common import jsonutils
from keystone import tests
@ -224,6 +225,9 @@ class LocalizedResponseTest(tests.TestCase):
super(LocalizedResponseTest, self).setUp()
gettextutils._AVAILABLE_LANGUAGES.clear()
fixture = self.useFixture(moxstubout.MoxStubout())
self.stubs = fixture.stubs
def tearDown(self):
gettextutils._AVAILABLE_LANGUAGES.clear()
super(LocalizedResponseTest, self).tearDown()