Exemple #1
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 #2
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 #3
0
def test_url_validator_schemes():
    v = URLValidator(allowed_schemes=(), blocked_scheme='X')
    el = scalar(u'http://*****:*****@there/path#fragment')
    assert not v.validate(el, None)
    eq_(el.errors, [u'X'])

    v = URLValidator(allowed_schemes=('https', ), blocked_scheme='X')
    el = scalar(u'http://*****:*****@there/path#fragment')
    assert not v.validate(el, None)
    eq_(el.errors, [u'X'])
Exemple #4
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'])
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"])
Exemple #6
0
def test_url_validator_parts():
    v = URLValidator(allowed_parts=(), blocked_part='X')
    el = scalar(u'http://*****:*****@there/path#fragment')
    assert not v.validate(el, None)
    eq_(el.errors, [u'X'])

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

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

    v = URLValidator(allowed_parts=('scheme', 'netloc'), blocked_part='X')
    el = scalar(u'http://blarg/')
    assert not v.validate(el, None)
    eq_(el.errors, [u'X'])
Exemple #7
0
def test_url_validator_default():
    v = URLValidator()
    el = scalar(u'http://*****:*****@there/path#fragment')
    assert v.validate(el, None)
    assert not el.errors
Exemple #8
0
        try:
            meta = json.loads(element.value)
        except:  # noqa - catch ANY exception that happens due to unserializing
            return self.note_error(element, state, 'invalid_json_msg')
        if not self.validnamespace(meta.get(NAMESPACE)):
            return self.note_error(element, state, 'invalid_namespace_msg')
        if state[FQNAME].field == ITEMID:
            if not self.validitemid(meta.get(ITEMID, state[FQNAME].value)):
                return self.note_error(element, state, 'invalid_itemid_msg')
        return True


JSON = OptionalMultilineText.with_properties(
    lang='en', dir='ltr').validated_by(ValidJSON())

URL = String.with_properties(widget=WIDGET_TEXT).validated_by(URLValidator())

Email = String.using(label=L_('E-Mail')).with_properties(
    widget=WIDGET_EMAIL,
    placeholder=L_("E-Mail address")).validated_by(IsEmail())

YourEmail = Email.with_properties(placeholder=L_("Your E-Mail address"))

Password = Text.with_properties(widget=WIDGET_PASSWORD).using(
    label=L_('Password'))

RequiredPassword = Password.validated_by(Present())

Checkbox = Boolean.with_properties(widget=WIDGET_CHECKBOX).using(optional=True,
                                                                 default=1)
Exemple #9
0
def test_url_validator_default():
    v = URLValidator()
    el = scalar('http://*****:*****@there/path#fragment')
    assert v.validate(el, None)
    assert not el.errors