tuning-box/tuning_box/tests/library/test_levels_hierarchy.py
Alexander Kislitsky a21d1a1212 Hierarchy removed from level values
We don't need to have duplicate of levels hierarchy in the
level values. Without duplication we can easy change hierarchy
levels in the environment.
Cascade deletion added on level deletion to level values.

Change-Id: I9aded18c93b8c3f0f08e59817d33e7d21ff12d54
2016-08-19 08:24:12 +00:00

59 lines
2.2 KiB
Python

# 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 werkzeug
from tuning_box import db
from tuning_box.library import levels_hierarchy
from tuning_box.tests.test_app import BaseTest
class TestLevelsHierarchy(BaseTest):
def test_get_environment_level_value_root(self):
self._fixture()
with self.app.app_context(), db.db.session.begin():
level_value = levels_hierarchy.get_environment_level_value(
db.Environment(id=9),
[],
)
self.assertIsNone(level_value)
def test_get_environment_level_value_deep(self):
self._fixture()
with self.app.app_context(), db.db.session.begin():
level_value = levels_hierarchy.get_environment_level_value(
db.Environment(id=9),
[('lvl1', 'val1'), ('lvl2', 'val2')],
)
self.assertIsNotNone(level_value)
self.assertEqual(level_value.level.name, 'lvl2')
self.assertEqual(level_value.value, 'val2')
level = level_value.level.parent
self.assertIsNotNone(level)
self.assertEqual(level.name, 'lvl1')
self.assertIsNone(level.parent)
def test_get_environment_level_value_bad_level(self):
self._fixture()
with self.app.app_context(), db.db.session.begin():
exc = self.assertRaises(
werkzeug.exceptions.BadRequest,
levels_hierarchy.get_environment_level_value,
db.Environment(id=9),
[('lvlx', 'val1')],
)
self.assertEqual(
exc.description,
"Unexpected level name 'lvlx'. Expected 'lvl1'.",
)