From d04007efd236f9cacf381b622b19cdad7e4529e8 Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Mon, 17 Oct 2011 14:49:28 -0400 Subject: Refactoring nova.tests.api.openstack.test_flavors Change-Id: I668e7b7fb379a99edee8a8f5ca948a32c0ba9896 --- nova/api/openstack/flavors.py | 2 +- nova/tests/api/openstack/test_flavors.py | 68 ++++++++++++-------------------- 2 files changed, 26 insertions(+), 44 deletions(-) (limited to 'nova') diff --git a/nova/api/openstack/flavors.py b/nova/api/openstack/flavors.py index 0727ee258..f9fe0f804 100644 --- a/nova/api/openstack/flavors.py +++ b/nova/api/openstack/flavors.py @@ -69,7 +69,7 @@ class Controller(object): ctxt = req.environ['nova.context'] flavor = db.api.instance_type_get_by_flavor_id(ctxt, id) except exception.NotFound: - return webob.exc.HTTPNotFound() + raise webob.exc.HTTPNotFound() builder = self._get_view_builder(req) values = builder.build(flavor, is_detail=True) diff --git a/nova/tests/api/openstack/test_flavors.py b/nova/tests/api/openstack/test_flavors.py index 6cea114b1..bc347e803 100644 --- a/nova/tests/api/openstack/test_flavors.py +++ b/nova/tests/api/openstack/test_flavors.py @@ -85,6 +85,8 @@ class FlavorsTest(test.TestCase): self.stubs.Set(nova.db.api, "instance_type_get_by_flavor_id", fake_instance_type_get_by_flavor_id) + self.controller = flavors.Controller() + def tearDown(self): self.stubs.UnsetAll() super(FlavorsTest, self).tearDown() @@ -92,15 +94,13 @@ class FlavorsTest(test.TestCase): def test_get_flavor_by_invalid_id(self): self.stubs.Set(nova.db.api, "instance_type_get_by_flavor_id", return_instance_type_not_found) - req = webob.Request.blank('/v1.1/fake/flavors/asdf') - res = req.get_response(fakes.wsgi_app()) - self.assertEqual(res.status_int, 404) + req = fakes.HTTPRequest.blank('/v1.1/fake/flavors/asdf') + self.assertRaises(webob.exc.HTTPNotFound, + self.controller.show, req, 'asdf') def test_get_flavor_by_id(self): - req = webob.Request.blank('/v1.1/fake/flavors/1') - res = req.get_response(fakes.wsgi_app()) - self.assertEqual(res.status_int, 200) - flavor = json.loads(res.body) + req = fakes.HTTPRequest.blank('/v1.1/fake/flavors/1') + flavor = self.controller.show(req, '1') expected = { "flavor": { "id": "1", @@ -126,10 +126,8 @@ class FlavorsTest(test.TestCase): self.assertEqual(flavor, expected) def test_get_flavor_list(self): - req = webob.Request.blank('/v1.1/fake/flavors') - res = req.get_response(fakes.wsgi_app()) - self.assertEqual(res.status_int, 200) - flavor = json.loads(res.body) + req = fakes.HTTPRequest.blank('/v1.1/fake/flavors') + flavor = self.controller.index(req) expected = { "flavors": [ { @@ -165,10 +163,8 @@ class FlavorsTest(test.TestCase): self.assertEqual(flavor, expected) def test_get_flavor_list_detail(self): - req = webob.Request.blank('/v1.1/fake/flavors/detail') - res = req.get_response(fakes.wsgi_app()) - self.assertEqual(res.status_int, 200) - flavor = json.loads(res.body) + req = fakes.HTTPRequest.blank('/v1.1/fake/flavors/detail') + flavor = self.controller.detail(req) expected = { "flavors": [ { @@ -219,19 +215,15 @@ class FlavorsTest(test.TestCase): self.stubs.Set(nova.db.api, "instance_type_get_all", empty_instance_type_get_all) - req = webob.Request.blank('/v1.1/fake/flavors') - res = req.get_response(fakes.wsgi_app()) - self.assertEqual(res.status_int, 200) - flavors = json.loads(res.body)["flavors"] - expected = [] + req = fakes.HTTPRequest.blank('/v1.1/fake/flavors') + flavors = self.controller.index(req) + expected = {'flavors': []} self.assertEqual(flavors, expected) def test_get_flavor_list_filter_min_ram(self): """Flavor lists may be filtered by minRam""" - req = webob.Request.blank('/v1.1/fake/flavors?minRam=512') - res = req.get_response(fakes.wsgi_app()) - self.assertEqual(res.status_int, 200) - flavor = json.loads(res.body) + req = fakes.HTTPRequest.blank('/v1.1/fake/flavors?minRam=512') + flavor = self.controller.index(req) expected = { "flavors": [ { @@ -254,10 +246,8 @@ class FlavorsTest(test.TestCase): def test_get_flavor_list_filter_min_disk(self): """Flavor lists may be filtered by minRam""" - req = webob.Request.blank('/v1.1/fake/flavors?minDisk=20') - res = req.get_response(fakes.wsgi_app()) - self.assertEqual(res.status_int, 200) - flavor = json.loads(res.body) + req = fakes.HTTPRequest.blank('/v1.1/fake/flavors?minDisk=20') + flavor = self.controller.index(req) expected = { "flavors": [ { @@ -282,11 +272,9 @@ class FlavorsTest(test.TestCase): """Tests that filtering work on flavor details and that minRam and minDisk filters can be combined """ - req = webob.Request.blank( - '/v1.1/fake/flavors/detail?minRam=256&minDisk=20') - res = req.get_response(fakes.wsgi_app()) - self.assertEqual(res.status_int, 200) - flavor = json.loads(res.body) + req = fakes.HTTPRequest.blank('/v1.1/fake/flavors/detail' + '?minRam=256&minDisk=20') + flavor = self.controller.detail(req) expected = { "flavors": [ { @@ -315,11 +303,8 @@ class FlavorsTest(test.TestCase): def test_get_flavor_list_detail_bogus_min_ram(self): """Tests that bogus minRam filtering values are ignored""" - req = webob.Request.blank( - '/v1.1/fake/flavors/detail?minRam=16GB') - res = req.get_response(fakes.wsgi_app()) - self.assertEqual(res.status_int, 200) - flavor = json.loads(res.body) + req = fakes.HTTPRequest.blank('/v1.1/fake/flavors/detail?minRam=16GB') + flavor = self.controller.detail(req) expected = { "flavors": [ { @@ -368,11 +353,8 @@ class FlavorsTest(test.TestCase): def test_get_flavor_list_detail_bogus_min_disk(self): """Tests that bogus minDisk filtering values are ignored""" - req = webob.Request.blank( - '/v1.1/fake/flavors/detail?minDisk=16GB') - res = req.get_response(fakes.wsgi_app()) - self.assertEqual(res.status_int, 200) - flavor = json.loads(res.body) + req = fakes.HTTPRequest.blank('/v1.1/fake/flavors/detail?minDisk=16GB') + flavor = self.controller.detail(req) expected = { "flavors": [ { -- cgit