Merge "Remove use of mox/mox3"
This commit is contained in:
commit
14d12a741f
|
@ -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',
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue