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