Merge "Get rid of the "with" warnings in tests"

This commit is contained in:
Jenkins 2015-01-26 13:27:03 +00:00 committed by Gerrit Code Review
commit 6e48b885c3
1 changed files with 41 additions and 31 deletions

View File

@ -12,8 +12,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import contextlib
from django.core import urlresolvers from django.core import urlresolvers
import mock import mock
from tuskar_ui import api from tuskar_ui import api
@ -27,11 +25,14 @@ INDEX_URL = urlresolvers.reverse(
class BoxesViewsTests(helpers.BaseAdminViewTests): class BoxesViewsTests(helpers.BaseAdminViewTests):
def test_index_edit_get(self): def test_index_edit_get(self):
with contextlib.nested( with (
tests._mock_plan(), tests._mock_plan()
mock.patch('tuskar_ui.api.heat.Stack.list', return_value=[]), ), (
mock.patch('tuskar_ui.api.node.Node.list', return_value=[]), mock.patch('tuskar_ui.api.heat.Stack.list', return_value=[])
mock.patch('tuskar_ui.api.flavor.Flavor.list', return_value=[]), ), (
mock.patch('tuskar_ui.api.node.Node.list', return_value=[])
), (
mock.patch('tuskar_ui.api.flavor.Flavor.list', return_value=[])
): ):
res = self.client.get(INDEX_URL) res = self.client.get(INDEX_URL)
self.assertTemplateUsed( self.assertTemplateUsed(
@ -42,12 +43,15 @@ class BoxesViewsTests(helpers.BaseAdminViewTests):
def test_index_edit_post(self): def test_index_edit_post(self):
roles = [api.tuskar.Role(role) roles = [api.tuskar.Role(role)
for role in self.tuskarclient_roles.list()] for role in self.tuskarclient_roles.list()]
with contextlib.nested( with (
tests._mock_plan(), tests._mock_plan()
mock.patch('tuskar_ui.api.heat.Stack.list', return_value=[]), ) as plan, (
mock.patch('tuskar_ui.api.node.Node.list', return_value=[]), mock.patch('tuskar_ui.api.heat.Stack.list', return_value=[])
mock.patch('tuskar_ui.api.flavor.Flavor.list', return_value=[]), ), (
) as (plan, _stack_list, _node_list, _flavor_list): mock.patch('tuskar_ui.api.node.Node.list', return_value=[])
), (
mock.patch('tuskar_ui.api.flavor.Flavor.list', return_value=[])
):
plan.role_list = roles plan.role_list = roles
data = { data = {
'role-1-count': 1, 'role-1-count': 1,
@ -76,16 +80,17 @@ class BoxesViewsTests(helpers.BaseAdminViewTests):
roles = [api.tuskar.Role(role) roles = [api.tuskar.Role(role)
for role in self.tuskarclient_roles.list()] for role in self.tuskarclient_roles.list()]
with contextlib.nested( with (
tests._mock_plan(**{ tests._mock_plan(**{
'get_role_by_name.side_effect': None, 'get_role_by_name.side_effect': None,
'get_role_by_name.return_value': roles[0], 'get_role_by_name.return_value': roles[0],
}), })
), (
mock.patch('tuskar_ui.api.heat.Stack.get_by_plan', mock.patch('tuskar_ui.api.heat.Stack.get_by_plan',
return_value=stack), return_value=stack)
mock.patch('tuskar_ui.api.heat.Stack.events', ), (
return_value=[]), mock.patch('tuskar_ui.api.heat.Stack.events', return_value=[])
) as (Plan, stack_get_mock, stack_events_mock): ):
res = self.client.get(INDEX_URL) res = self.client.get(INDEX_URL)
self.assertTemplateUsed( self.assertTemplateUsed(
res, 'tuskar_boxes/overview/index.html') res, 'tuskar_boxes/overview/index.html')
@ -97,18 +102,23 @@ class BoxesViewsTests(helpers.BaseAdminViewTests):
def test_index_progress_get(self): def test_index_progress_get(self):
stack = api.heat.Stack(tests.TEST_DATA.heatclient_stacks.first()) stack = api.heat.Stack(tests.TEST_DATA.heatclient_stacks.first())
with contextlib.nested( with (
tests._mock_plan(), tests._mock_plan()
mock.patch('tuskar_ui.api.heat.Stack.get_by_plan', ), (
return_value=stack), mock.patch('tuskar_ui.api.heat.Stack.get_by_plan',
mock.patch('tuskar_ui.api.heat.Stack.is_deleting', return_value=stack)
return_value=True), ), (
mock.patch('tuskar_ui.api.heat.Stack.is_deployed', mock.patch('tuskar_ui.api.heat.Stack.is_deleting',
return_value=False), return_value=True)
mock.patch('tuskar_ui.api.heat.Stack.resources', ), (
return_value=[]), mock.patch('tuskar_ui.api.heat.Stack.is_deployed',
mock.patch('tuskar_ui.api.heat.Stack.events', return_value=False)
return_value=[]), ), (
mock.patch('tuskar_ui.api.heat.Stack.resources',
return_value=[])
), (
mock.patch('tuskar_ui.api.heat.Stack.events',
return_value=[])
): ):
res = self.client.get(INDEX_URL) res = self.client.get(INDEX_URL)
self.assertTemplateUsed( self.assertTemplateUsed(