From 9428adb95a979b27136e24dfb280c9c610ad6167 Mon Sep 17 00:00:00 2001 From: Artem Tiumentcev Date: Tue, 2 May 2017 13:31:30 +0300 Subject: [PATCH] Fixed issues on Python 3 Blueprint: murano-python-3-support Change-Id: I01a095dc2c8953d177a8b13c1b97ddb4561d6e5f --- muranodashboard/api/packages.py | 2 +- muranodashboard/catalog/views.py | 3 +- muranodashboard/dynamic_ui/services.py | 2 +- .../tests/unit/packages/test_api.py | 34 +++++++++++++++---- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/muranodashboard/api/packages.py b/muranodashboard/api/packages.py index 18f0eea2a..d26ba7ed7 100644 --- a/muranodashboard/api/packages.py +++ b/muranodashboard/api/packages.py @@ -69,7 +69,7 @@ def app_by_fqn(request, fqn, catalog=True, version=None): kwargs['version'] = version apps = api.muranoclient(request).packages.filter(**kwargs) try: - return apps.next() + return next(apps) except StopIteration: return None diff --git a/muranodashboard/catalog/views.py b/muranodashboard/catalog/views.py index a048af0c9..1ccaceaeb 100644 --- a/muranodashboard/catalog/views.py +++ b/muranodashboard/catalog/views.py @@ -342,8 +342,7 @@ class Wizard(generic_views.PageTitleMixin, views.ModalFormMixin, LazyWizard): def done(self, form_list, **kwargs): app_name = self.storage.extra_data['app'].name - - service = form_list[0].service + service = tuple(form_list)[0].service attributes = service.extract_attributes() attributes = helpers.insert_hidden_ids(attributes) diff --git a/muranodashboard/dynamic_ui/services.py b/muranodashboard/dynamic_ui/services.py index 40725106c..c89018034 100644 --- a/muranodashboard/dynamic_ui/services.py +++ b/muranodashboard/dynamic_ui/services.py @@ -255,7 +255,7 @@ def get_app_forms(request, kwargs): return _get_form_name(i, form, _('Step {0}')) step_names = [get_form_name(*pair) for pair in enumerate(app.forms)] - return zip(step_names, app.forms) + return list(zip(step_names, app.forms)) def service_type_from_id(service_id): diff --git a/muranodashboard/tests/unit/packages/test_api.py b/muranodashboard/tests/unit/packages/test_api.py index ce2c21a3a..d399b5f81 100644 --- a/muranodashboard/tests/unit/packages/test_api.py +++ b/muranodashboard/tests/unit/packages/test_api.py @@ -13,14 +13,28 @@ # under the License. import mock +from six import PY3 from muranoclient.v1 import client from muranodashboard.api import packages from openstack_dashboard.test import helpers -class TestPackagesAPI(helpers.APITestCase): +def mock_next(obj, attr, value): + if PY3: + setattr(obj.__next__, attr, value) + else: + setattr(obj.next, attr, value) + +class MagicIterMock(mock.MagicMock): + if PY3: + __next__ = mock.Mock(return_value=None) + else: + next = mock.Mock(return_value=None) + + +class TestPackagesAPI(helpers.APITestCase): def setUp(self): super(TestPackagesAPI, self).setUp() @@ -84,8 +98,12 @@ class TestPackagesAPI(helpers.APITestCase): inherits='test_fqn') def test_app_by_fqn(self): - self.mock_client = mock.Mock(spec=client) - self.mock_client.packages.filter().next.return_value = self.packages[0] + self.mock_client = MagicIterMock(spec=client) + mock_next( + self.mock_client.packages.filter(), + 'return_value', + self.packages[0] + ) packages.api.muranoclient.return_value = self.mock_client self.mock_client.reset_mock() @@ -98,8 +116,12 @@ class TestPackagesAPI(helpers.APITestCase): fqn='test_fqn', catalog=True, version='1.0') def test_app_by_fqn_except_stop_iteration(self): - self.mock_client = mock.Mock(spec=client) - self.mock_client.packages.filter().next.side_effect = StopIteration + self.mock_client = MagicIterMock(spec=client) + mock_next( + self.mock_client.packages.filter(), + 'side_effect', + StopIteration + ) packages.api.muranoclient.return_value = self.mock_client self.mock_client.reset_mock() @@ -145,7 +167,7 @@ class TestPackagesAPI(helpers.APITestCase): return_value=None) @mock.patch('muranodashboard.common.cache._save_to_file') def test_get_app_supplier_logo(self, *args): - mock_get_supplier_logo = packages.api.muranoclient().packages.\ + mock_get_supplier_logo = packages.api.muranoclient().packages. \ get_supplier_logo mock_get_supplier_logo.return_value = 'foo_app_supplier_logo'