def test_parse():
    """Parse a path to a stack, default namespaces.
    """
    assert ([(DEFAULT, 'a'),
             (DEFAULT, 'b'),
             (DEFAULT, 'c')] ==
            list(parse_path('/a/b/c')))
    assert list(parse_path('/')) == []
    assert list(parse_path('')) == []
def test_parse_ns():
    """Parse a path to a stack with namespaces.
    """
    assert ([(DEFAULT, 'a'),
             (DEFAULT, 'b'),
             (VIEW, 'c')] ==
            list(parse_path('/a/b/++view++c')))
示例#3
0
    def publish(self, root, environ):
        path = unquote(
            environ['PATH_INFO'].encode('latin-1').decode('utf-8'))
        stack = parse_path(path)
        model, crumbs = self.model_lookup(root, stack)
        component = self.view_lookup(model, crumbs, environ)

        # The model needs an renderer
        if component is None:
            raise PublicationError('%r can not be rendered.' % model)

        return component
def test_parse_ns_weird_no_open():
    # a namespace that closes but doesn't open
    assert ([(DEFAULT, 'a'),
             (DEFAULT, 'b'),
             (DEFAULT, 'view++c')] ==
            list(parse_path('/a/b/view++c')))
def test_parse_ns_weird_no_close():
    assert ([(DEFAULT, 'a'),
             (DEFAULT, 'b'),
             (DEFAULT, '++c')] ==
            list(parse_path('/a/b/++c')))
def test_parse_ns_shortcut_not_at_beginning():
    # shortcuts should be at the beginning of a step to be recognized
    assert ([(DEFAULT, 'a'),
             (DEFAULT, 'b'),
             (DEFAULT, 'a@@c')] ==
            list(parse_path('/a/b/a@@c', shortcuts={'@@': VIEW})))
def test_parse_ns_shortcut():
    assert ([(DEFAULT, 'a'),
             (DEFAULT, 'b'),
             (VIEW, 'c')] ==
            list(parse_path('/a/b/@@c', shortcuts={'@@': VIEW})))
def test_multi_slash():
    assert parse_path('/a/b/c') == parse_path('/a///b//c')
    assert parse_path('/a/b/c') == parse_path('/a/b/c/')