def test_fix_urls(): transform = wiseguy.transforms.fix_urls() template = wiseguy.utils.MockObject(element=wiseguy.html.jade(''' html head link(href="/static/blueprint.css", type="text/css") link(href="../static/blueprint.css", type="text/css") script(src="/static/jquery.css") script(src="../static/jquery.css") body p img(src="/images/foo.png") img(src="images/foo.png") p a(href="/a_link.html?foo=bar") a(href="http://example.com?foo=bar") form(method="POST", action="/form_handler") form(method="POST", action="form_handler") ''')) assert transform.keys == set(['url']) transform.action(template=template, url=werkzeug.Href("/mountpoint")) expected = ''' <html> <head> <link href="/mountpoint/static/blueprint.css" type="text/css"> <link href="../static/blueprint.css" type="text/css"> <script src="/mountpoint/static/jquery.css"></script><script src="../static/jquery.css"></script> </head> <body> <p><img src="/mountpoint/images/foo.png"><img src="images/foo.png"></p> <p><a href="/mountpoint/a_link.html?foo=bar"></a><a href="http://example.com?foo=bar"></a></p> <form method="POST" action="/mountpoint/form_handler"></form> <form method="POST" action="form_handler"></form> </body> </html> '''.strip() result = template.element.to_string().strip() assert result == expected
def urlplus(url, params): return werkzeug.Href(url)(params or None)
# -*- coding: utf-8 -*- import unittest import lxml.html import werkzeug as wz from wiseguy import widgets url = wz.Href('/') item_url = wz.Href('/item_type') class TestPagination(unittest.TestCase): kwargs_filter = staticmethod(lambda context, **k: dict(offset=k['offset'])) def test_prev_li_disabled(self): context = dict(offset=0, limit=5) expected = ''' <li class="prev disabled"><a>← Previous</a></li> '''.strip() result = widgets.prev_li(context, item_url) result = lxml.html.tostring(result) assert expected == result def test_prev_li_enabled(self): context = dict(offset=1, limit=5) expected = ''' <li class="prev"><a href="/item_type?limit=5&offset=0">← Previous</a></li> '''.strip() result = widgets.prev_li(context, item_url)
def __init__(self, config, url_map, env): self.config = config self.env = env self.mountpoint = wz.Href(config.get('mountpoint', '/')) self.env.globals.update(dict(url=self.mountpoint)) self.url_map = make_url_map(self.mountpoint(), url_map)
def __init__(self, environ, **kwargs): super(self.__class__, self).__init__(environ) self.url = wz.Href("/submount")