class AccountSchema(Schema): account_id = StringField() first_name = StringField() last_name = StringField() nick_name = StringField() #---------------------------------------------------------------------- @invariant def full_name_or_nick_name(self, first_name, last_name, nick_name): if (self.first_name.is_defined(first_name) or self.last_name.is_defined(last_name)) \ and self.nick_name.is_defined(nick_name): return 'Specify either full name or nick name'
class SubTestSchema(TestSchema): description = StringField()
class TestSchema(Schema): name = StringField()
class TestSchema(Schema): name = StringField(max_length=32) description = NillableField(StringField(min_length=1)) sub_object = NillableField(SchemaObjectField(SubTestSchema))
class SubTestSchema(Schema): name = StringField(max_length=32)
def test_list_validation_error_type(): field = ListField(StringField()) field.validate(FIELD_NAME, TEST_LIST_MIXED)
def test_list_validation_index_on_exception(): field = ListField(StringField()) try: field.validate(FIELD_NAME, TEST_LIST_MIXED) except ListFieldInvalidError as e: assert e.index == 1
def test_list_validation_success_empty(): field = ListField(StringField()) field.validate(FIELD_NAME, TEST_LIST_EMPTY)
def test_list_validation_success(): field = ListField(StringField()) field.validate(FIELD_NAME, TEST_LIST_STRINGS)
def test_string_validation_too_long(): field = StringField(max_length=3) field.validate(FIELD_NAME, TEST_STRING)
class AccountSchema(Schema): name = StringField()
def test_string_validation_too_short(): field = StringField(min_length=12) field.validate(FIELD_NAME, TEST_STRING)
def test_string_validation_success_w_all_checks(): field = StringField(min_length=3, max_length=12) field.validate(FIELD_NAME, TEST_STRING)
def test_string_validation_success_w_min_check(): field = StringField(min_length=3) field.validate(FIELD_NAME, TEST_STRING)
def test_string_validation_success_simple(): field = StringField() field.validate(FIELD_NAME, TEST_STRING)
class LoginSchema(Schema): name = StringField()