Use stubs instead of monkey patch.
This commit is contained in:
parent
7e42a8fd78
commit
2356e4c0ca
39
tests/base.py
Normal file
39
tests/base.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
|
||||||
|
#
|
||||||
|
# Author: Chmouel Boudjnah <chmouel@enovance.com>
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
"""Test base classes imported from ceilometer.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import unittest2
|
||||||
|
|
||||||
|
import mox
|
||||||
|
import stubout
|
||||||
|
|
||||||
|
|
||||||
|
class TestCase(unittest2.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestCase, self).setUp()
|
||||||
|
self.mox = mox.Mox()
|
||||||
|
self.stubs = stubout.StubOutForTesting()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.mox.UnsetStubs()
|
||||||
|
self.stubs.UnsetAll()
|
||||||
|
self.stubs.SmartUnsetAll()
|
||||||
|
self.mox.VerifyAll()
|
||||||
|
super(TestCase, self).tearDown()
|
@ -14,27 +14,29 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# 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 unittest2
|
|
||||||
import swiftclient
|
import swiftclient
|
||||||
import keystoneclient
|
import keystoneclient
|
||||||
|
|
||||||
|
import base as test_base
|
||||||
import sync.accounts
|
import sync.accounts
|
||||||
from fakes import FakeSWConnection, TENANTS_LIST, STORAGE_ORIG, \
|
from fakes import FakeSWConnection, TENANTS_LIST, STORAGE_ORIG, \
|
||||||
STORAGE_DEST, FakeSWClient, FakeKS, CONFIGDICT, CONTAINERS_LIST, \
|
STORAGE_DEST, FakeSWClient, FakeKS, CONFIGDICT, CONTAINERS_LIST, \
|
||||||
fake_get_config
|
fake_get_config
|
||||||
|
|
||||||
|
|
||||||
class TestAccount(unittest2.TestCase):
|
class TestAccount(test_base.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
super(TestAccount, self).setUp()
|
||||||
self.accounts_cls = sync.accounts.Accounts()
|
self.accounts_cls = sync.accounts.Accounts()
|
||||||
self._monkey_patch()
|
self._stubs()
|
||||||
|
|
||||||
def _monkey_patch(self):
|
def _stubs(self):
|
||||||
keystoneclient.v2_0.client = FakeKS
|
self.stubs.Set(keystoneclient.v2_0, 'client', FakeKS)
|
||||||
swiftclient.get_account = FakeSWClient.get_account
|
self.stubs.Set(swiftclient.client, 'Connection', FakeSWConnection)
|
||||||
swiftclient.http_connection = FakeSWClient.http_connection
|
self.stubs.Set(sync.accounts, 'get_config', fake_get_config)
|
||||||
swiftclient.client.Connection = FakeSWConnection
|
self.stubs.Set(swiftclient, 'get_account', FakeSWClient.get_account)
|
||||||
sync.accounts.get_config = fake_get_config
|
self.stubs.Set(swiftclient, 'http_connection',
|
||||||
|
FakeSWClient.http_connection)
|
||||||
|
|
||||||
def test_get_swift_auth(self):
|
def test_get_swift_auth(self):
|
||||||
tenant_name = 'foo1'
|
tenant_name = 'foo1'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user