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))
def test_parse(): """Parse a path to a stack, default namespaces. """ assert ([(DEFAULT, 'a'), (DEFAULT, 'b'), (DEFAULT, 'c')] == list(parse_path('/a/b/c')))
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'))
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'))
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')))
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')]
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)
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')]
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')]
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'))
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, u'a@@c'), (DEFAULT, u'b'), (DEFAULT, u'a')] == parse_path(u'/a/b/a@@c', shortcuts={u'@@': VIEW}))
def test_create_ns_weird_no_close(): assert ([(DEFAULT, u'++c'), (DEFAULT, u'b'), (DEFAULT, u'a')] == parse_path(u'/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 ([(VIEW, u'c'), (DEFAULT, u'b'), (DEFAULT, u'a')] == parse_path(u'/a/b/@@c', shortcuts={u'@@': VIEW}))
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/')
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_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/')
def test_parse_ns_shortcut(): assert ([(DEFAULT, 'a'), (DEFAULT, 'b'), (VIEW, 'c')] == list(parse_path('/a/b/@@c', shortcuts={'@@': VIEW})))