diff options
Diffstat (limited to 'repoze')
| -rw-r--r-- | repoze/bfg/tests/test_traversal.py | 26 | ||||
| -rw-r--r-- | repoze/bfg/traversal.py | 27 |
2 files changed, 41 insertions, 12 deletions
diff --git a/repoze/bfg/tests/test_traversal.py b/repoze/bfg/tests/test_traversal.py index f361d0a79..867dae318 100644 --- a/repoze/bfg/tests/test_traversal.py +++ b/repoze/bfg/tests/test_traversal.py @@ -384,7 +384,31 @@ class ModelPathTests(unittest.TestCase): root.__name__ = None result = self._callFUT(root) self.assertEqual(result, '/') - + + def test_root_default_emptystring(self): + root = DummyContext() + root.__parent__ = None + root.__name__ = '' + result = self._callFUT(root) + self.assertEqual(result, '/') + + def test_root_object_nonnull_name_direct(self): + root = DummyContext() + root.__parent__ = None + root.__name__ = 'flubadub' + result = self._callFUT(root) + self.assertEqual(result, 'flubadub') # insane case + + def test_root_object_nonnull_name_indirect(self): + root = DummyContext() + root.__parent__ = None + root.__name__ = 'flubadub' + other = DummyContext() + other.__parent__ = root + other.__name__ = 'barker' + result = self._callFUT(other) + self.assertEqual(result, 'flubadub/barker') # insane case + def test_nonroot_default(self): root = DummyContext() root.__parent__ = None diff --git a/repoze/bfg/traversal.py b/repoze/bfg/traversal.py index f4f64484f..9da1818fc 100644 --- a/repoze/bfg/traversal.py +++ b/repoze/bfg/traversal.py @@ -172,12 +172,14 @@ def model_path(model, *elements): instance, if one of the models in your graph has a ``__name__`` which (by error) is a dictionary, the ``model_path`` function will attempt to append it to a - string and it will cause a TypeError. A single - exception to this rule exists: the :term:`root` model - may have a ``__name__`` attribute of any value; the - value of this attribute will always be ignored (and - effectively replaced with a leading ``/``) when the path - is generated. + string and it will cause a TypeError. + + .. note:: The the :term:`root` model *must* have a ``__name__`` + attribute with a value of either ``None`` or the empty + string for paths to be generated properly. If the root + model has a non-null ``__name__`` attribute, its name + will be prepended to the generated path rather than a + single leading '/' character. """ path = _model_path_list(model, *elements) return path and '/'.join([quote_path_segment(x) for x in path]) or '/' @@ -210,11 +212,14 @@ def model_path_tuple(model, *elements): instance, if one of the models in your graph has a ``__name__`` which (by error) is a dictionary, that dictionary will be placed in the path tuple; no warning - or error will be given. A single exception to this rule - exists: the :term:`root` model may have a ``__name__`` - attribute of any value; the value of this attribute will - always be ignored (and effectively replaced with ``''``) - when the path is generated. + or error will be given. + + .. note:: The the :term:`root` model *must* have a ``__name__`` + attribute with a value of either ``None`` or the empty + string for path tuples to be generated properly. If + the root model has a non-null ``__name__`` attribute, + its name will be the first element in the generated + path tuple rather than the empty string. """ return tuple(_model_path_list(model, *elements)) |
