示例#1
0
def test_resolve_traverse():
    lookup = ModelLookup()
    lookup.register(Container, Traverser(traverse_container))

    root = get_structure()

    request = webob.Request.blank(u'/a')
    assert (root['a'], []) == lookup(
        request, root, parse_path(request.path))

    request = webob.Request.blank(u'/sub')
    assert (root['sub'], []) == lookup(
        request, root, parse_path(request.path))

    request = webob.Request.blank(u'/sub/b')
    assert (root['sub']['b'], []) == lookup(
        request, root, parse_path(request.path))

    request = webob.Request.blank(u'/c')
    assert (root, [(DEFAULT, u'c')]) == lookup(
        request, root, parse_path(request.path))

    request = webob.Request.blank(u'/sub/c')
    assert (root[u'sub'], [(DEFAULT, u'c')]) == lookup(
        request, root, parse_path(request.path))
示例#2
0
def test_parse():
    """Parse a path to a stack, default namespaces.
    """
    assert ([(DEFAULT, 'a'),
             (DEFAULT, 'b'),
             (DEFAULT, 'c')] ==
            list(parse_path('/a/b/c')))
示例#3
0
def test_parse():
    """Parse a path to a stack, default namespaces.
    """
    assert ([(DEFAULT, u'c'),
             (DEFAULT, u'b'),
             (DEFAULT, u'a')] ==
            parse_path(u'/a/b/c'))
示例#4
0
def test_parse_ns():
    """Parse a path to a stack with namespaces.
    """
    assert ([(VIEW, u'c'),
             (DEFAULT, u'b'),
             (DEFAULT, u'a')] ==
            parse_path(u'/a/b/++view++c'))
示例#5
0
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')))
示例#6
0
def test_resolve_traverse():
    lookup = ModelLookup()
    lookup.register(Container, Traverser(traverse_container))

    root = get_structure()

    request = webob.Request.blank('/a')
    obj, left = lookup(request, root, parse_path(request.path))
    assert obj == root['a'] and not left

    request = webob.Request.blank('/sub')
    obj, left = lookup(request, root, parse_path(request.path))
    assert obj == root['sub'] and not left

    request = webob.Request.blank('/sub/b')
    obj, left = lookup(request, root, parse_path(request.path))
    assert obj == root['sub']['b'] and not left

    request = webob.Request.blank('/c')
    obj, left = lookup(request, root, parse_path(request.path))
    assert obj == root and list(left) == [(DEFAULT, 'c')]

    request = webob.Request.blank('/sub/c')
    obj, left = lookup(request, root, parse_path(request.path))
    assert obj == root['sub'] and list(left) == [(DEFAULT, 'c')]

    # We make sure the stack is untouched by the traversing
    request = webob.Request.blank('/sub/c')
    stack = parse_path(request.path)
    obj, left = lookup(request, root, parse_path(request.path))
    assert list(left) == [(DEFAULT, 'c')]
    assert list(stack) == [('default', 'sub'), ('default', 'c')]
示例#7
0
def test_resolve_traverse():
    lookup = ModelLookup()
    lookup.register(Container, Traverser(traverse_container))

    root = get_structure()

    request = webob.Request.blank('/a')
    obj, left = lookup(request, root, parse_path(request.path))
    assert obj == root['a'] and not left

    request = webob.Request.blank('/sub')
    obj, left = lookup(request, root, parse_path(request.path))
    assert obj == root['sub'] and not left

    request = webob.Request.blank('/sub/b')
    obj, left = lookup(request, root, parse_path(request.path))
    assert obj == root['sub']['b'] and not left

    request = webob.Request.blank('/c')
    obj, left = lookup(request, root, parse_path(request.path))
    assert obj == root and list(left) == [(DEFAULT, 'c')]

    request = webob.Request.blank('/sub/c')
    obj, left = lookup(request, root, parse_path(request.path))
    assert obj == root['sub'] and list(left) == [(DEFAULT, 'c')]

    # We make sure the stack is untouched by the traversing
    request = webob.Request.blank('/sub/c')
    stack = parse_path(request.path)
    obj, left = lookup(request, root, parse_path(request.path))
    assert list(left) == [(DEFAULT, 'c')]
    assert list(stack) == [('default', 'sub'), ('default', 'c')]
示例#8
0
 def __call__(self, environ, start_response):
     request = webob.Request(environ)
     if request.charset is None:
         request.charset = 'utf8'
     stack = parse_path(request.path)
     model, unconsumed = self.model_lookup(request, self.root, stack)
     view = self.view_lookup(request, model, unconsumed)
     response = view(request, model)
     return response(environ, start_response)
示例#9
0
 def __call__(self, environ, start_response):
     request = webob.Request(environ)
     if request.charset is None:
         request.charset = 'utf8'
     stack = parse_path(request.path)
     model, unconsumed = self.model_lookup(request, self.root, stack)
     view = self.view_lookup(request, model, unconsumed)
     response = view(request, model)
     return response(environ, start_response)
示例#10
0
def test_resolve_no_consumers():
    lookup = ModelLookup()
    root = get_structure()

    request = webob.Request.blank('/a')
    stack = parse_path(request.path)
    obj, unconsumed = lookup(request, root, stack)

    assert obj is root
    assert list(unconsumed) == [(DEFAULT, 'a')]
示例#11
0
def test_resolve_no_consumers():
    lookup = ModelLookup()
    root = get_structure()

    request = webob.Request.blank(u'/a')
    stack = parse_path(request.path)
    obj, unconsumed = lookup(request, root, stack)

    assert obj is root
    assert unconsumed == [(DEFAULT, u'a')]
示例#12
0
def test_create_ns_weird_no_open():
    # a namespace that closes but doesn't open
    assert ([(DEFAULT, u'view++c'),
             (DEFAULT, u'b'),
             (DEFAULT, u'a')] ==
            parse_path(u'/a/b/view++c'))
示例#13
0
def test_parse_ns_weird_no_close():
    assert ([(DEFAULT, 'a'),
             (DEFAULT, 'b'),
             (DEFAULT, '++c')] ==
            list(parse_path('/a/b/++c')))
示例#14
0
def test_parse_ns_shortcut_not_at_beginning():
    # shortcuts should be at the beginning of a step to be recognized
    assert ([(DEFAULT, u'a@@c'),
             (DEFAULT, u'b'),
             (DEFAULT, u'a')] ==
            parse_path(u'/a/b/a@@c', shortcuts={u'@@': VIEW}))
示例#15
0
def test_create_ns_weird_no_close():
    assert ([(DEFAULT, u'++c'),
             (DEFAULT, u'b'),
             (DEFAULT, u'a')] ==
            parse_path(u'/a/b/++c'))
示例#16
0
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})))
示例#17
0
def test_parse_ns_shortcut():
    assert ([(VIEW, u'c'),
             (DEFAULT, u'b'),
             (DEFAULT, u'a')] ==
            parse_path(u'/a/b/@@c', shortcuts={u'@@': VIEW}))
示例#18
0
def test_parse_ns_weird_no_close():
    assert ([(DEFAULT, 'a'), (DEFAULT, 'b'),
             (DEFAULT, '++c')] == list(parse_path('/a/b/++c')))
示例#19
0
def test_multi_slash():
    assert parse_path(u'/a/b/c') == parse_path(u'/a///b//c')
    assert parse_path(u'/a/b/c') == parse_path(u'/a/b/c/')
示例#20
0
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')))
示例#21
0
def test_parse():
    """Parse a path to a stack, default namespaces.
    """
    assert ([(DEFAULT, 'a'), (DEFAULT, 'b'),
             (DEFAULT, 'c')] == list(parse_path('/a/b/c')))
示例#22
0
def test_parse_ns_shortcut():
    assert ([(DEFAULT, 'a'), (DEFAULT, 'b'), (VIEW, 'c')
             ] == list(parse_path('/a/b/@@c', shortcuts={'@@': VIEW})))
示例#23
0
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/')
示例#24
0
def test_parse_ns_shortcut():
    assert ([(DEFAULT, 'a'),
             (DEFAULT, 'b'),
             (VIEW, 'c')] ==
            list(parse_path('/a/b/@@c', shortcuts={'@@': VIEW})))
示例#25
0
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')))
示例#26
0
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')))