# Path: deckhand/common/utils.py
# LOG = logging.getLogger(__name__)
# _PATH_CACHE = dict()
# _ARRAY_RE = re.compile(r'.*\[\d+\].*')
# def to_camel_case(s):
# def to_snake_case(name):
# def _normalize_jsonpath(jsonpath):
# def _jsonpath_parse_cache(jsonpath):
# def jsonpath_parse(data, jsonpath, match_all=False):
# def _populate_data_with_attributes(jsonpath, data):
# def jsonpath_replace(data, value, jsonpath, pattern=None):
#     def _do_replace():
# def multisort(data, sort_by=None, order_by=None):
# def deepfilter(dct, **filters):
#     def _transform_filter_bool(filter_val):
# 
# Path: deckhand/tests/unit/base.py
# CONF = cfg.CONF
# class DeckhandTestCase(testtools.TestCase):
# class DeckhandWithDBTestCase(DeckhandTestCase):
#     def setUp(self):
#     def override_config(self, name, override, group=None):
#     def assertEmpty(self, collection):
#     def assertDictItemsAlmostEqual(self, first, second, ignore):
#     def patch(self, target, autospec=True, **kwargs):
#     def patchobject(self, target, attribute, new=mock.DEFAULT, **kwargs):
#     def setUp(self):


from deckhand.common import utils
from deckhand.tests.unit import base as test_base
# 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 TestUtils(test_base.DeckhandTestCase):

    def test_jsonpath_replace_creates_object(self):
        path = ".values.endpoints.admin"
        expected = {'values': {'endpoints': {'admin': 'foo'}}}
        result = utils.jsonpath_replace({}, 'foo', path)
        self.assertEqual(expected, result)

    def test_jsonpath_replace_with_array_index_creates_array(self):
        path = ".values.endpoints[0].admin"
        expected = {'values': {'endpoints': [{'admin': 'foo'}]}}
        result = utils.jsonpath_replace({}, 'foo', path)
        self.assertEqual(expected, result)

        path = ".values.endpoints[1].admin"
        expected = {'values': {'endpoints': [{}, {'admin': 'foo'}]}}

# Path: deckhand/common/utils.py
# LOG = logging.getLogger(__name__)
# _PATH_CACHE = dict()
# _ARRAY_RE = re.compile(r'.*\[\d+\].*')
# def to_camel_case(s):
# def to_snake_case(name):
# def _normalize_jsonpath(jsonpath):
# def _jsonpath_parse_cache(jsonpath):
# def jsonpath_parse(data, jsonpath, match_all=False):
# def _populate_data_with_attributes(jsonpath, data):
# def jsonpath_replace(data, value, jsonpath, pattern=None):
#     def _do_replace():
# def multisort(data, sort_by=None, order_by=None):
# def deepfilter(dct, **filters):
#     def _transform_filter_bool(filter_val):
# 
# Path: deckhand/tests/unit/base.py
# CONF = cfg.CONF
# class DeckhandTestCase(testtools.TestCase):
# class DeckhandWithDBTestCase(DeckhandTestCase):
#     def setUp(self):
#     def override_config(self, name, override, group=None):
#     def assertEmpty(self, collection):
#     def assertDictItemsAlmostEqual(self, first, second, ignore):
#     def patch(self, target, autospec=True, **kwargs):
#     def patchobject(self, target, attribute, new=mock.DEFAULT, **kwargs):
#     def setUp(self):


# Path: deckhand/tests/unit/common/test_utils.py
from deckhand.common import utils
from deckhand.tests.unit import base as test_base

# 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 TestUtils(test_base.DeckhandTestCase):

    def test_jsonpath_replace_creates_object(self):
        path = ".values.endpoints.admin"
        expected = {'values': {'endpoints': {'admin': 'foo'}}}
        result = utils.jsonpath_replace({}, 'foo', path)
        self.assertEqual(expected, result)

    def test_jsonpath_replace_with_array_index_creates_array(self):
        path = ".values.endpoints[0].admin"
        expected = {'values': {'endpoints': [{'admin': 'foo'}]}}
        result = utils.jsonpath_replace({}, 'foo', path)
        self.assertEqual(expected, result)

        path = ".values.endpoints[1].admin"
        expected = {'values': {'endpoints': [{}, {'admin': 'foo'}]}}

        result = utils.jsonpath_replace({}, 'foo', path)