Drop bunch dependency
Instead use hand-written muranodashboard.common.utils.Bunch class. Change-Id: I8982dda81a0d2dac09bf49e0c9ffcfc2d67f84e5
This commit is contained in:
parent
ea984d0e03
commit
a3666e57a8
0
muranodashboard/common/__init__.py
Normal file
0
muranodashboard/common/__init__.py
Normal file
38
muranodashboard/common/utils.py
Normal file
38
muranodashboard/common/utils.py
Normal file
@ -0,0 +1,38 @@
|
||||
# Copyright (c) 2014 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
class Bunch(object):
|
||||
"""
|
||||
Bunch is a container that provides both dictionary-like and
|
||||
object-like attribute access.
|
||||
"""
|
||||
def __init__(self, **kwargs):
|
||||
for key, value in kwargs.iteritems():
|
||||
setattr(self, key, value)
|
||||
|
||||
def __getitem__(self, item):
|
||||
return getattr(self, item)
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
setattr(self, key, value)
|
||||
|
||||
def __delitem__(self, key):
|
||||
delattr(self, key)
|
||||
|
||||
def __contains__(self, item):
|
||||
return hasattr(self, item)
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self.__dict__.itervalues())
|
@ -13,7 +13,6 @@
|
||||
# under the License.
|
||||
|
||||
import logging
|
||||
import bunch
|
||||
import json
|
||||
from django.conf import settings
|
||||
from horizon.exceptions import ServiceCatalogException
|
||||
@ -25,6 +24,7 @@ from consts import STATUS_ID_READY, STATUS_ID_NEW
|
||||
from .network import get_network_params
|
||||
|
||||
from muranodashboard.environments import format
|
||||
from muranodashboard.common import utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@ -259,7 +259,7 @@ def services_list(request, environment_id):
|
||||
services.append(service_data)
|
||||
|
||||
LOG.debug('Service::List')
|
||||
return [bunch.bunchify(service) for service in services]
|
||||
return [utils.Bunch(**service) for service in services]
|
||||
|
||||
|
||||
def app_id_by_fqn(request, fqn):
|
||||
|
@ -12,12 +12,12 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import bunch
|
||||
import mock
|
||||
import unittest2 as unittest
|
||||
|
||||
from mock import patch
|
||||
|
||||
from muranodashboard.common import utils
|
||||
|
||||
from muranodashboard.dynamic_ui.fields import PostgreSqlChoiceField
|
||||
|
||||
|
||||
@ -25,10 +25,8 @@ class CustomFieldsTests(unittest.TestCase):
|
||||
def test_postgresql_choice_field_values(self):
|
||||
|
||||
with patch('muranodashboard.dynamic_ui.fields.api') as mock:
|
||||
mock.service_list_by_type.return_value = [bunch.bunchify({
|
||||
'id': 'id1',
|
||||
'name': 'examplePostgreSQL'
|
||||
})]
|
||||
mock.service_list_by_type.return_value = [
|
||||
utils.Bunch(id='id1', name='examplePostgreSQL')]
|
||||
|
||||
field = PostgreSqlChoiceField()
|
||||
field.update({'environment_id': None}, request='request')
|
||||
|
69
muranodashboard/tests/test_utils.py
Normal file
69
muranodashboard/tests/test_utils.py
Normal file
@ -0,0 +1,69 @@
|
||||
# Copyright (c) 2014 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import unittest2 as unittest
|
||||
|
||||
from muranodashboard.common import utils
|
||||
|
||||
|
||||
class BunchTests(unittest.TestCase):
|
||||
def test_get_attr(self):
|
||||
obj = utils.Bunch(one=10)
|
||||
|
||||
self.assertEqual(10, obj.one)
|
||||
|
||||
def test_get_item(self):
|
||||
obj = utils.Bunch(two=15)
|
||||
|
||||
self.assertEqual(15, obj['two'])
|
||||
|
||||
def test_in(self):
|
||||
obj = utils.Bunch(one=10)
|
||||
|
||||
self.assertIn('one', obj)
|
||||
|
||||
def test_iteration(self):
|
||||
obj = utils.Bunch(one=10, two=15)
|
||||
|
||||
sorted_objs = sorted([o for o in obj])
|
||||
|
||||
self.assertEqual([10, 15], sorted_objs)
|
||||
|
||||
def test_set_attr(self):
|
||||
obj = utils.Bunch()
|
||||
|
||||
obj.one = 10
|
||||
|
||||
self.assertEqual(10, obj['one'])
|
||||
|
||||
def test_set_item(self):
|
||||
obj = utils.Bunch()
|
||||
|
||||
obj['two'] = 20
|
||||
|
||||
self.assertEqual(20, obj['two'])
|
||||
|
||||
def test_del_attr(self):
|
||||
obj = utils.Bunch(one=10)
|
||||
|
||||
del obj.one
|
||||
|
||||
self.assertNotIn('one', obj)
|
||||
|
||||
def test_del_item(self):
|
||||
obj = utils.Bunch(two=20)
|
||||
|
||||
del obj['two']
|
||||
|
||||
self.assertNotIn('two', obj)
|
@ -1,6 +1,5 @@
|
||||
pbr>=0.6,<1.0
|
||||
anyjson>=0.3.3
|
||||
bunch
|
||||
iso8601>=0.1.8
|
||||
six>=1.5.2
|
||||
PyYAML>=3.1.0
|
||||
|
Loading…
x
Reference in New Issue
Block a user