Beispiel #1
0
    def test_it(self):
        from asobibi.exceptions import ValidationError
        from asobibi.translations import SystemMessage, DisplayMessage
        from asobibi.construct import ErrorList

        SystemMessage("unicode", fmt="{value} is not strict unicode.", mapping={"value": "----"})
        DisplayMessage("unicode", fmt=u"入力してください {field}", mapping={"field": "----"})

        def strict_unicode(name, x):
            if x is None or x == "":
                raise ValidationError({"name": "unicode", "field": name, "value": x})

        from asobibi import schema, field
        StrictUnicode = field(converters=[strict_unicode])
        Person = schema("Person", [StrictUnicode("first_name"), StrictUnicode("last_name")])

        person = Person()
        self.assertFalse(person.validate())
        self.assertEquals(str(person.errors),
                          str(ErrorList({'first_name': ['first_name is Missing.'],
                                         'last_name': ['last_name is Missing.']})))
        self.assertEquals(unicode(person.errors),
                          unicode(ErrorList({'first_name': [u'first_name がみつかりません'],
                                             'last_name': [u'last_name がみつかりません']})))

        person = Person(first_name="test", last_name="")
        self.assertFalse(person.validate())
        self.assertEquals(str(person.errors),
                          str(ErrorList({'last_name': [' is not strict unicode.']})))

        self.assertEquals(unicode(person.errors),
                          unicode(ErrorList({"last_name": [u"入力してください last_name"]})))
Beispiel #2
0
# validation definition


def tiny_email(k, x):
    if not "@" in x:
        params = dict(field=k, value=x, fmt="{field} is not email address")
        raise ValidationError(params)
    return x


@c.validation_from_condition
def not_empty(x):
    return x != ""

Unicode = field(converters=[c.Unicode, not_empty])


# schema definition

Submit = schema(
    "Submit",
    (Unicode("mail", initial="sample@mail", converters=[tiny_email]),
     Unicode("password"),
     Unicode("confirm")
     ))


submit = Submit(mail="foo", password="******", confirm="@")
assert submit.validate() == False
Beispiel #3
0
        params = dict(field=k, value=x, fmt="{field} is not email address")
        raise ValidationError(params)
    return x


@c.validation_from_condition
def not_empty(x):
    return x != ""


def same(k, x, y):
    assert x == y


# Field Definition
UnicodeField = field(converters=[c.Unicode, not_empty])


# Schema Definition
@as_schema()
class Submit(object):
    mail = column(UnicodeField, initial="sample@mail", converters=[tiny_email])
    password = column(UnicodeField)
    confirm = column(UnicodeField)


@as_schema()
class Submit2(object):
    mail = column(UnicodeField, initial="sample@mail", converters=[tiny_email])
    password = column(UnicodeField, required=False)
    confirm = column(UnicodeField, required=False)