Get rid of the "with" warnings in tests
Since we are now Python 2.7 only, we can use the "multiple with" statement as the build-in warning tells us. The resulting code is fugly, but what do I know. Change-Id: I3b13c42f6b13c3180721d848923cdc0f05654fe5
This commit is contained in:
parent
c0daa7faaa
commit
337e79d712
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user