From 19761bfa609f5e34f7d589b33ef4e1c6f82121d2 Mon Sep 17 00:00:00 2001 From: Anastasia Kuznetsova Date: Tue, 16 Feb 2016 11:15:59 +0300 Subject: [PATCH] Fix gate-mistral-dashboard-python34 Fixed a lot of AttributeError: 'module' object has no attribute 'nested' and F821 undefined name 'unicode' errors. Change-Id: I79e73e27608ec6b76fd4ccf0ee9dcaf2ddf965ed Closes-Bug: #1544499 --- mistraldashboard/actions/tests.py | 7 ++--- mistraldashboard/executions/tests.py | 7 ++--- mistraldashboard/tasks/tests.py | 7 ++--- mistraldashboard/workbooks/forms.py | 4 ++- mistraldashboard/workbooks/tests.py | 40 ++++++++++++---------------- mistraldashboard/workflows/forms.py | 4 ++- mistraldashboard/workflows/tests.py | 40 ++++++++++++---------------- 7 files changed, 46 insertions(+), 63 deletions(-) diff --git a/mistraldashboard/actions/tests.py b/mistraldashboard/actions/tests.py index a2ce85d..a62a9a7 100644 --- a/mistraldashboard/actions/tests.py +++ b/mistraldashboard/actions/tests.py @@ -12,8 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -import contextlib - from django.core.urlresolvers import reverse import mock @@ -25,9 +23,8 @@ INDEX_URL = reverse('horizon:mistral:actions:index') class ActionsTest(test.TestCase): def test_index(self): - with contextlib.nested( - mock.patch('mistraldashboard.api.action_list', - return_value=self.mistralclient_actions.list()),): + with mock.patch('mistraldashboard.api.action_list', + return_value=self.mistralclient_actions.list()): res = self.client.get(INDEX_URL) self.assertTemplateUsed(res, 'mistral/actions/index.html') diff --git a/mistraldashboard/executions/tests.py b/mistraldashboard/executions/tests.py index 5bed856..542320b 100644 --- a/mistraldashboard/executions/tests.py +++ b/mistraldashboard/executions/tests.py @@ -12,8 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -import contextlib - from django.core.urlresolvers import reverse import mock @@ -25,9 +23,8 @@ INDEX_URL = reverse('horizon:mistral:executions:index') class ExecutionsTest(test.TestCase): def test_index(self): - with contextlib.nested( - mock.patch('mistraldashboard.api.pagination_list', - return_value=self.mistralclient_executions.list()),): + with mock.patch('mistraldashboard.api.pagination_list', + return_value=self.mistralclient_executions.list()): res = self.client.get(INDEX_URL) self.assertTemplateUsed(res, 'mistral/executions/index.html') diff --git a/mistraldashboard/tasks/tests.py b/mistraldashboard/tasks/tests.py index dca481b..7d63f19 100644 --- a/mistraldashboard/tasks/tests.py +++ b/mistraldashboard/tasks/tests.py @@ -12,8 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -import contextlib - from django.core.urlresolvers import reverse import mock @@ -25,9 +23,8 @@ INDEX_URL = reverse('horizon:mistral:tasks:index') class TasksTest(test.TestCase): def test_index(self): - with contextlib.nested( - mock.patch('mistraldashboard.api.task_list', - return_value=self.mistralclient_tasks.list()),): + with mock.patch('mistraldashboard.api.task_list', + return_value=self.mistralclient_tasks.list()): res = self.client.get(INDEX_URL) self.assertTemplateUsed(res, 'mistral/tasks/index.html') diff --git a/mistraldashboard/workbooks/forms.py b/mistraldashboard/workbooks/forms.py index 16bab06..501036f 100644 --- a/mistraldashboard/workbooks/forms.py +++ b/mistraldashboard/workbooks/forms.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import six + from django.core.urlresolvers import reverse from django.utils.translation import ugettext_lazy as _ @@ -74,7 +76,7 @@ class DefinitionForm(forms.SelfHandlingForm): cleaned_data['definition'] ) except Exception as e: - raise forms.ValidationError(unicode(e)) + raise forms.ValidationError(six.text_type(e)) if not validated.get('valid'): raise forms.ValidationError( diff --git a/mistraldashboard/workbooks/tests.py b/mistraldashboard/workbooks/tests.py index 4782083..7f6680f 100644 --- a/mistraldashboard/workbooks/tests.py +++ b/mistraldashboard/workbooks/tests.py @@ -12,8 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -import contextlib - from django.core.urlresolvers import reverse import mock @@ -27,9 +25,8 @@ UPDATE_URL = reverse('horizon:mistral:workbooks:update') class WorkflowsTest(test.TestCase): def test_index(self): - with contextlib.nested( - mock.patch('mistraldashboard.api.workbook_list', - return_value=self.mistralclient_workbooks.list()),): + with mock.patch('mistraldashboard.api.workbook_list', + return_value=self.mistralclient_workbooks.list()): res = self.client.get(INDEX_URL) self.assertTemplateUsed(res, 'mistral/workbooks/index.html') @@ -51,9 +48,8 @@ class WorkflowsTest(test.TestCase): 'definition_source': 'raw', 'definition_data': workbook.definition } - with contextlib.nested( - mock.patch('mistraldashboard.api.workbook_validate', - return_value={'valid': True}),) as (mocked_validate,): + with mock.patch('mistraldashboard.api.workbook_validate', + return_value={'valid': True}) as mocked_validate: res = self.client.post(url, form_data) self.assertTemplateUsed(res, 'mistral/workbooks/create.html') @@ -65,9 +61,8 @@ class WorkflowsTest(test.TestCase): form_data = { 'definition': workbook.definition } - with contextlib.nested( - mock.patch('mistraldashboard.api.workbook_create', - return_value=workbook),) as (mocked_create,): + with mock.patch('mistraldashboard.api.workbook_create', + return_value=workbook) as mocked_create: res = self.client.post(CREATE_URL, form_data) self.assertNoFormErrors(res) self.assertEqual(res.status_code, 302) @@ -95,9 +90,8 @@ class WorkflowsTest(test.TestCase): 'definition_source': 'raw', 'definition_data': workbook.definition } - with contextlib.nested( - mock.patch('mistraldashboard.api.workbook_validate', - return_value={'valid': True}),) as (mocked_validate,): + with mock.patch('mistraldashboard.api.workbook_validate', + return_value={'valid': True}) as mocked_validate: res = self.client.post(url, form_data) self.assertTemplateUsed(res, 'mistral/workbooks/update.html') @@ -109,9 +103,8 @@ class WorkflowsTest(test.TestCase): form_data = { 'definition': workbook.definition } - with contextlib.nested( - mock.patch('mistraldashboard.api.workbook_update', - return_value=workbook),) as (mocked_update,): + with mock.patch('mistraldashboard.api.workbook_update', + return_value=workbook) as mocked_update: res = self.client.post(UPDATE_URL, form_data) self.assertNoFormErrors(res) self.assertEqual(res.status_code, 302) @@ -128,12 +121,13 @@ class WorkflowsTest(test.TestCase): data = {'action': 'workbooks__delete', 'object_ids': [workbooks[0].name]} - with contextlib.nested( - mock.patch('mistraldashboard.api.workbook_list', - return_value=workbooks), - mock.patch('mistraldashboard.api.workbook_delete', - return_value=None),) as ( - mocked_list, mocked_delete): + with mock.patch( + 'mistraldashboard.api.workbook_list', + return_value=workbooks + ), mock.patch( + 'mistraldashboard.api.workbook_delete', + return_value=None + ) as mocked_delete: res = self.client.post(INDEX_URL, data) diff --git a/mistraldashboard/workflows/forms.py b/mistraldashboard/workflows/forms.py index e56ee10..928801c 100644 --- a/mistraldashboard/workflows/forms.py +++ b/mistraldashboard/workflows/forms.py @@ -14,6 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import six + from django.core.urlresolvers import reverse from django.utils.translation import ugettext_lazy as _ @@ -108,7 +110,7 @@ class DefinitionForm(forms.SelfHandlingForm): cleaned_data['definition'] ) except Exception as e: - raise forms.ValidationError(unicode(e)) + raise forms.ValidationError(six.text_type(e)) if not validated.get('valid'): raise forms.ValidationError( diff --git a/mistraldashboard/workflows/tests.py b/mistraldashboard/workflows/tests.py index b91e112..d4616c3 100644 --- a/mistraldashboard/workflows/tests.py +++ b/mistraldashboard/workflows/tests.py @@ -12,8 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -import contextlib - from django.core.urlresolvers import reverse import mock @@ -27,9 +25,8 @@ UPDATE_URL = reverse('horizon:mistral:workflows:update') class WorkflowsTest(test.TestCase): def test_index(self): - with contextlib.nested( - mock.patch('mistraldashboard.api.workflow_list', - return_value=self.mistralclient_workflows.list()),): + with mock.patch('mistraldashboard.api.workflow_list', + return_value=self.mistralclient_workflows.list()): res = self.client.get(INDEX_URL) self.assertTemplateUsed(res, 'mistral/workflows/index.html') @@ -51,9 +48,8 @@ class WorkflowsTest(test.TestCase): 'definition_source': 'raw', 'definition_data': workflow.definition } - with contextlib.nested( - mock.patch('mistraldashboard.api.workflow_validate', - return_value={'valid': True}),) as (mocked_validate,): + with mock.patch('mistraldashboard.api.workflow_validate', + return_value={'valid': True}) as mocked_validate: res = self.client.post(url, form_data) self.assertTemplateUsed(res, 'mistral/workflows/create.html') @@ -65,9 +61,8 @@ class WorkflowsTest(test.TestCase): form_data = { 'definition': workflow.definition } - with contextlib.nested( - mock.patch('mistraldashboard.api.workflow_create', - return_value=workflow),) as (mocked_create,): + with mock.patch('mistraldashboard.api.workflow_create', + return_value=workflow) as mocked_create: res = self.client.post(CREATE_URL, form_data) self.assertNoFormErrors(res) self.assertEqual(res.status_code, 302) @@ -95,9 +90,8 @@ class WorkflowsTest(test.TestCase): 'definition_source': 'raw', 'definition_data': workflow.definition } - with contextlib.nested( - mock.patch('mistraldashboard.api.workflow_validate', - return_value={'valid': True}),) as (mocked_validate,): + with mock.patch('mistraldashboard.api.workflow_validate', + return_value={'valid': True}) as mocked_validate: res = self.client.post(url, form_data) self.assertTemplateUsed(res, 'mistral/workflows/update.html') @@ -109,9 +103,8 @@ class WorkflowsTest(test.TestCase): form_data = { 'definition': workflow.definition } - with contextlib.nested( - mock.patch('mistraldashboard.api.workflow_update', - return_value=workflow),) as (mocked_update,): + with mock.patch('mistraldashboard.api.workflow_update', + return_value=workflow) as mocked_update: res = self.client.post(UPDATE_URL, form_data) self.assertNoFormErrors(res) self.assertEqual(res.status_code, 302) @@ -128,12 +121,13 @@ class WorkflowsTest(test.TestCase): data = {'action': 'workflows__delete', 'object_ids': [workflows[0].name]} - with contextlib.nested( - mock.patch('mistraldashboard.api.workflow_list', - return_value=workflows), - mock.patch('mistraldashboard.api.workflow_delete', - return_value=None),) as ( - mocked_list, mocked_delete): + with mock.patch( + 'mistraldashboard.api.workflow_list', + return_value=workflows + ), mock.patch( + 'mistraldashboard.api.workflow_delete', + return_value=None + ) as mocked_delete: res = self.client.post(INDEX_URL, data)