Merge "Fix missing import package button in murano dashboard"
This commit is contained in:
commit
a06d59eed3
@ -213,10 +213,10 @@ class ModifyPackageForm(PackageParamsMixin, horizon_forms.SelfHandlingForm):
|
||||
choices=[('', 'No categories available')],
|
||||
required=False)
|
||||
try:
|
||||
categories = api.muranoclient(request).packages.categories()
|
||||
categories = api.muranoclient(request).categories.list()
|
||||
if categories:
|
||||
self.fields['categories'].choices = [(c, c)
|
||||
for c in categories]
|
||||
category_names = [(c.name, c.name) for c in categories]
|
||||
self.fields['categories'].choices = category_names
|
||||
if package.categories:
|
||||
self.fields['categories'].initial = dict(
|
||||
(key, True) for key in package.categories)
|
||||
@ -285,10 +285,10 @@ class SelectCategories(forms.Form):
|
||||
super(SelectCategories, self).__init__(*args, **kwargs)
|
||||
|
||||
try:
|
||||
categories = api.muranoclient(request).packages.categories()
|
||||
categories = api.muranoclient(request).categories.list()
|
||||
if categories:
|
||||
self.fields['categories'].choices = [(c, c)
|
||||
for c in categories]
|
||||
category_names = [(c.name, c.name) for c in categories]
|
||||
self.fields['categories'].choices = category_names
|
||||
except (exc.HTTPException, Exception):
|
||||
msg = _('Unable to get list of categories')
|
||||
LOG.exception(msg)
|
||||
|
@ -51,7 +51,8 @@ class ImportPackage(tables.LinkAction):
|
||||
_allowed = False
|
||||
with api.handled_exceptions(request):
|
||||
client = api.muranoclient(request)
|
||||
_allowed = client.packages.categories() is not None
|
||||
if client.categories.list():
|
||||
_allowed = True
|
||||
return _allowed
|
||||
|
||||
|
||||
|
@ -149,8 +149,12 @@ class TestModifyPackageForm(helpers.APITestCase):
|
||||
self.mock_request = mock.MagicMock(return_value=(fake_response))
|
||||
|
||||
with mock.patch('muranodashboard.api.muranoclient') as mock_client:
|
||||
mock_client().packages.categories.return_value =\
|
||||
['c3', 'c4']
|
||||
mock_categories = []
|
||||
for cname in ['c3', 'c4']:
|
||||
mock_category = mock.Mock()
|
||||
mock_category.configure_mock(name=cname)
|
||||
mock_categories.append(mock_category)
|
||||
mock_client().categories.list.return_value = mock_categories
|
||||
self.modify_pkg_form = forms.ModifyPackageForm(self.mock_request,
|
||||
**self.kwargs)
|
||||
|
||||
@ -170,7 +174,7 @@ class TestModifyPackageForm(helpers.APITestCase):
|
||||
@mock.patch('muranodashboard.api.muranoclient')
|
||||
def test_init_except_http_exception(self, mock_client, mock_reverse,
|
||||
mock_exceptions):
|
||||
mock_client().packages.categories.side_effect = exc.HTTPException
|
||||
mock_client().categories.list.side_effect = exc.HTTPException
|
||||
mock_reverse.return_value = 'test_redirect'
|
||||
|
||||
self.modify_pkg_form = forms.ModifyPackageForm(self.mock_request,
|
||||
@ -265,8 +269,12 @@ class TestSelectCategories(helpers.APITestCase):
|
||||
self.kwargs = {'request': self.mock_request}
|
||||
|
||||
with mock.patch('muranodashboard.api.muranoclient') as mock_client:
|
||||
mock_client().packages.categories.return_value =\
|
||||
['c1', 'c2']
|
||||
mock_categories = []
|
||||
for cname in ['c1', 'c2']:
|
||||
mock_category = mock.Mock()
|
||||
mock_category.configure_mock(name=cname)
|
||||
mock_categories.append(mock_category)
|
||||
mock_client().categories.list.return_value = mock_categories
|
||||
self.select_categories_form = forms.SelectCategories(**self.kwargs)
|
||||
|
||||
def test_init(self):
|
||||
@ -279,7 +287,7 @@ class TestSelectCategories(helpers.APITestCase):
|
||||
@mock.patch('muranodashboard.api.muranoclient')
|
||||
def test_init_except_http_exception(self, mock_client, mock_reverse,
|
||||
mock_exceptions):
|
||||
mock_client().packages.categories.side_effect = exc.HTTPException
|
||||
mock_client().categories.list.side_effect = exc.HTTPException
|
||||
mock_reverse.return_value = 'test_redirect'
|
||||
|
||||
forms.SelectCategories(**self.kwargs)
|
||||
|
@ -40,10 +40,10 @@ class TestImportPackage(testtools.TestCase):
|
||||
|
||||
@mock.patch.object(tables, 'api')
|
||||
def test_allowed(self, mock_api):
|
||||
mock_api.muranoclient().packages.categories.return_value = ['foo_cat']
|
||||
mock_api.muranoclient().categories.list.return_value = ['foo_cat']
|
||||
self.assertTrue(self.import_package.allowed(None, None))
|
||||
|
||||
mock_api.muranoclient().packages.categories.return_value = None
|
||||
mock_api.muranoclient().categories.list.return_value = None
|
||||
self.assertFalse(self.import_package.allowed(None, None))
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user