Ejemplo n.º 1
0
    def test_href(self):
        x = urls.Href('http://www.example.com/')
        self.assert_strict_equal(x(u'foo'), 'http://www.example.com/foo')
        self.assert_strict_equal(x.foo(u'bar'), 'http://www.example.com/foo/bar')
        self.assert_strict_equal(x.foo(u'bar', x=42), 'http://www.example.com/foo/bar?x=42')
        self.assert_strict_equal(x.foo(u'bar', class_=42), 'http://www.example.com/foo/bar?class=42')
        self.assert_strict_equal(x.foo(u'bar', {u'class': 42}), 'http://www.example.com/foo/bar?class=42')
        self.assert_raises(AttributeError, lambda: x.__blah__)

        x = urls.Href('blah')
        self.assert_strict_equal(x.foo(u'bar'), 'blah/foo/bar')

        self.assert_raises(TypeError, x.foo, {u"foo": 23}, x=42)

        x = urls.Href('')
        self.assert_strict_equal(x('foo'), 'foo')
Ejemplo n.º 2
0
def test_href():
    x = urls.Href("http://www.example.com/")
    strict_eq(x(u"foo"), "http://www.example.com/foo")
    strict_eq(x.foo(u"bar"), "http://www.example.com/foo/bar")
    strict_eq(x.foo(u"bar", x=42), "http://www.example.com/foo/bar?x=42")
    strict_eq(x.foo(u"bar", class_=42), "http://www.example.com/foo/bar?class=42")
    strict_eq(x.foo(u"bar", {u"class": 42}), "http://www.example.com/foo/bar?class=42")
    pytest.raises(AttributeError, lambda: x.__blah__)

    x = urls.Href("blah")
    strict_eq(x.foo(u"bar"), "blah/foo/bar")

    pytest.raises(TypeError, x.foo, {u"foo": 23}, x=42)

    x = urls.Href("")
    strict_eq(x("foo"), "foo")
Ejemplo n.º 3
0
def test_href():
    x = urls.Href("http://www.example.com/")
    assert x("foo") == "http://www.example.com/foo"
    assert x.foo("bar") == "http://www.example.com/foo/bar"
    assert x.foo("bar", x=42) == "http://www.example.com/foo/bar?x=42"
    assert x.foo("bar", class_=42) == "http://www.example.com/foo/bar?class=42"
    assert x.foo("bar", {"class": 42}) == "http://www.example.com/foo/bar?class=42"
    pytest.raises(AttributeError, lambda: x.__blah__)

    x = urls.Href("blah")
    assert x.foo("bar") == "blah/foo/bar"

    pytest.raises(TypeError, x.foo, {"foo": 23}, x=42)

    x = urls.Href("")
    assert x("foo") == "foo"
Ejemplo n.º 4
0
    def test_href(self):
        x = urls.Href('http://www.example.com/')
        assert x('foo') == 'http://www.example.com/foo'
        assert x.foo('bar') == 'http://www.example.com/foo/bar'
        assert x.foo('bar', x=42) == 'http://www.example.com/foo/bar?x=42'
        assert x.foo('bar', class_=42) == 'http://www.example.com/foo/bar?class=42'
        assert x.foo('bar', {'class': 42}) == 'http://www.example.com/foo/bar?class=42'
        self.assert_raises(AttributeError, lambda: x.__blah__)

        x = urls.Href('blah')
        assert x.foo('bar') == 'blah/foo/bar'

        self.assert_raises(TypeError, x.foo, {"foo": 23}, x=42)

        x = urls.Href('')
        assert x('foo') == 'foo'
Ejemplo n.º 5
0
def test_href_past_root():
    base_href = urls.Href('http://www.blagga.com/1/2/3')
    strict_eq(base_href('../foo'), 'http://www.blagga.com/1/2/foo')
    strict_eq(base_href('../../foo'), 'http://www.blagga.com/1/foo')
    strict_eq(base_href('../../../foo'), 'http://www.blagga.com/foo')
    strict_eq(base_href('../../../../foo'), 'http://www.blagga.com/foo')
    strict_eq(base_href('../../../../../foo'), 'http://www.blagga.com/foo')
    strict_eq(base_href('../../../../../../foo'), 'http://www.blagga.com/foo')
Ejemplo n.º 6
0
 def test_href_past_root(self):
     base_href = urls.Href('http://www.blagga.com/1/2/3')
     self.assert_strict_equal(base_href('../foo'), 'http://www.blagga.com/1/2/foo')
     self.assert_strict_equal(base_href('../../foo'), 'http://www.blagga.com/1/foo')
     self.assert_strict_equal(base_href('../../../foo'), 'http://www.blagga.com/foo')
     self.assert_strict_equal(base_href('../../../../foo'), 'http://www.blagga.com/foo')
     self.assert_strict_equal(base_href('../../../../../foo'), 'http://www.blagga.com/foo')
     self.assert_strict_equal(base_href('../../../../../../foo'), 'http://www.blagga.com/foo')
Ejemplo n.º 7
0
def test_href_past_root():
    base_href = urls.Href("http://www.blagga.com/1/2/3")
    assert base_href("../foo") == "http://www.blagga.com/1/2/foo"
    assert base_href("../../foo") == "http://www.blagga.com/1/foo"
    assert base_href("../../../foo") == "http://www.blagga.com/foo"
    assert base_href("../../../../foo") == "http://www.blagga.com/foo"
    assert base_href("../../../../../foo") == "http://www.blagga.com/foo"
    assert base_href("../../../../../../foo") == "http://www.blagga.com/foo"
Ejemplo n.º 8
0
def test_href_past_root():
    base_href = urls.Href("http://www.blagga.com/1/2/3")
    strict_eq(base_href("../foo"), "http://www.blagga.com/1/2/foo")
    strict_eq(base_href("../../foo"), "http://www.blagga.com/1/foo")
    strict_eq(base_href("../../../foo"), "http://www.blagga.com/foo")
    strict_eq(base_href("../../../../foo"), "http://www.blagga.com/foo")
    strict_eq(base_href("../../../../../foo"), "http://www.blagga.com/foo")
    strict_eq(base_href("../../../../../../foo"), "http://www.blagga.com/foo")
Ejemplo n.º 9
0
 def test_href_past_root(self):
     base_href = urls.Href('http://www.blagga.com/1/2/3')
     assert base_href('../foo') == 'http://www.blagga.com/1/2/foo'
     assert base_href('../../foo') == 'http://www.blagga.com/1/foo'
     assert base_href('../../../foo') == 'http://www.blagga.com/foo'
     assert base_href('../../../../foo') == 'http://www.blagga.com/foo'
     assert base_href('../../../../../foo') == 'http://www.blagga.com/foo'
     assert base_href('../../../../../../foo') == 'http://www.blagga.com/foo'
Ejemplo n.º 10
0
    def create_view_path(self, include_request_args=False):
        """Construct view path from request.path with option to include GET
        args.
        """
        href = urls.Href(request.path)

        if include_request_args:
            ignored = current_app.config['CARAFE_CACHE_IGNORED_REQUEST_ARGS']
            args = dict(
                (k, v) for k, v in request.args.lists() if k not in ignored)
        else:
            args = None

        return href(args)
Ejemplo n.º 11
0
def test_href_url_join():
    x = urls.Href(u'test')
    assert x(u'foo:bar') == u'test/foo:bar'
    assert x(u'http://example.com/') == u'test/http://example.com/'
    assert x.a() == u'test/a'
Ejemplo n.º 12
0
 def test_href_url_join(self):
     x = urls.Href(u'test')
     self.assert_line_equal(x(u'foo:bar'), u'test/foo:bar')
     self.assert_line_equal(x(u'http://example.com/'), u'test/http://example.com/')
     self.assert_line_equal(x.a(), u'test/a')
Ejemplo n.º 13
0
def test_href_url_join():
    x = urls.Href("test")
    assert x("foo:bar") == "test/foo:bar"
    assert x("http://example.com/") == "test/http://example.com/"
    assert x.a() == "test/a"
Ejemplo n.º 14
0
 def test_href_url_join(self):
     x = urls.Href('test')
     assert x('foo:bar') == 'test/foo:bar'
     assert x('http://example.com/') == 'test/http://example.com/'
Ejemplo n.º 15
0
    def get(self, url, params=None, **kargs):
        """Wrap get request with URL params support."""
        if params:
            url = urls.Href(url)(params)

        return super(Client, self).get(url, **kargs)
Ejemplo n.º 16
0
def make_arg_url(base_url, arg_dict):
    with_args = wurls.Href(base_url)
    return with_args(arg_dict)