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:
@@ -13,16 +13,16 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from hashlib import md5
|
||||
from mock import MagicMock, patch
|
||||
import httplib
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import socket
|
||||
import uuid
|
||||
import logging
|
||||
import swiftclient.client as swift_client
|
||||
import swiftclient
|
||||
from hashlib import md5
|
||||
from mock import MagicMock
|
||||
import swiftclient.client as swift_client
|
||||
import uuid
|
||||
|
||||
from swiftclient import client as swift
|
||||
|
||||
@@ -203,7 +203,35 @@ class FakeSwiftConnection(object):
|
||||
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
|
||||
before tests are invoked in "fake" mode. Invoke methods to control
|
||||
@@ -257,6 +285,7 @@ class SwiftClientStub(object):
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
super(SwiftClientStub, self).__init__()
|
||||
self._connection = swift_client.Connection()
|
||||
self._containers = {}
|
||||
self._containers_list = []
|
||||
@@ -296,7 +325,7 @@ class SwiftClientStub(object):
|
||||
'content-type': 'application/json; charset=utf-8',
|
||||
'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'MIINrwYJKoZIhvcNAQcCoIINoDCCDZwCAQExCTAHBgUrDgMCGjCCDIgGCSqGSIb3'
|
||||
u'DQEHAaCCDHkEggx1eyJhY2Nlc3MiOiB7InRva2VuIjogeyJpc3N1ZWRfYXQiOiAi'
|
||||
@@ -305,9 +334,17 @@ class SwiftClientStub(object):
|
||||
u'ImVuYWJsZWQiOiB0cnVlLCAiZGVzY3JpcHRpb24iOiBudWxsLCAibmFtZSI6ICJy'
|
||||
u'ZWRkd2FyZiIsICJpZCI6ICJjN2IwMzg5NzZkZjI0ZDk2YmYxOTgwZjVkYTE3YmQ4'
|
||||
u'OSJ9fSwgInNlcnZpY2VDYXRhbG9nIjogW3siZW5kcG9pbnRzIjogW3siYWRtaW5')
|
||||
)
|
||||
swift_client.Connection.get_account = MagicMock(
|
||||
return_value=account_resp())
|
||||
|
||||
get_auth_patcher = patch.object(
|
||||
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
|
||||
|
||||
def _create_container(self, container_name):
|
||||
@@ -351,7 +388,9 @@ class SwiftClientStub(object):
|
||||
self._objects[container])
|
||||
|
||||
# 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):
|
||||
if args[0] in self._containers:
|
||||
@@ -362,8 +401,10 @@ class SwiftClientStub(object):
|
||||
|
||||
self._create_container(container_name)
|
||||
# return container headers
|
||||
swift_client.Connection.get_container = MagicMock(
|
||||
side_effect=side_effect_func)
|
||||
get_container_patcher = patch.object(
|
||||
swift_client.Connection, 'get_container',
|
||||
MagicMock(side_effect=side_effect_func))
|
||||
self._start_patcher(get_container_patcher)
|
||||
|
||||
return self
|
||||
|
||||
@@ -411,8 +452,10 @@ class SwiftClientStub(object):
|
||||
:param contents: the contents of the object
|
||||
"""
|
||||
|
||||
swift_client.Connection.put_object = MagicMock(
|
||||
return_value=uuid.uuid1())
|
||||
put_object_patcher = patch.object(
|
||||
swift_client.Connection, 'put_object',
|
||||
MagicMock(return_value=uuid.uuid1()))
|
||||
self._start_patcher(put_object_patcher)
|
||||
|
||||
def side_effect_func(*args, **kwargs):
|
||||
if (args[0] in self._containers and
|
||||
@@ -432,8 +475,10 @@ class SwiftClientStub(object):
|
||||
raise swiftclient.ClientException('Resource Not Found',
|
||||
http_status=404)
|
||||
|
||||
swift_client.Connection.get_object = MagicMock(
|
||||
side_effect=side_effect_func)
|
||||
get_object_patcher = patch.object(
|
||||
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._objects[container].append(
|
||||
@@ -471,8 +516,10 @@ class SwiftClientStub(object):
|
||||
else:
|
||||
return None
|
||||
|
||||
swift_client.Connection.delete_object = MagicMock(
|
||||
side_effect=side_effect_func)
|
||||
delete_object_patcher = patch.object(
|
||||
swift_client.Connection, 'delete_object',
|
||||
MagicMock(side_effect=side_effect_func))
|
||||
self._start_patcher(delete_object_patcher)
|
||||
|
||||
self._remove_object(name, self._objects[container])
|
||||
return self
|
||||
|
||||
@@ -13,13 +13,12 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
import trove.common.context as context
|
||||
|
||||
import testtools
|
||||
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):
|
||||
expected_service_catalog = {'key': 'value'}
|
||||
ctx = context.TroveContext(user="test_user_id",
|
||||
|
||||
@@ -11,13 +11,11 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from testtools import TestCase
|
||||
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):
|
||||
error = TroveError("%02d" % 1)
|
||||
|
||||
@@ -15,12 +15,11 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
import testtools
|
||||
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):
|
||||
view = PaginatedDataView("TestType", [], "http://current_page",
|
||||
|
||||
@@ -15,237 +15,240 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
from mock import MagicMock
|
||||
import testtools
|
||||
from testtools import matchers
|
||||
|
||||
from mock import patch, MagicMock
|
||||
from testtools import ExpectedException, matchers
|
||||
from trove.common import cfg
|
||||
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 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(testtools.TestCase):
|
||||
class TestRemote(trove_testtools.TestCase):
|
||||
def setUp(self):
|
||||
super(TestRemote, self).setUp()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestRemote, self).tearDown()
|
||||
|
||||
def test_creation(self):
|
||||
swiftclient.client.Connection.get_auth = MagicMock(return_value=None)
|
||||
conn = swiftclient.client.Connection()
|
||||
self.assertIsNone(conn.get_auth())
|
||||
@patch.object(swiftclient.client.Connection, 'get_auth')
|
||||
def test_creation(self, get_auth_mock):
|
||||
self.assertIsNotNone(swiftclient.client.Connection())
|
||||
|
||||
def test_create_swift_client(self):
|
||||
mock_resp = MagicMock()
|
||||
swiftclient.client.Connection.get_container = MagicMock(
|
||||
return_value=["text", mock_resp])
|
||||
service_catalog = [{'endpoints': [{'region': 'RegionOne',
|
||||
'publicURL': 'example.com'}],
|
||||
'type': 'object-store'}]
|
||||
client = remote.create_swift_client(TroveContext(
|
||||
tenant=uuid.uuid4().hex,
|
||||
service_catalog=service_catalog))
|
||||
headers, container = client.get_container('bob')
|
||||
self.assertIs(headers, "text")
|
||||
self.assertIs(container, mock_resp)
|
||||
with patch.object(swiftclient.client.Connection, 'get_container',
|
||||
MagicMock(return_value=["text", mock_resp])):
|
||||
service_catalog = [{'endpoints': [{'region': 'RegionOne',
|
||||
'publicURL': 'example.com'}],
|
||||
'type': 'object-store'}]
|
||||
client = remote.create_swift_client(TroveContext(
|
||||
tenant=uuid.uuid4().hex,
|
||||
service_catalog=service_catalog))
|
||||
headers, container = client.get_container('bob')
|
||||
self.assertIs(headers, "text")
|
||||
self.assertIs(container, mock_resp)
|
||||
|
||||
def test_empty_account(self):
|
||||
"""
|
||||
this is an account with no containers and no objects
|
||||
"""
|
||||
# setup expectation
|
||||
swift_stub = SwiftClientStub()
|
||||
swift_stub.with_account('123223')
|
||||
# interact
|
||||
conn = swiftclient.client.Connection()
|
||||
account_info = conn.get_account()
|
||||
self.assertThat(account_info, matchers.Not(matchers.Is(None)))
|
||||
self.assertThat(len(account_info), matchers.Is(2))
|
||||
self.assertThat(account_info, matchers.IsInstance(tuple))
|
||||
self.assertThat(account_info[0], matchers.IsInstance(dict))
|
||||
self.assertThat(account_info[0],
|
||||
matchers.KeysEqual('content-length', 'accept-ranges',
|
||||
'x-timestamp', 'x-trans-id', 'date',
|
||||
'x-account-bytes-used',
|
||||
'x-account-container-count',
|
||||
'content-type',
|
||||
'x-account-object-count'))
|
||||
self.assertThat(account_info[1], matchers.IsInstance(list))
|
||||
self.assertThat(len(account_info[1]), matchers.Is(0))
|
||||
with SwiftClientStub() as swift_stub:
|
||||
swift_stub.with_account('123223')
|
||||
# interact
|
||||
conn = swiftclient.client.Connection()
|
||||
account_info = conn.get_account()
|
||||
self.assertThat(account_info, matchers.Not(matchers.Is(None)))
|
||||
self.assertThat(len(account_info), matchers.Is(2))
|
||||
self.assertThat(account_info, matchers.IsInstance(tuple))
|
||||
self.assertThat(account_info[0], matchers.IsInstance(dict))
|
||||
self.assertThat(
|
||||
account_info[0],
|
||||
matchers.KeysEqual('content-length', 'accept-ranges',
|
||||
'x-timestamp', 'x-trans-id', 'date',
|
||||
'x-account-bytes-used',
|
||||
'x-account-container-count',
|
||||
'content-type',
|
||||
'x-account-object-count'))
|
||||
self.assertThat(account_info[1], matchers.IsInstance(list))
|
||||
self.assertThat(len(account_info[1]), matchers.Is(0))
|
||||
|
||||
def test_one_container(self):
|
||||
"""
|
||||
tests to ensure behavior is normal with one container
|
||||
"""
|
||||
# setup expectation
|
||||
swift_stub = SwiftClientStub()
|
||||
swift_stub.with_account('123223')
|
||||
cont_name = 'a-container-name'
|
||||
swift_stub.with_container(cont_name)
|
||||
# interact
|
||||
conn = swiftclient.client.Connection()
|
||||
conn.get_auth()
|
||||
conn.put_container(cont_name)
|
||||
# get headers plus container metadata
|
||||
self.assertThat(len(conn.get_account()), matchers.Is(2))
|
||||
# verify container details
|
||||
account_containers = conn.get_account()[1]
|
||||
self.assertThat(len(account_containers), matchers.Is(1))
|
||||
self.assertThat(account_containers[0],
|
||||
matchers.KeysEqual('count', 'bytes', 'name'))
|
||||
self.assertThat(account_containers[0]['name'], matchers.Is(cont_name))
|
||||
# get container details
|
||||
cont_info = conn.get_container(cont_name)
|
||||
self.assertIsNotNone(cont_info)
|
||||
self.assertThat(cont_info[0], matchers.KeysEqual('content-length',
|
||||
'x-container-object-count', 'accept-ranges',
|
||||
'x-container-bytes-used', 'x-timestamp',
|
||||
'x-trans-id', 'date', 'content-type'))
|
||||
self.assertThat(len(cont_info[1]), matchers.Equals(0))
|
||||
# remove container
|
||||
swift_stub.without_container(cont_name)
|
||||
with testtools.ExpectedException(swiftclient.ClientException):
|
||||
conn.get_container(cont_name)
|
||||
# ensure there are no more containers in account
|
||||
self.assertThat(len(conn.get_account()[1]), matchers.Is(0))
|
||||
with SwiftClientStub() as swift_stub:
|
||||
swift_stub.with_account('123223')
|
||||
cont_name = 'a-container-name'
|
||||
swift_stub.with_container(cont_name)
|
||||
# interact
|
||||
conn = swiftclient.client.Connection()
|
||||
conn.get_auth()
|
||||
conn.put_container(cont_name)
|
||||
# get headers plus container metadata
|
||||
self.assertThat(len(conn.get_account()), matchers.Is(2))
|
||||
# verify container details
|
||||
account_containers = conn.get_account()[1]
|
||||
self.assertThat(len(account_containers), matchers.Is(1))
|
||||
self.assertThat(account_containers[0],
|
||||
matchers.KeysEqual('count', 'bytes', 'name'))
|
||||
self.assertThat(account_containers[0]['name'],
|
||||
matchers.Is(cont_name))
|
||||
# get container details
|
||||
cont_info = conn.get_container(cont_name)
|
||||
self.assertIsNotNone(cont_info)
|
||||
self.assertThat(cont_info[0], matchers.KeysEqual('content-length',
|
||||
'x-container-object-count', 'accept-ranges',
|
||||
'x-container-bytes-used', 'x-timestamp',
|
||||
'x-trans-id', 'date', 'content-type'))
|
||||
self.assertThat(len(cont_info[1]), matchers.Equals(0))
|
||||
# remove container
|
||||
swift_stub.without_container(cont_name)
|
||||
with ExpectedException(swiftclient.ClientException):
|
||||
conn.get_container(cont_name)
|
||||
# ensure there are no more containers in account
|
||||
self.assertThat(len(conn.get_account()[1]), matchers.Is(0))
|
||||
|
||||
def test_one_object(self):
|
||||
swift_stub = SwiftClientStub()
|
||||
swift_stub.with_account('123223')
|
||||
swift_stub.with_container('bob')
|
||||
swift_stub.with_object('bob', 'test', 'test_contents')
|
||||
# create connection
|
||||
conn = swiftclient.client.Connection()
|
||||
# test container lightly
|
||||
cont_info = conn.get_container('bob')
|
||||
self.assertIsNotNone(cont_info)
|
||||
self.assertThat(cont_info[0],
|
||||
matchers.KeysEqual('content-length',
|
||||
'x-container-object-count',
|
||||
'accept-ranges',
|
||||
'x-container-bytes-used',
|
||||
'x-timestamp', 'x-trans-id', 'date',
|
||||
'content-type'))
|
||||
cont_objects = cont_info[1]
|
||||
self.assertThat(len(cont_objects), matchers.Equals(1))
|
||||
obj_1 = cont_objects[0]
|
||||
self.assertThat(obj_1, matchers.Equals(
|
||||
{'bytes': 13, 'last_modified': '2013-03-15T22:10:49.361950',
|
||||
'hash': 'ccc55aefbf92aa66f42b638802c5e7f6', 'name': 'test',
|
||||
'content_type': 'application/octet-stream',
|
||||
'contents': 'test_contents'}))
|
||||
# test object api - not much to do here
|
||||
self.assertThat(conn.get_object('bob', 'test')[1],
|
||||
matchers.Is('test_contents'))
|
||||
with SwiftClientStub() as swift_stub:
|
||||
swift_stub.with_account('123223')
|
||||
swift_stub.with_container('bob')
|
||||
swift_stub.with_object('bob', 'test', 'test_contents')
|
||||
# create connection
|
||||
conn = swiftclient.client.Connection()
|
||||
# test container lightly
|
||||
cont_info = conn.get_container('bob')
|
||||
self.assertIsNotNone(cont_info)
|
||||
self.assertThat(cont_info[0],
|
||||
matchers.KeysEqual('content-length',
|
||||
'x-container-object-count',
|
||||
'accept-ranges',
|
||||
'x-container-bytes-used',
|
||||
'x-timestamp',
|
||||
'x-trans-id',
|
||||
'date',
|
||||
'content-type'))
|
||||
cont_objects = cont_info[1]
|
||||
self.assertThat(len(cont_objects), matchers.Equals(1))
|
||||
obj_1 = cont_objects[0]
|
||||
self.assertThat(obj_1, matchers.Equals(
|
||||
{'bytes': 13, 'last_modified': '2013-03-15T22:10:49.361950',
|
||||
'hash': 'ccc55aefbf92aa66f42b638802c5e7f6', 'name': 'test',
|
||||
'content_type': 'application/octet-stream',
|
||||
'contents': '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
|
||||
swift_stub.without_object('bob', 'test')
|
||||
# interact
|
||||
with testtools.ExpectedException(swiftclient.ClientException):
|
||||
conn.delete_object('bob', 'test')
|
||||
self.assertThat(len(conn.get_container('bob')[1]), matchers.Is(0))
|
||||
# test remove object
|
||||
swift_stub.without_object('bob', 'test')
|
||||
# interact
|
||||
with ExpectedException(swiftclient.ClientException):
|
||||
conn.delete_object('bob', 'test')
|
||||
self.assertThat(len(conn.get_container('bob')[1]), matchers.Is(0))
|
||||
|
||||
def test_two_objects(self):
|
||||
swift_stub = SwiftClientStub()
|
||||
swift_stub.with_account('123223')
|
||||
swift_stub.with_container('bob')
|
||||
swift_stub.with_container('bob2')
|
||||
swift_stub.with_object('bob', 'test', 'test_contents')
|
||||
swift_stub.with_object('bob', 'test2', 'test_contents2')
|
||||
with SwiftClientStub() as swift_stub:
|
||||
swift_stub.with_account('123223')
|
||||
swift_stub.with_container('bob')
|
||||
swift_stub.with_container('bob2')
|
||||
swift_stub.with_object('bob', 'test', 'test_contents')
|
||||
swift_stub.with_object('bob', 'test2', 'test_contents2')
|
||||
|
||||
conn = swiftclient.client.Connection()
|
||||
conn = swiftclient.client.Connection()
|
||||
|
||||
self.assertIs(len(conn.get_account()), 2)
|
||||
cont_info = conn.get_container('bob')
|
||||
self.assertIsNotNone(cont_info)
|
||||
self.assertThat(cont_info[0],
|
||||
matchers.KeysEqual('content-length',
|
||||
'x-container-object-count',
|
||||
'accept-ranges',
|
||||
'x-container-bytes-used',
|
||||
'x-timestamp', 'x-trans-id', 'date',
|
||||
'content-type'))
|
||||
self.assertThat(len(cont_info[1]), matchers.Equals(2))
|
||||
self.assertThat(cont_info[1][0], matchers.Equals(
|
||||
{'bytes': 13, 'last_modified': '2013-03-15T22:10:49.361950',
|
||||
'hash': 'ccc55aefbf92aa66f42b638802c5e7f6', 'name': 'test',
|
||||
'content_type': 'application/octet-stream',
|
||||
'contents': 'test_contents'}))
|
||||
self.assertThat(conn.get_object('bob', 'test')[1],
|
||||
matchers.Is('test_contents'))
|
||||
self.assertThat(conn.get_object('bob', 'test2')[1],
|
||||
matchers.Is('test_contents2'))
|
||||
self.assertIs(len(conn.get_account()), 2)
|
||||
cont_info = conn.get_container('bob')
|
||||
self.assertIsNotNone(cont_info)
|
||||
self.assertThat(cont_info[0],
|
||||
matchers.KeysEqual('content-length',
|
||||
'x-container-object-count',
|
||||
'accept-ranges',
|
||||
'x-container-bytes-used',
|
||||
'x-timestamp',
|
||||
'x-trans-id',
|
||||
'date',
|
||||
'content-type'))
|
||||
self.assertThat(len(cont_info[1]), matchers.Equals(2))
|
||||
self.assertThat(cont_info[1][0], matchers.Equals(
|
||||
{'bytes': 13, 'last_modified': '2013-03-15T22:10:49.361950',
|
||||
'hash': 'ccc55aefbf92aa66f42b638802c5e7f6', 'name': 'test',
|
||||
'content_type': 'application/octet-stream',
|
||||
'contents': 'test_contents'}))
|
||||
self.assertThat(conn.get_object('bob', 'test')[1],
|
||||
matchers.Is('test_contents'))
|
||||
self.assertThat(conn.get_object('bob', 'test2')[1],
|
||||
matchers.Is('test_contents2'))
|
||||
|
||||
swift_stub.without_object('bob', 'test')
|
||||
with testtools.ExpectedException(swiftclient.ClientException):
|
||||
conn.delete_object('bob', 'test')
|
||||
self.assertThat(len(conn.get_container('bob')[1]), matchers.Is(1))
|
||||
swift_stub.without_object('bob', 'test')
|
||||
with ExpectedException(swiftclient.ClientException):
|
||||
conn.delete_object('bob', 'test')
|
||||
self.assertThat(len(conn.get_container('bob')[1]), matchers.Is(1))
|
||||
|
||||
swift_stub.without_container('bob')
|
||||
with testtools.ExpectedException(swiftclient.ClientException):
|
||||
conn.get_container('bob')
|
||||
swift_stub.without_container('bob')
|
||||
with ExpectedException(swiftclient.ClientException):
|
||||
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):
|
||||
"""
|
||||
when a container does not exist and is accessed then a 404 is returned
|
||||
"""
|
||||
from trove.tests.fakes.swift import SwiftClientStub
|
||||
|
||||
swift_stub = SwiftClientStub()
|
||||
swift_stub.with_account('123223')
|
||||
swift_stub.with_container('existing')
|
||||
with SwiftClientStub() as swift_stub:
|
||||
swift_stub.with_account('123223')
|
||||
swift_stub.with_container('existing')
|
||||
|
||||
conn = swiftclient.client.Connection()
|
||||
conn = swiftclient.client.Connection()
|
||||
|
||||
with testtools.ExpectedException(swiftclient.ClientException):
|
||||
conn.get_container('nonexisting')
|
||||
with ExpectedException(swiftclient.ClientException):
|
||||
conn.get_container('nonexisting')
|
||||
|
||||
def test_replace_object(self):
|
||||
"""
|
||||
Test to ensure that if an object is updated the container object
|
||||
count is the same and the contents of the object are updated
|
||||
"""
|
||||
swift_stub = SwiftClientStub()
|
||||
swift_stub.with_account('1223df2')
|
||||
swift_stub.with_container('new-container')
|
||||
swift_stub.with_object('new-container', 'new-object',
|
||||
'new-object-contents')
|
||||
with SwiftClientStub() as swift_stub:
|
||||
swift_stub.with_account('1223df2')
|
||||
swift_stub.with_container('new-container')
|
||||
swift_stub.with_object('new-container', 'new-object',
|
||||
'new-object-contents')
|
||||
|
||||
conn = swiftclient.client.Connection()
|
||||
conn = swiftclient.client.Connection()
|
||||
|
||||
conn.put_object('new-container', 'new-object', 'new-object-contents')
|
||||
obj_resp = conn.get_object('new-container', 'new-object')
|
||||
self.assertThat(obj_resp, matchers.Not(matchers.Is(None)))
|
||||
self.assertThat(len(obj_resp), matchers.Is(2))
|
||||
self.assertThat(obj_resp[1], matchers.Is('new-object-contents'))
|
||||
conn.put_object('new-container', 'new-object',
|
||||
'new-object-contents')
|
||||
obj_resp = conn.get_object('new-container', 'new-object')
|
||||
self.assertThat(obj_resp, matchers.Not(matchers.Is(None)))
|
||||
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
|
||||
# behavior however keep in mind this is just to support testing of
|
||||
# trove components
|
||||
swift_stub.with_object('new-container', 'new-object',
|
||||
'updated-object-contents')
|
||||
# set expected behavior - trivial here since it is the intended
|
||||
# behavior however keep in mind this is just to support testing of
|
||||
# trove components
|
||||
swift_stub.with_object('new-container', 'new-object',
|
||||
'updated-object-contents')
|
||||
|
||||
conn.put_object('new-container', 'new-object',
|
||||
'updated-object-contents')
|
||||
obj_resp = conn.get_object('new-container', 'new-object')
|
||||
self.assertThat(obj_resp, matchers.Not(matchers.Is(None)))
|
||||
self.assertThat(len(obj_resp), matchers.Is(2))
|
||||
self.assertThat(obj_resp[1], matchers.Is('updated-object-contents'))
|
||||
# ensure object count has not increased
|
||||
self.assertThat(len(conn.get_container('new-container')[1]),
|
||||
matchers.Is(1))
|
||||
conn.put_object('new-container', 'new-object',
|
||||
'updated-object-contents')
|
||||
obj_resp = conn.get_object('new-container', 'new-object')
|
||||
self.assertThat(obj_resp, matchers.Not(matchers.Is(None)))
|
||||
self.assertThat(len(obj_resp), matchers.Is(2))
|
||||
self.assertThat(obj_resp[1], matchers.Is(
|
||||
'updated-object-contents'))
|
||||
# ensure object count has not increased
|
||||
self.assertThat(len(conn.get_container('new-container')[1]),
|
||||
matchers.Is(1))
|
||||
|
||||
|
||||
class TestCreateCinderClient(testtools.TestCase):
|
||||
class TestCreateCinderClient(trove_testtools.TestCase):
|
||||
def setUp(self):
|
||||
super(TestCreateCinderClient, self).setUp()
|
||||
self.volumev2_public_url = 'http://publicURL/v2'
|
||||
@@ -320,7 +323,7 @@ class TestCreateCinderClient(testtools.TestCase):
|
||||
client.client.management_url)
|
||||
|
||||
|
||||
class TestCreateNovaClient(testtools.TestCase):
|
||||
class TestCreateNovaClient(trove_testtools.TestCase):
|
||||
def setUp(self):
|
||||
super(TestCreateNovaClient, self).setUp()
|
||||
self.compute_public_url = 'http://publicURL/v2'
|
||||
@@ -395,7 +398,7 @@ class TestCreateNovaClient(testtools.TestCase):
|
||||
client.client.management_url)
|
||||
|
||||
|
||||
class TestCreateHeatClient(testtools.TestCase):
|
||||
class TestCreateHeatClient(trove_testtools.TestCase):
|
||||
def setUp(self):
|
||||
super(TestCreateHeatClient, self).setUp()
|
||||
self.heat_public_url = 'http://publicURL/v2'
|
||||
@@ -470,7 +473,7 @@ class TestCreateHeatClient(testtools.TestCase):
|
||||
client.http_client.endpoint)
|
||||
|
||||
|
||||
class TestCreateSwiftClient(testtools.TestCase):
|
||||
class TestCreateSwiftClient(trove_testtools.TestCase):
|
||||
def setUp(self):
|
||||
super(TestCreateSwiftClient, self).setUp()
|
||||
self.swift_public_url = 'http://publicURL/v2'
|
||||
@@ -536,7 +539,7 @@ class TestCreateSwiftClient(testtools.TestCase):
|
||||
client.url)
|
||||
|
||||
|
||||
class TestEndpoints(testtools.TestCase):
|
||||
class TestEndpoints(trove_testtools.TestCase):
|
||||
"""
|
||||
Copied from glance/tests/unit/test_auth.py.
|
||||
"""
|
||||
|
||||
@@ -1,28 +1,25 @@
|
||||
#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
|
||||
# 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
|
||||
# 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.
|
||||
|
||||
|
||||
# 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.
|
||||
from mock import Mock
|
||||
import testtools
|
||||
import re
|
||||
|
||||
from trove.common import exception
|
||||
from trove.common import template
|
||||
from trove.common import utils
|
||||
from trove.datastore.models import DatastoreVersion
|
||||
from trove.tests.unittests import trove_testtools
|
||||
from trove.tests.unittests.util import util
|
||||
import re
|
||||
|
||||
|
||||
class TemplateTest(testtools.TestCase):
|
||||
class TemplateTest(trove_testtools.TestCase):
|
||||
def setUp(self):
|
||||
super(TemplateTest, self).setUp()
|
||||
util.init_db()
|
||||
@@ -106,7 +103,7 @@ class TemplateTest(testtools.TestCase):
|
||||
self.assertTrue(self._find_in_template(config.render(), "relay_log"))
|
||||
|
||||
|
||||
class HeatTemplateLoadTest(testtools.TestCase):
|
||||
class HeatTemplateLoadTest(trove_testtools.TestCase):
|
||||
|
||||
class FakeTemplate():
|
||||
def __init__(self):
|
||||
|
||||
@@ -13,16 +13,14 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
from trove.common import exception
|
||||
import trove.common.utils as utils
|
||||
|
||||
from mock import Mock
|
||||
import testtools
|
||||
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):
|
||||
super(TestTroveExecuteWithTimeout, self).setUp()
|
||||
|
||||
@@ -13,14 +13,13 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# 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 testtools
|
||||
from testtools.matchers import Equals, Is, Not
|
||||
|
||||
|
||||
class TestWsgi(testtools.TestCase):
|
||||
class TestWsgi(trove_testtools.TestCase):
|
||||
def test_process_request(self):
|
||||
middleware = wsgi.ContextMiddleware("test_trove")
|
||||
req = webob.BaseRequest({})
|
||||
|
||||
Reference in New Issue
Block a user