diff options
author | Jenkins <jenkins@review.openstack.org> | 2014-03-28 00:26:48 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2014-03-28 00:26:48 +0000 |
commit | aac9668a992c730eb7b0b21831d34214399c58f3 (patch) | |
tree | 69037d9f82c75feeeed408e23c8aedaf1dc9c9c9 | |
parent | 27375855e86da65ba2c8452ad44f59f8fb352859 (diff) | |
parent | d6a597585124abd0ef2ecbca065e8752bcf9dd3a (diff) | |
download | ironic-aac9668a992c730eb7b0b21831d34214399c58f3.tar.gz |
Merge "Replace fixtures with mock in test_keystone.py"
-rw-r--r-- | ironic/tests/test_keystone.py | 78 |
1 files changed, 18 insertions, 60 deletions
diff --git a/ironic/tests/test_keystone.py b/ironic/tests/test_keystone.py index 25f6a7079..3bc31699c 100644 --- a/ironic/tests/test_keystone.py +++ b/ironic/tests/test_keystone.py @@ -12,7 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -import fixtures from keystoneclient import exceptions as ksexception import mock @@ -34,8 +33,6 @@ class FakeClient: return True -# TODO(lucasagomes): Replace fixtures with mock for some of the tests in -# the KeystoneTestCase class class KeystoneTestCase(base.TestCase): def setUp(self): @@ -48,71 +45,32 @@ class KeystoneTestCase(base.TestCase): def test_failure_authorization(self): self.assertRaises(exception.CatalogFailure, keystone.get_service_url) - def test_get_url(self): + @mock.patch.object(FakeCatalog, 'url_for') + @mock.patch('keystoneclient.v2_0.client.Client') + def test_get_url(self, mock_ks, mock_uf): fake_url = 'http://127.0.0.1:6385' - - class _fake_catalog: - def url_for(self, **kwargs): - return fake_url - - class _fake_client: - def __init__(self, **kwargs): - self.service_catalog = _fake_catalog() - - def has_service_catalog(self): - return True - - self.useFixture(fixtures.MonkeyPatch( - 'keystoneclient.v2_0.client.Client', - _fake_client)) - + mock_uf.return_value = fake_url + mock_ks.return_value = FakeClient() res = keystone.get_service_url() self.assertEqual(fake_url, res) - def test_url_not_found(self): - - class _fake_catalog: - def url_for(self, **kwargs): - raise ksexception.EndpointNotFound - - class _fake_client: - def __init__(self, **kwargs): - self.service_catalog = _fake_catalog() - - def has_service_catalog(self): - return True - - self.useFixture(fixtures.MonkeyPatch( - 'keystoneclient.v2_0.client.Client', - _fake_client)) - + @mock.patch.object(FakeCatalog, 'url_for') + @mock.patch('keystoneclient.v2_0.client.Client') + def test_url_not_found(self, mock_ks, mock_uf): + mock_uf.side_effect = ksexception.EndpointNotFound + mock_ks.return_value = FakeClient() self.assertRaises(exception.CatalogNotFound, keystone.get_service_url) - def test_no_catalog(self): - - class _fake_client: - def __init__(self, **kwargs): - pass - - def has_service_catalog(self): - return False - - self.useFixture(fixtures.MonkeyPatch( - 'keystoneclient.v2_0.client.Client', - _fake_client)) - + @mock.patch.object(FakeClient, 'has_service_catalog') + @mock.patch('keystoneclient.v2_0.client.Client') + def test_no_catalog(self, mock_ks, mock_hsc): + mock_hsc.return_value = False + mock_ks.return_value = FakeClient() self.assertRaises(exception.CatalogFailure, keystone.get_service_url) - def test_unauthorized(self): - - class _fake_client: - def __init__(self, **kwargs): - raise ksexception.Unauthorized - - self.useFixture(fixtures.MonkeyPatch( - 'keystoneclient.v2_0.client.Client', - _fake_client)) - + @mock.patch('keystoneclient.v2_0.client.Client') + def test_unauthorized(self, mock_ks): + mock_ks.side_effect = ksexception.Unauthorized self.assertRaises(exception.CatalogUnauthorized, keystone.get_service_url) |