Use mock rather than mox

Switch to mock rather than mox. We should pick one or the other
mocking library, and mock is preferred.

Change-Id: I86ad9638da2f53189fbaea3fd9476356eb0c7ff5
This commit is contained in:
Brant Knudson
2015-06-13 08:17:20 -05:00
parent 75d4b16eaf
commit f249332bb6
3 changed files with 42 additions and 34 deletions

View File

@@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslotest import mockpatch
from keystoneclient import base
from keystoneclient.tests.unit import utils
from keystoneclient.v2_0 import client
@@ -40,9 +42,9 @@ class BaseTest(utils.TestCase):
auth_url='http://127.0.0.1:5000',
endpoint='http://127.0.0.1:5000')
self.client._adapter.get = self.mox.CreateMockAnything()
self.client._adapter.get('/OS-KSADM/roles/1').AndRaise(AttributeError)
self.mox.ReplayAll()
self.useFixture(mockpatch.PatchObject(
self.client._adapter, 'get', side_effect=AttributeError,
autospec=True))
f = roles.Role(self.client.roles, {'id': 1, 'name': 'Member'})
self.assertEqual(f.name, 'Member')
@@ -95,67 +97,78 @@ class ManagerTest(utils.TestCase):
self.assertEqual(self.mgr.api, self.client)
def test_get(self):
self.client.get = self.mox.CreateMockAnything()
self.client.get(self.url).AndReturn((None, self.body))
self.mox.ReplayAll()
get_mock = self.useFixture(mockpatch.PatchObject(
self.client, 'get', autospec=True, return_value=(None, self.body))
).mock
rsrc = self.mgr._get(self.url, "hello")
get_mock.assert_called_once_with(self.url)
self.assertEqual(rsrc.hi, 1)
def test_post(self):
self.client.post = self.mox.CreateMockAnything()
self.client.post(self.url, body=self.body).AndReturn((None, self.body))
self.client.post(self.url, body=self.body).AndReturn((None, self.body))
self.mox.ReplayAll()
post_mock = self.useFixture(mockpatch.PatchObject(
self.client, 'post', autospec=True, return_value=(None, self.body))
).mock
rsrc = self.mgr._post(self.url, self.body, "hello")
post_mock.assert_called_once_with(self.url, body=self.body)
self.assertEqual(rsrc.hi, 1)
post_mock.reset_mock()
rsrc = self.mgr._post(self.url, self.body, "hello", return_raw=True)
post_mock.assert_called_once_with(self.url, body=self.body)
self.assertEqual(rsrc["hi"], 1)
def test_put(self):
self.client.put = self.mox.CreateMockAnything()
self.client.put(self.url, body=self.body).AndReturn((None, self.body))
self.client.put(self.url, body=self.body).AndReturn((None, self.body))
self.mox.ReplayAll()
put_mock = self.useFixture(mockpatch.PatchObject(
self.client, 'put', autospec=True, return_value=(None, self.body))
).mock
rsrc = self.mgr._put(self.url, self.body, "hello")
put_mock.assert_called_once_with(self.url, body=self.body)
self.assertEqual(rsrc.hi, 1)
put_mock.reset_mock()
rsrc = self.mgr._put(self.url, self.body)
put_mock.assert_called_once_with(self.url, body=self.body)
self.assertEqual(rsrc.hello["hi"], 1)
def test_patch(self):
self.client.patch = self.mox.CreateMockAnything()
self.client.patch(self.url, body=self.body).AndReturn(
(None, self.body))
self.client.patch(self.url, body=self.body).AndReturn(
(None, self.body))
self.mox.ReplayAll()
patch_mock = self.useFixture(mockpatch.PatchObject(
self.client, 'patch', autospec=True,
return_value=(None, self.body))
).mock
rsrc = self.mgr._patch(self.url, self.body, "hello")
patch_mock.assert_called_once_with(self.url, body=self.body)
self.assertEqual(rsrc.hi, 1)
patch_mock.reset_mock()
rsrc = self.mgr._patch(self.url, self.body)
patch_mock.assert_called_once_with(self.url, body=self.body)
self.assertEqual(rsrc.hello["hi"], 1)
def test_update(self):
self.client.patch = self.mox.CreateMockAnything()
self.client.put = self.mox.CreateMockAnything()
self.client.patch(
self.url, body=self.body, management=False).AndReturn((None,
self.body))
self.client.put(self.url, body=None, management=True).AndReturn(
(None, self.body))
self.mox.ReplayAll()
patch_mock = self.useFixture(mockpatch.PatchObject(
self.client, 'patch', autospec=True,
return_value=(None, self.body))
).mock
put_mock = self.useFixture(mockpatch.PatchObject(
self.client, 'put', autospec=True, return_value=(None, self.body))
).mock
rsrc = self.mgr._update(
self.url, body=self.body, response_key="hello", method="PATCH",
management=False)
patch_mock.assert_called_once_with(
self.url, management=False, body=self.body)
self.assertEqual(rsrc.hi, 1)
rsrc = self.mgr._update(
self.url, body=None, response_key="hello", method="PUT",
management=True)
put_mock.assert_called_once_with(self.url, management=True, body=None)
self.assertEqual(rsrc.hi, 1)

View File

@@ -17,7 +17,6 @@ import uuid
import fixtures
import mock
from mox3 import mox
from oslo_serialization import jsonutils
import requests
from requests_mock.contrib import fixture
@@ -43,7 +42,6 @@ class TestCase(testtools.TestCase):
def setUp(self):
super(TestCase, self).setUp()
self.mox = mox.Mox()
self.logger = self.useFixture(fixtures.FakeLogger(level=logging.DEBUG))
self.time_patcher = mock.patch.object(time, 'time', lambda: 1234)
self.time_patcher.start()
@@ -52,8 +50,6 @@ class TestCase(testtools.TestCase):
def tearDown(self):
self.time_patcher.stop()
self.mox.UnsetStubs()
self.mox.VerifyAll()
super(TestCase, self).tearDown()
def stub_url(self, method, parts=None, base_url=None, json=None, **kwargs):

View File

@@ -10,7 +10,6 @@ fixtures>=0.3.14
keyring>=2.1,!=3.3
lxml>=2.3
mock>=1.0
mox3>=0.7.0
oauthlib>=0.6
oslosphinx>=2.5.0 # Apache-2.0
oslotest>=1.5.1 # Apache-2.0