Merge "Remove use of mox/mox3"

This commit is contained in:
Zuul 2018-03-06 14:10:54 +00:00 committed by Gerrit Code Review
commit 14d12a741f
2 changed files with 26 additions and 61 deletions

View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from mox3 import mox
import mock
from six.moves import http_client
import testtools
@ -26,63 +26,40 @@ class TestClient(testtools.TestCase):
def setUp(self):
super(TestClient, self).setUp()
self.mock = mox.Mox()
self.mock.StubOutWithMock(http_client.HTTPConnection, 'request')
self.mock.StubOutWithMock(http_client.HTTPConnection, 'getresponse')
self.endpoint = 'example.com'
self.client = client.BaseClient(self.endpoint, port=9191,
auth_token=u'abc123')
def tearDown(self):
super(TestClient, self).tearDown()
self.mock.UnsetStubs()
def test_make_auth_plugin(self):
creds = {'strategy': 'keystone'}
insecure = False
configure_via_auth = True
self.mock.StubOutWithMock(auth, 'get_plugin_from_strategy')
auth.get_plugin_from_strategy('keystone', creds, insecure,
configure_via_auth)
self.mock.ReplayAll()
self.client.make_auth_plugin(creds, insecure)
self.mock.VerifyAll()
def test_http_encoding_headers(self):
http_client.HTTPConnection.request(
mox.IgnoreArg(),
mox.IgnoreArg(),
mox.IgnoreArg(),
mox.IgnoreArg())
with mock.patch.object(auth, 'get_plugin_from_strategy'):
self.client.make_auth_plugin(creds, insecure)
@mock.patch.object(http_client.HTTPConnection, "getresponse")
@mock.patch.object(http_client.HTTPConnection, "request")
def test_http_encoding_headers(self, _mock_req, _mock_resp):
# Lets fake the response
# returned by http_client
fake = utils.FakeHTTPResponse(data=b"Ok")
http_client.HTTPConnection.getresponse().AndReturn(fake)
self.mock.ReplayAll()
_mock_resp.return_value = fake
headers = {"test": u'ni\xf1o'}
resp = self.client.do_request('GET', '/v1/images/detail',
headers=headers)
self.assertEqual(fake, resp)
def test_http_encoding_params(self):
http_client.HTTPConnection.request(
mox.IgnoreArg(),
mox.IgnoreArg(),
mox.IgnoreArg(),
mox.IgnoreArg())
@mock.patch.object(http_client.HTTPConnection, "getresponse")
@mock.patch.object(http_client.HTTPConnection, "request")
def test_http_encoding_params(self, _mock_req, _mock_resp):
# Lets fake the response
# returned by http_client
fake = utils.FakeHTTPResponse(data=b"Ok")
http_client.HTTPConnection.getresponse().AndReturn(fake)
self.mock.ReplayAll()
_mock_resp.return_value = fake
params = {"test": u'ni\xf1o'}
resp = self.client.do_request('GET', '/v1/images/detail',

View File

@ -18,7 +18,6 @@ import uuid
import glance_store
import mock
from mock import patch
from mox3 import mox
from oslo_config import cfg
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
from six.moves import range
@ -39,10 +38,8 @@ class TestScrubber(test_utils.BaseTestCase):
self.config(group='glance_store', default_store='file',
filesystem_store_datadir=self.test_dir)
glance_store.create_stores()
self.mox = mox.Mox()
def tearDown(self):
self.mox.UnsetStubs()
# These globals impact state outside of this test class, kill them.
scrubber._file_queue = None
scrubber._db_queue = None
@ -52,13 +49,10 @@ class TestScrubber(test_utils.BaseTestCase):
uri = 'file://some/path/%s' % uuid.uuid4()
id = 'helloworldid'
scrub = scrubber.Scrubber(glance_store)
self.mox.StubOutWithMock(glance_store, "delete_from_backend")
glance_store.delete_from_backend(
uri,
mox.IgnoreArg()).AndRaise(ex)
self.mox.ReplayAll()
scrub._scrub_image(id, [(id, '-', uri)])
self.mox.VerifyAll()
with patch.object(glance_store,
"delete_from_backend") as _mock_delete:
_mock_delete.side_effect = ex
scrub._scrub_image(id, [(id, '-', uri)])
@mock.patch.object(db_api, "image_get")
def test_store_delete_successful(self, mock_image_get):
@ -66,11 +60,9 @@ class TestScrubber(test_utils.BaseTestCase):
id = 'helloworldid'
scrub = scrubber.Scrubber(glance_store)
self.mox.StubOutWithMock(glance_store, "delete_from_backend")
glance_store.delete_from_backend(uri, mox.IgnoreArg()).AndReturn('')
self.mox.ReplayAll()
scrub._scrub_image(id, [(id, '-', uri)])
self.mox.VerifyAll()
with patch.object(glance_store,
"delete_from_backend"):
scrub._scrub_image(id, [(id, '-', uri)])
@mock.patch.object(db_api, "image_get")
def test_store_delete_store_exceptions(self, mock_image_get):
@ -83,13 +75,10 @@ class TestScrubber(test_utils.BaseTestCase):
ex = glance_store.GlanceStoreException()
scrub = scrubber.Scrubber(glance_store)
self.mox.StubOutWithMock(glance_store, "delete_from_backend")
glance_store.delete_from_backend(
uri,
mox.IgnoreArg()).AndRaise(ex)
self.mox.ReplayAll()
scrub._scrub_image(id, [(id, '-', uri)])
self.mox.VerifyAll()
with patch.object(glance_store,
"delete_from_backend") as _mock_delete:
_mock_delete.side_effect = ex
scrub._scrub_image(id, [(id, '-', uri)])
@mock.patch.object(db_api, "image_get")
def test_store_delete_notfound_exception(self, mock_image_get):
@ -100,11 +89,10 @@ class TestScrubber(test_utils.BaseTestCase):
ex = glance_store.NotFound(message='random')
scrub = scrubber.Scrubber(glance_store)
self.mox.StubOutWithMock(glance_store, "delete_from_backend")
glance_store.delete_from_backend(uri, mox.IgnoreArg()).AndRaise(ex)
self.mox.ReplayAll()
scrub._scrub_image(id, [(id, '-', uri)])
self.mox.VerifyAll()
with patch.object(glance_store,
"delete_from_backend") as _mock_delete:
_mock_delete.side_effect = ex
scrub._scrub_image(id, [(id, '-', uri)])
def test_scrubber_exits(self):
# Checks for Scrubber exits when it is not able to fetch jobs from