Fix leaked mocks in the 'common' module if any

Make all test suites in the module extend 'trove_testtools.TestCase' to
enable dangling mock detector.

Change-Id: I378878a2e3129c2d694695fbe3bb4174826386be
Partial-Bug: 1448273
This commit is contained in:
Petr Malik
2015-05-03 20:10:42 -04:00
parent b1cf32ba5b
commit fbfc1cfab0
8 changed files with 277 additions and 237 deletions

View File

@@ -13,16 +13,16 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from hashlib import md5
from mock import MagicMock, patch
import httplib import httplib
import json import json
import logging
import os import os
import socket import socket
import uuid
import logging
import swiftclient.client as swift_client
import swiftclient import swiftclient
from hashlib import md5 import swiftclient.client as swift_client
from mock import MagicMock import uuid
from swiftclient import client as swift from swiftclient import client as swift
@@ -203,7 +203,35 @@ class FakeSwiftConnection(object):
pass pass
class SwiftClientStub(object): class Patcher(object):
"""Objects that need to mock global symbols throughout their existence
should extend this base class.
The object acts as a context manager which, when used in conjunction with
the 'with' statement, terminates all running patchers when it leaves the
scope.
"""
def __init__(self):
self.__patchers = None
def __enter__(self):
self.__patchers = []
return self
def __exit__(self, type, value, traceback):
# Stop patchers in the LIFO order.
while self.__patchers:
self.__patchers.pop().stop()
def _start_patcher(self, patcher):
"""All patchers started by this method will be automatically
terminated on __exit__().
"""
self.__patchers.append(patcher)
return patcher.start()
class SwiftClientStub(Patcher):
""" """
Component for controlling behavior of Swift Client Stub. Instantiated Component for controlling behavior of Swift Client Stub. Instantiated
before tests are invoked in "fake" mode. Invoke methods to control before tests are invoked in "fake" mode. Invoke methods to control
@@ -257,6 +285,7 @@ class SwiftClientStub(object):
""" """
def __init__(self): def __init__(self):
super(SwiftClientStub, self).__init__()
self._connection = swift_client.Connection() self._connection = swift_client.Connection()
self._containers = {} self._containers = {}
self._containers_list = [] self._containers_list = []
@@ -296,7 +325,7 @@ class SwiftClientStub(object):
'content-type': 'application/json; charset=utf-8', 'content-type': 'application/json; charset=utf-8',
'x-account-object-count': '0'}, self._containers_list) 'x-account-object-count': '0'}, self._containers_list)
swift_client.Connection.get_auth = MagicMock(return_value=( get_auth_return_value = (
u"http://127.0.0.1:8080/v1/AUTH_c7b038976df24d96bf1980f5da17bd89", u"http://127.0.0.1:8080/v1/AUTH_c7b038976df24d96bf1980f5da17bd89",
u'MIINrwYJKoZIhvcNAQcCoIINoDCCDZwCAQExCTAHBgUrDgMCGjCCDIgGCSqGSIb3' u'MIINrwYJKoZIhvcNAQcCoIINoDCCDZwCAQExCTAHBgUrDgMCGjCCDIgGCSqGSIb3'
u'DQEHAaCCDHkEggx1eyJhY2Nlc3MiOiB7InRva2VuIjogeyJpc3N1ZWRfYXQiOiAi' u'DQEHAaCCDHkEggx1eyJhY2Nlc3MiOiB7InRva2VuIjogeyJpc3N1ZWRfYXQiOiAi'
@@ -305,9 +334,17 @@ class SwiftClientStub(object):
u'ImVuYWJsZWQiOiB0cnVlLCAiZGVzY3JpcHRpb24iOiBudWxsLCAibmFtZSI6ICJy' u'ImVuYWJsZWQiOiB0cnVlLCAiZGVzY3JpcHRpb24iOiBudWxsLCAibmFtZSI6ICJy'
u'ZWRkd2FyZiIsICJpZCI6ICJjN2IwMzg5NzZkZjI0ZDk2YmYxOTgwZjVkYTE3YmQ4' u'ZWRkd2FyZiIsICJpZCI6ICJjN2IwMzg5NzZkZjI0ZDk2YmYxOTgwZjVkYTE3YmQ4'
u'OSJ9fSwgInNlcnZpY2VDYXRhbG9nIjogW3siZW5kcG9pbnRzIjogW3siYWRtaW5') u'OSJ9fSwgInNlcnZpY2VDYXRhbG9nIjogW3siZW5kcG9pbnRzIjogW3siYWRtaW5')
)
swift_client.Connection.get_account = MagicMock( get_auth_patcher = patch.object(
return_value=account_resp()) swift_client.Connection, 'get_auth',
MagicMock(return_value=get_auth_return_value))
self._start_patcher(get_auth_patcher)
get_account_patcher = patch.object(
swift_client.Connection, 'get_account',
MagicMock(return_value=account_resp()))
self._start_patcher(get_account_patcher)
return self return self
def _create_container(self, container_name): def _create_container(self, container_name):
@@ -351,7 +388,9 @@ class SwiftClientStub(object):
self._objects[container]) self._objects[container])
# if this is called multiple times then nothing happens # if this is called multiple times then nothing happens
swift_client.Connection.put_container = MagicMock(return_value=None) put_container_patcher = patch.object(swift_client.Connection,
'put_container')
self._start_patcher(put_container_patcher)
def side_effect_func(*args, **kwargs): def side_effect_func(*args, **kwargs):
if args[0] in self._containers: if args[0] in self._containers:
@@ -362,8 +401,10 @@ class SwiftClientStub(object):
self._create_container(container_name) self._create_container(container_name)
# return container headers # return container headers
swift_client.Connection.get_container = MagicMock( get_container_patcher = patch.object(
side_effect=side_effect_func) swift_client.Connection, 'get_container',
MagicMock(side_effect=side_effect_func))
self._start_patcher(get_container_patcher)
return self return self
@@ -411,8 +452,10 @@ class SwiftClientStub(object):
:param contents: the contents of the object :param contents: the contents of the object
""" """
swift_client.Connection.put_object = MagicMock( put_object_patcher = patch.object(
return_value=uuid.uuid1()) swift_client.Connection, 'put_object',
MagicMock(return_value=uuid.uuid1()))
self._start_patcher(put_object_patcher)
def side_effect_func(*args, **kwargs): def side_effect_func(*args, **kwargs):
if (args[0] in self._containers and if (args[0] in self._containers and
@@ -432,8 +475,10 @@ class SwiftClientStub(object):
raise swiftclient.ClientException('Resource Not Found', raise swiftclient.ClientException('Resource Not Found',
http_status=404) http_status=404)
swift_client.Connection.get_object = MagicMock( get_object_patcher = patch.object(
side_effect=side_effect_func) swift_client.Connection, 'get_object',
MagicMock(side_effect=side_effect_func))
self._start_patcher(get_object_patcher)
self._remove_object(name, self._objects[container]) self._remove_object(name, self._objects[container])
self._objects[container].append( self._objects[container].append(
@@ -471,8 +516,10 @@ class SwiftClientStub(object):
else: else:
return None return None
swift_client.Connection.delete_object = MagicMock( delete_object_patcher = patch.object(
side_effect=side_effect_func) swift_client.Connection, 'delete_object',
MagicMock(side_effect=side_effect_func))
self._start_patcher(delete_object_patcher)
self._remove_object(name, self._objects[container]) self._remove_object(name, self._objects[container])
return self return self

View File

@@ -13,13 +13,12 @@
# 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 trove.common.context as context
import testtools
from testtools.matchers import Equals, Is from testtools.matchers import Equals, Is
from trove.common import context
from trove.tests.unittests import trove_testtools
class TestTroveContext(testtools.TestCase): class TestTroveContext(trove_testtools.TestCase):
def test_create_with_extended_args(self): def test_create_with_extended_args(self):
expected_service_catalog = {'key': 'value'} expected_service_catalog = {'key': 'value'}
ctx = context.TroveContext(user="test_user_id", ctx = context.TroveContext(user="test_user_id",

View File

@@ -11,13 +11,11 @@
# 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.
from testtools import TestCase
from trove.common.exception import TroveError from trove.common.exception import TroveError
from trove.tests.unittests import trove_testtools
class TroveErrorTest(TestCase): class TroveErrorTest(trove_testtools.TestCase):
def test_valid_error_message_format(self): def test_valid_error_message_format(self):
error = TroveError("%02d" % 1) error = TroveError("%02d" % 1)

View File

@@ -15,12 +15,11 @@
# 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 testtools
from trove.common.pagination import PaginatedDataView from trove.common.pagination import PaginatedDataView
from trove.tests.unittests import trove_testtools
class TestPaginatedDataView(testtools.TestCase): class TestPaginatedDataView(trove_testtools.TestCase):
def test_creation_with_string_marker(self): def test_creation_with_string_marker(self):
view = PaginatedDataView("TestType", [], "http://current_page", view = PaginatedDataView("TestType", [], "http://current_page",

View File

@@ -15,237 +15,240 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
# #
from mock import patch, MagicMock
from mock import MagicMock from testtools import ExpectedException, matchers
import testtools from trove.common import cfg
from testtools import matchers from trove.common import exception
from trove.common import remote
from trove.common.context import TroveContext
from trove.tests.fakes.swift import SwiftClientStub
from trove.tests.unittests import trove_testtools
import swiftclient.client import swiftclient.client
import uuid import uuid
from trove.tests.fakes.swift import SwiftClientStub
from trove.common.context import TroveContext
from trove.common import remote
from trove.common import exception
from trove.common import cfg
class TestRemote(trove_testtools.TestCase):
class TestRemote(testtools.TestCase):
def setUp(self): def setUp(self):
super(TestRemote, self).setUp() super(TestRemote, self).setUp()
def tearDown(self): def tearDown(self):
super(TestRemote, self).tearDown() super(TestRemote, self).tearDown()
def test_creation(self): @patch.object(swiftclient.client.Connection, 'get_auth')
swiftclient.client.Connection.get_auth = MagicMock(return_value=None) def test_creation(self, get_auth_mock):
conn = swiftclient.client.Connection() self.assertIsNotNone(swiftclient.client.Connection())
self.assertIsNone(conn.get_auth())
def test_create_swift_client(self): def test_create_swift_client(self):
mock_resp = MagicMock() mock_resp = MagicMock()
swiftclient.client.Connection.get_container = MagicMock( with patch.object(swiftclient.client.Connection, 'get_container',
return_value=["text", mock_resp]) MagicMock(return_value=["text", mock_resp])):
service_catalog = [{'endpoints': [{'region': 'RegionOne', service_catalog = [{'endpoints': [{'region': 'RegionOne',
'publicURL': 'example.com'}], 'publicURL': 'example.com'}],
'type': 'object-store'}] 'type': 'object-store'}]
client = remote.create_swift_client(TroveContext( client = remote.create_swift_client(TroveContext(
tenant=uuid.uuid4().hex, tenant=uuid.uuid4().hex,
service_catalog=service_catalog)) service_catalog=service_catalog))
headers, container = client.get_container('bob') headers, container = client.get_container('bob')
self.assertIs(headers, "text") self.assertIs(headers, "text")
self.assertIs(container, mock_resp) self.assertIs(container, mock_resp)
def test_empty_account(self): def test_empty_account(self):
""" """
this is an account with no containers and no objects this is an account with no containers and no objects
""" """
# setup expectation # setup expectation
swift_stub = SwiftClientStub() with SwiftClientStub() as swift_stub:
swift_stub.with_account('123223') swift_stub.with_account('123223')
# interact # interact
conn = swiftclient.client.Connection() conn = swiftclient.client.Connection()
account_info = conn.get_account() account_info = conn.get_account()
self.assertThat(account_info, matchers.Not(matchers.Is(None))) self.assertThat(account_info, matchers.Not(matchers.Is(None)))
self.assertThat(len(account_info), matchers.Is(2)) self.assertThat(len(account_info), matchers.Is(2))
self.assertThat(account_info, matchers.IsInstance(tuple)) self.assertThat(account_info, matchers.IsInstance(tuple))
self.assertThat(account_info[0], matchers.IsInstance(dict)) self.assertThat(account_info[0], matchers.IsInstance(dict))
self.assertThat(account_info[0], self.assertThat(
matchers.KeysEqual('content-length', 'accept-ranges', account_info[0],
'x-timestamp', 'x-trans-id', 'date', matchers.KeysEqual('content-length', 'accept-ranges',
'x-account-bytes-used', 'x-timestamp', 'x-trans-id', 'date',
'x-account-container-count', 'x-account-bytes-used',
'content-type', 'x-account-container-count',
'x-account-object-count')) 'content-type',
self.assertThat(account_info[1], matchers.IsInstance(list)) 'x-account-object-count'))
self.assertThat(len(account_info[1]), matchers.Is(0)) self.assertThat(account_info[1], matchers.IsInstance(list))
self.assertThat(len(account_info[1]), matchers.Is(0))
def test_one_container(self): def test_one_container(self):
""" """
tests to ensure behavior is normal with one container tests to ensure behavior is normal with one container
""" """
# setup expectation # setup expectation
swift_stub = SwiftClientStub() with SwiftClientStub() as swift_stub:
swift_stub.with_account('123223') swift_stub.with_account('123223')
cont_name = 'a-container-name' cont_name = 'a-container-name'
swift_stub.with_container(cont_name) swift_stub.with_container(cont_name)
# interact # interact
conn = swiftclient.client.Connection() conn = swiftclient.client.Connection()
conn.get_auth() conn.get_auth()
conn.put_container(cont_name) conn.put_container(cont_name)
# get headers plus container metadata # get headers plus container metadata
self.assertThat(len(conn.get_account()), matchers.Is(2)) self.assertThat(len(conn.get_account()), matchers.Is(2))
# verify container details # verify container details
account_containers = conn.get_account()[1] account_containers = conn.get_account()[1]
self.assertThat(len(account_containers), matchers.Is(1)) self.assertThat(len(account_containers), matchers.Is(1))
self.assertThat(account_containers[0], self.assertThat(account_containers[0],
matchers.KeysEqual('count', 'bytes', 'name')) matchers.KeysEqual('count', 'bytes', 'name'))
self.assertThat(account_containers[0]['name'], matchers.Is(cont_name)) self.assertThat(account_containers[0]['name'],
# get container details matchers.Is(cont_name))
cont_info = conn.get_container(cont_name) # get container details
self.assertIsNotNone(cont_info) cont_info = conn.get_container(cont_name)
self.assertThat(cont_info[0], matchers.KeysEqual('content-length', self.assertIsNotNone(cont_info)
'x-container-object-count', 'accept-ranges', self.assertThat(cont_info[0], matchers.KeysEqual('content-length',
'x-container-bytes-used', 'x-timestamp', 'x-container-object-count', 'accept-ranges',
'x-trans-id', 'date', 'content-type')) 'x-container-bytes-used', 'x-timestamp',
self.assertThat(len(cont_info[1]), matchers.Equals(0)) 'x-trans-id', 'date', 'content-type'))
# remove container self.assertThat(len(cont_info[1]), matchers.Equals(0))
swift_stub.without_container(cont_name) # remove container
with testtools.ExpectedException(swiftclient.ClientException): swift_stub.without_container(cont_name)
conn.get_container(cont_name) with ExpectedException(swiftclient.ClientException):
# ensure there are no more containers in account conn.get_container(cont_name)
self.assertThat(len(conn.get_account()[1]), matchers.Is(0)) # ensure there are no more containers in account
self.assertThat(len(conn.get_account()[1]), matchers.Is(0))
def test_one_object(self): def test_one_object(self):
swift_stub = SwiftClientStub() with SwiftClientStub() as swift_stub:
swift_stub.with_account('123223') swift_stub.with_account('123223')
swift_stub.with_container('bob') swift_stub.with_container('bob')
swift_stub.with_object('bob', 'test', 'test_contents') swift_stub.with_object('bob', 'test', 'test_contents')
# create connection # create connection
conn = swiftclient.client.Connection() conn = swiftclient.client.Connection()
# test container lightly # test container lightly
cont_info = conn.get_container('bob') cont_info = conn.get_container('bob')
self.assertIsNotNone(cont_info) self.assertIsNotNone(cont_info)
self.assertThat(cont_info[0], self.assertThat(cont_info[0],
matchers.KeysEqual('content-length', matchers.KeysEqual('content-length',
'x-container-object-count', 'x-container-object-count',
'accept-ranges', 'accept-ranges',
'x-container-bytes-used', 'x-container-bytes-used',
'x-timestamp', 'x-trans-id', 'date', 'x-timestamp',
'content-type')) 'x-trans-id',
cont_objects = cont_info[1] 'date',
self.assertThat(len(cont_objects), matchers.Equals(1)) 'content-type'))
obj_1 = cont_objects[0] cont_objects = cont_info[1]
self.assertThat(obj_1, matchers.Equals( self.assertThat(len(cont_objects), matchers.Equals(1))
{'bytes': 13, 'last_modified': '2013-03-15T22:10:49.361950', obj_1 = cont_objects[0]
'hash': 'ccc55aefbf92aa66f42b638802c5e7f6', 'name': 'test', self.assertThat(obj_1, matchers.Equals(
'content_type': 'application/octet-stream', {'bytes': 13, 'last_modified': '2013-03-15T22:10:49.361950',
'contents': 'test_contents'})) 'hash': 'ccc55aefbf92aa66f42b638802c5e7f6', 'name': 'test',
# test object api - not much to do here 'content_type': 'application/octet-stream',
self.assertThat(conn.get_object('bob', 'test')[1], 'contents': 'test_contents'}))
matchers.Is('test_contents')) # test object api - not much to do here
self.assertThat(conn.get_object('bob', 'test')[1],
matchers.Is('test_contents'))
# test remove object # test remove object
swift_stub.without_object('bob', 'test') swift_stub.without_object('bob', 'test')
# interact # interact
with testtools.ExpectedException(swiftclient.ClientException): with ExpectedException(swiftclient.ClientException):
conn.delete_object('bob', 'test') conn.delete_object('bob', 'test')
self.assertThat(len(conn.get_container('bob')[1]), matchers.Is(0)) self.assertThat(len(conn.get_container('bob')[1]), matchers.Is(0))
def test_two_objects(self): def test_two_objects(self):
swift_stub = SwiftClientStub() with SwiftClientStub() as swift_stub:
swift_stub.with_account('123223') swift_stub.with_account('123223')
swift_stub.with_container('bob') swift_stub.with_container('bob')
swift_stub.with_container('bob2') swift_stub.with_container('bob2')
swift_stub.with_object('bob', 'test', 'test_contents') swift_stub.with_object('bob', 'test', 'test_contents')
swift_stub.with_object('bob', 'test2', 'test_contents2') swift_stub.with_object('bob', 'test2', 'test_contents2')
conn = swiftclient.client.Connection() conn = swiftclient.client.Connection()
self.assertIs(len(conn.get_account()), 2) self.assertIs(len(conn.get_account()), 2)
cont_info = conn.get_container('bob') cont_info = conn.get_container('bob')
self.assertIsNotNone(cont_info) self.assertIsNotNone(cont_info)
self.assertThat(cont_info[0], self.assertThat(cont_info[0],
matchers.KeysEqual('content-length', matchers.KeysEqual('content-length',
'x-container-object-count', 'x-container-object-count',
'accept-ranges', 'accept-ranges',
'x-container-bytes-used', 'x-container-bytes-used',
'x-timestamp', 'x-trans-id', 'date', 'x-timestamp',
'content-type')) 'x-trans-id',
self.assertThat(len(cont_info[1]), matchers.Equals(2)) 'date',
self.assertThat(cont_info[1][0], matchers.Equals( 'content-type'))
{'bytes': 13, 'last_modified': '2013-03-15T22:10:49.361950', self.assertThat(len(cont_info[1]), matchers.Equals(2))
'hash': 'ccc55aefbf92aa66f42b638802c5e7f6', 'name': 'test', self.assertThat(cont_info[1][0], matchers.Equals(
'content_type': 'application/octet-stream', {'bytes': 13, 'last_modified': '2013-03-15T22:10:49.361950',
'contents': 'test_contents'})) 'hash': 'ccc55aefbf92aa66f42b638802c5e7f6', 'name': 'test',
self.assertThat(conn.get_object('bob', 'test')[1], 'content_type': 'application/octet-stream',
matchers.Is('test_contents')) 'contents': 'test_contents'}))
self.assertThat(conn.get_object('bob', 'test2')[1], self.assertThat(conn.get_object('bob', 'test')[1],
matchers.Is('test_contents2')) matchers.Is('test_contents'))
self.assertThat(conn.get_object('bob', 'test2')[1],
matchers.Is('test_contents2'))
swift_stub.without_object('bob', 'test') swift_stub.without_object('bob', 'test')
with testtools.ExpectedException(swiftclient.ClientException): with ExpectedException(swiftclient.ClientException):
conn.delete_object('bob', 'test') conn.delete_object('bob', 'test')
self.assertThat(len(conn.get_container('bob')[1]), matchers.Is(1)) self.assertThat(len(conn.get_container('bob')[1]), matchers.Is(1))
swift_stub.without_container('bob') swift_stub.without_container('bob')
with testtools.ExpectedException(swiftclient.ClientException): with ExpectedException(swiftclient.ClientException):
conn.get_container('bob') conn.get_container('bob')
self.assertThat(len(conn.get_account()), matchers.Is(2)) self.assertThat(len(conn.get_account()), matchers.Is(2))
def test_nonexisting_container(self): def test_nonexisting_container(self):
""" """
when a container does not exist and is accessed then a 404 is returned when a container does not exist and is accessed then a 404 is returned
""" """
from trove.tests.fakes.swift import SwiftClientStub
swift_stub = SwiftClientStub() with SwiftClientStub() as swift_stub:
swift_stub.with_account('123223') swift_stub.with_account('123223')
swift_stub.with_container('existing') swift_stub.with_container('existing')
conn = swiftclient.client.Connection() conn = swiftclient.client.Connection()
with testtools.ExpectedException(swiftclient.ClientException): with ExpectedException(swiftclient.ClientException):
conn.get_container('nonexisting') conn.get_container('nonexisting')
def test_replace_object(self): def test_replace_object(self):
""" """
Test to ensure that if an object is updated the container object Test to ensure that if an object is updated the container object
count is the same and the contents of the object are updated count is the same and the contents of the object are updated
""" """
swift_stub = SwiftClientStub() with SwiftClientStub() as swift_stub:
swift_stub.with_account('1223df2') swift_stub.with_account('1223df2')
swift_stub.with_container('new-container') swift_stub.with_container('new-container')
swift_stub.with_object('new-container', 'new-object', swift_stub.with_object('new-container', 'new-object',
'new-object-contents') 'new-object-contents')
conn = swiftclient.client.Connection() conn = swiftclient.client.Connection()
conn.put_object('new-container', 'new-object', 'new-object-contents') conn.put_object('new-container', 'new-object',
obj_resp = conn.get_object('new-container', 'new-object') 'new-object-contents')
self.assertThat(obj_resp, matchers.Not(matchers.Is(None))) obj_resp = conn.get_object('new-container', 'new-object')
self.assertThat(len(obj_resp), matchers.Is(2)) self.assertThat(obj_resp, matchers.Not(matchers.Is(None)))
self.assertThat(obj_resp[1], matchers.Is('new-object-contents')) self.assertThat(len(obj_resp), matchers.Is(2))
self.assertThat(obj_resp[1], matchers.Is('new-object-contents'))
# set expected behavior - trivial here since it is the intended # set expected behavior - trivial here since it is the intended
# behavior however keep in mind this is just to support testing of # behavior however keep in mind this is just to support testing of
# trove components # trove components
swift_stub.with_object('new-container', 'new-object', swift_stub.with_object('new-container', 'new-object',
'updated-object-contents') 'updated-object-contents')
conn.put_object('new-container', 'new-object', conn.put_object('new-container', 'new-object',
'updated-object-contents') 'updated-object-contents')
obj_resp = conn.get_object('new-container', 'new-object') obj_resp = conn.get_object('new-container', 'new-object')
self.assertThat(obj_resp, matchers.Not(matchers.Is(None))) self.assertThat(obj_resp, matchers.Not(matchers.Is(None)))
self.assertThat(len(obj_resp), matchers.Is(2)) self.assertThat(len(obj_resp), matchers.Is(2))
self.assertThat(obj_resp[1], matchers.Is('updated-object-contents')) self.assertThat(obj_resp[1], matchers.Is(
# ensure object count has not increased 'updated-object-contents'))
self.assertThat(len(conn.get_container('new-container')[1]), # ensure object count has not increased
matchers.Is(1)) self.assertThat(len(conn.get_container('new-container')[1]),
matchers.Is(1))
class TestCreateCinderClient(testtools.TestCase): class TestCreateCinderClient(trove_testtools.TestCase):
def setUp(self): def setUp(self):
super(TestCreateCinderClient, self).setUp() super(TestCreateCinderClient, self).setUp()
self.volumev2_public_url = 'http://publicURL/v2' self.volumev2_public_url = 'http://publicURL/v2'
@@ -320,7 +323,7 @@ class TestCreateCinderClient(testtools.TestCase):
client.client.management_url) client.client.management_url)
class TestCreateNovaClient(testtools.TestCase): class TestCreateNovaClient(trove_testtools.TestCase):
def setUp(self): def setUp(self):
super(TestCreateNovaClient, self).setUp() super(TestCreateNovaClient, self).setUp()
self.compute_public_url = 'http://publicURL/v2' self.compute_public_url = 'http://publicURL/v2'
@@ -395,7 +398,7 @@ class TestCreateNovaClient(testtools.TestCase):
client.client.management_url) client.client.management_url)
class TestCreateHeatClient(testtools.TestCase): class TestCreateHeatClient(trove_testtools.TestCase):
def setUp(self): def setUp(self):
super(TestCreateHeatClient, self).setUp() super(TestCreateHeatClient, self).setUp()
self.heat_public_url = 'http://publicURL/v2' self.heat_public_url = 'http://publicURL/v2'
@@ -470,7 +473,7 @@ class TestCreateHeatClient(testtools.TestCase):
client.http_client.endpoint) client.http_client.endpoint)
class TestCreateSwiftClient(testtools.TestCase): class TestCreateSwiftClient(trove_testtools.TestCase):
def setUp(self): def setUp(self):
super(TestCreateSwiftClient, self).setUp() super(TestCreateSwiftClient, self).setUp()
self.swift_public_url = 'http://publicURL/v2' self.swift_public_url = 'http://publicURL/v2'
@@ -536,7 +539,7 @@ class TestCreateSwiftClient(testtools.TestCase):
client.url) client.url)
class TestEndpoints(testtools.TestCase): class TestEndpoints(trove_testtools.TestCase):
""" """
Copied from glance/tests/unit/test_auth.py. Copied from glance/tests/unit/test_auth.py.
""" """

View File

@@ -1,28 +1,25 @@
#Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
#You may obtain a copy of the License at # You may obtain a copy of the License at
# #
#http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
#Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
#limitations under the License. # limitations under the License.
from mock import Mock from mock import Mock
import testtools
import re
from trove.common import exception from trove.common import exception
from trove.common import template from trove.common import template
from trove.common import utils from trove.common import utils
from trove.datastore.models import DatastoreVersion from trove.datastore.models import DatastoreVersion
from trove.tests.unittests import trove_testtools
from trove.tests.unittests.util import util from trove.tests.unittests.util import util
import re
class TemplateTest(testtools.TestCase): class TemplateTest(trove_testtools.TestCase):
def setUp(self): def setUp(self):
super(TemplateTest, self).setUp() super(TemplateTest, self).setUp()
util.init_db() util.init_db()
@@ -106,7 +103,7 @@ class TemplateTest(testtools.TestCase):
self.assertTrue(self._find_in_template(config.render(), "relay_log")) self.assertTrue(self._find_in_template(config.render(), "relay_log"))
class HeatTemplateLoadTest(testtools.TestCase): class HeatTemplateLoadTest(trove_testtools.TestCase):
class FakeTemplate(): class FakeTemplate():
def __init__(self): def __init__(self):

View File

@@ -13,16 +13,14 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
# #
from trove.common import exception
import trove.common.utils as utils
from mock import Mock from mock import Mock
import testtools
from testtools import ExpectedException from testtools import ExpectedException
from trove.common import exception
from trove.common import utils
from trove.tests.unittests import trove_testtools
class TestTroveExecuteWithTimeout(testtools.TestCase): class TestTroveExecuteWithTimeout(trove_testtools.TestCase):
def setUp(self): def setUp(self):
super(TestTroveExecuteWithTimeout, self).setUp() super(TestTroveExecuteWithTimeout, self).setUp()

View File

@@ -13,14 +13,13 @@
# 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 trove.common.wsgi as wsgi from testtools.matchers import Equals, Is, Not
from trove.common import wsgi
from trove.tests.unittests import trove_testtools
import webob import webob
import testtools
from testtools.matchers import Equals, Is, Not
class TestWsgi(trove_testtools.TestCase):
class TestWsgi(testtools.TestCase):
def test_process_request(self): def test_process_request(self):
middleware = wsgi.ContextMiddleware("test_trove") middleware = wsgi.ContextMiddleware("test_trove")
req = webob.BaseRequest({}) req = webob.BaseRequest({})