Exemple #1
0
def test_url_canonicalizer_default():
    v = URLCanonicalizer()
    el = scalar("http://localhost/#foo")
    eq_(el.value, "http://localhost/#foo")

    assert v.validate(el, None)
    eq_(el.value, "http://localhost/")
    assert not el.errors
Exemple #2
0
def test_url_canonicalizer_want_all():
    v = URLCanonicalizer(discard_parts=())
    el = scalar("http://*****:*****@there/path#fragment")
    eq_(el.value, "http://*****:*****@there/path#fragment")

    assert v.validate(el, None)
    eq_(el.value, "http://*****:*****@there/path#fragment")
    assert not el.errors
Exemple #3
0
def test_http_validator_default():
    v = HTTPURLValidator(forbidden_part="X")
    el = scalar("http://there/path#fragment")
    assert v.validate(el, None)
    assert not el.errors

    el = scalar("http://*****:*****@there/path#fragment")
    not v.validate(el, None)
    eq_(el.errors, ["X"])
Exemple #4
0
def test_url_validator_schemes():
    v = URLValidator(allowed_schemes=(), blocked_scheme="X")
    el = scalar("http://*****:*****@there/path#fragment")
    assert not v.validate(el, None)
    eq_(el.errors, ["X"])

    v = URLValidator(allowed_schemes=("https",), blocked_scheme="X")
    el = scalar("http://*****:*****@there/path#fragment")
    assert not v.validate(el, None)
    eq_(el.errors, ["X"])
Exemple #5
0
def test_url_validator_parts():
    v = URLValidator(allowed_parts=(), blocked_part="X")
    el = scalar("http://*****:*****@there/path#fragment")
    assert not v.validate(el, None)
    eq_(el.errors, ["X"])

    v = URLValidator(allowed_parts=_url_parts)
    el = scalar("http://*****:*****@there/path#fragment")
    assert v.validate(el, None)
    assert not el.errors

    v = URLValidator(allowed_parts=("scheme", "netloc"))
    el = scalar("http://blarg")
    assert v.validate(el, None)
    assert not el.errors

    v = URLValidator(allowed_parts=("scheme", "netloc"), blocked_part="X")
    el = scalar("http://blarg/")
    assert not v.validate(el, None)
    eq_(el.errors, ["X"])