示例#1
0
文件: reverse.py 项目: riffm/iktomi
 def test_subdomains_and_cases(self):
     "Locations of web.cases with subdomains"
     chain = web.subdomain("news") | web.cases(web.match("/", "index"), web.match("/docs", "docs"))
     for k in ("index", "docs"):
         self.assert_(web.locations(chain).keys(), [k])
         self.assert_(web.locations(chain)[k][0].subdomains)
         self.assertEqual(web.locations(chain)[k][0].subdomains, ["news"])
示例#2
0
文件: reverse.py 项目: riffm/iktomi
 def test_prefix_and_cases(self):
     "Locations of web.cases with prefix"
     chain = web.prefix("/news") | web.cases(web.match("/", "index"), web.match("/docs", "docs"))
     for k in ("index", "docs"):
         self.assert_(web.locations(chain).keys(), [k])
         self.assert_(web.locations(chain)[k][0].builders)
         self.assertEqual(len(web.locations(chain)[k][0].builders), 2)
示例#3
0
文件: reverse.py 项目: riffm/iktomi
 def test_mix(self):
     "Loactions mix"
     chain = web.prefix("/items") | web.cases(
         web.match("/"),
         web.prefix("/news")
         | web.namespace("news")
         | web.cases(
             web.match("/"),
             web.match("/<int:id>", "item"),
             web.prefix("/docs") | web.namespace("docs") | web.cases(web.match("/"), web.match("/<int:id>", "item")),
         ),
     )
     locations = web.locations(chain)
     self.assertEqual(locations.keys(), ["", "news"])
     self.assertEqual(locations[""][0], Location(*(UrlTemplate("/items", match_whole_str=False), UrlTemplate("/"))))
     self.assertEqual(
         locations["news"][0],
         Location(*(UrlTemplate("/items", match_whole_str=False), UrlTemplate("/news", match_whole_str=False))),
     )
     self.assertEqual(locations["news"][1][""][0], Location(UrlTemplate("/")))
     self.assertEqual(locations["news"][1]["item"][0], Location(UrlTemplate("/<int:id>")))
     self.assertEqual(locations["news"][1]["docs"][0], Location(UrlTemplate("/docs", match_whole_str=False)))
     self.assertEqual(locations["news"][1]["docs"][1][""][0], Location(UrlTemplate("/")))
     self.assertEqual(locations["news"][1]["docs"][1]["item"][0], Location(UrlTemplate("/<int:id>")))
示例#4
0
文件: app.py 项目: riffm/iktomi
import handlers as h

static = static_files(cfg.STATIC)
media = static_files(cfg.MEDIA, '/media/')
template = Template(cfg.TEMPLATES, jinja2.TEMPLATE_DIR, engines={'html': jinja2.TemplateEngine})


@web.request_filter
def environment(env, data, next_handler):
    env.cfg = cfg

    env.url_for = url_for
    env.url_for_static = static.construct_reverse()
    env.template = template

    return next_handler(env, data)



app = environment | web.cases(
    static, media,
    match('/', 'files') | web.cases(
        # Playing REST ;)
        method('GET') | h.list_files,
        method('POST') | h.post_file,
        #method('DELETE') | h.delete_files,
    ),
)

url_for = web.Reverse(web.locations(app))
示例#5
0
文件: reverse.py 项目: riffm/iktomi
 def test_subdomain(self):
     "Locations and subdomains"
     chain = web.subdomain("news") | web.match("/", "index")
     self.assert_(web.locations(chain).keys(), ["index"])
     self.assert_(web.locations(chain)["index"][0].subdomains)
     self.assertEqual(web.locations(chain)["index"][0].subdomains, ["news"])
示例#6
0
文件: reverse.py 项目: riffm/iktomi
 def test_namespace_with_empty_name(self):
     "Namespaces with empty url name"
     chain = web.namespace("news") | web.match("/")
     self.assert_(web.locations(chain).keys(), ["news"])
示例#7
0
文件: reverse.py 项目: riffm/iktomi
 def test_namespace_and_cases(self):
     "Locations namespace with web.cases"
     chain = web.namespace("news") | web.cases(web.match("/", "index"), web.match("/docs", "docs"))
     self.assertEqual(web.locations(chain).keys(), ["news"])
     self.assertEqual(web.locations(chain)["news"][1].keys(), ["index", "docs"])
示例#8
0
文件: reverse.py 项目: riffm/iktomi
 def test_namespace(self):
     "Locations namespace"
     chain = web.namespace("news") | web.match("/", "index")
     self.assert_(web.locations(chain).keys(), ["news.index"])
示例#9
0
文件: reverse.py 项目: riffm/iktomi
 def test_prefix(self):
     "Locations of web.match with prefix"
     chain = web.prefix("/news") | web.match("/", "index")
     self.assert_(web.locations(chain).keys(), ["index"])
     self.assert_(web.locations(chain)["index"][0].builders)
     self.assertEqual(len(web.locations(chain)["index"][0].builders), 2)
示例#10
0
文件: reverse.py 项目: riffm/iktomi
 def test_nested_cases(self):
     "Locations of nested web.cases"
     chain = web.cases(web.match("/", "index"), web.cases(web.match("/docs", "docs")))
     self.assert_(web.locations(chain).keys(), ["index", "docs"])
示例#11
0
文件: reverse.py 项目: riffm/iktomi
 def test_match_dublication(self):
     "Raise error on same url names"
     self.assertRaises(
         ValueError, lambda: web.locations(web.cases(web.match("/", "index"), web.match("/index", "index")))
     )
示例#12
0
文件: reverse.py 项目: riffm/iktomi
 def test_match(self):
     "Locations of web.match"
     self.assert_(web.locations(web.match("/", "name")).keys(), ["name"])
示例#13
0
文件: reverse.py 项目: riffm/iktomi
 def test_function(self):
     "Reverse working with chained functions"
     app = web.cases(
         web.match("/", "index") | (lambda e, d: None), web.prefix("/xx") | (lambda e, d: None), (lambda e, d: None)
     )
     self.assertEqual(web.locations(app).keys(), ["index"])