def test_sets_allow_none_for_nullable_fields(self, models): fields_ = fields_for_model(models.Student) assert fields_['dob'].allow_none is True
def test_sets_enum_choices(self, models): fields_ = fields_for_model(models.Course) validator = contains_validator(fields_['level'], validate.OneOf) assert validator assert validator.choices == ('Primary', 'Secondary')
def test_fields_for_model_saves_doc(self, models): fields_ = fields_for_model(models.Student, include_fk=True) assert fields_['date_created'].metadata[ 'description'] == 'date the student was created'
def test_length_validator_set(self, models): fields_ = fields_for_model(models.Student) validator = contains_validator(fields_['full_name'], validate.Length) assert validator assert validator.max == 255
def test_fields_for_model_handles_exclude(self, models): fields_ = fields_for_model(models.Student, exclude=('dob', )) assert type(fields_['id']) is fields.Int assert type(fields_['full_name']) is fields.Str assert 'dob' not in fields_
def test_fields_for_model_handles_custom_types(self, models): fields_ = fields_for_model(models.Course, include_fk=True) assert type(fields_['grade']) is fields.Int
def test_overridden_with_fk(self, models): graded_paper_fields = fields_for_model(models.GradedPaper, include_fk=False) assert "id" in graded_paper_fields
def test_fields_for_model_handles_exclude(self, models): fields_ = fields_for_model(models.Student, exclude=("dob",)) assert type(fields_["id"]) is fields.Int assert type(fields_["full_name"]) is fields.Str assert fields_["dob"] is None
def test_many_to_many_relationship(self, models): student_fields = fields_for_model(models.Student) assert type(student_fields["courses"]) is RelatedList course_fields = fields_for_model(models.Course) assert type(course_fields["students"]) is RelatedList
def test_include_fk(self, models): student_fields = fields_for_model(models.Student, include_fk=False) assert "current_school_id" not in student_fields student_fields2 = fields_for_model(models.Student, include_fk=True) assert "current_school_id" in student_fields2
def test_sets_enum_choices(self, models): fields_ = fields_for_model(models.Course) validator = contains_validator(fields_["level"], validate.OneOf) assert validator assert list(validator.choices) == ["Primary", "Secondary"]
def test_fields_for_model_saves_doc(self, models): fields_ = fields_for_model(models.Student, include_fk=True) assert ( fields_["date_created"].metadata["description"] == "date the student was created" )
def test_fields_for_model_handles_custom_types(self, models): fields_ = fields_for_model(models.Course, include_fk=True) assert type(fields_["grade"]) is fields.Int assert type(fields_["transcription"]) is fields.Str
def test_many_to_many_relationship(self, models): student_fields = fields_for_model(models.Student) assert type(student_fields['courses']) is fields.List course_fields = fields_for_model(models.Course) assert type(course_fields['students']) is fields.List
def test_info_overrides(self, models): fields_ = fields_for_model(models.Course) field = fields_["description"] validator = contains_validator(field, validate.Length) assert validator.max == 1000 assert field.required
def test_many_to_one_relationship(self, models): student_fields = fields_for_model(models.Student) assert type(student_fields['current_school']) is Related school_fields = fields_for_model(models.School) assert type(school_fields['students']) is fields.List
def test_none_length_validator_not_set(self, models): fields_ = fields_for_model(models.Course) assert not contains_validator(fields_["transcription"], validate.Length)