コード例 #1
0
 def test_sets_allow_none_for_nullable_fields(self, models):
     fields_ = fields_for_model(models.Student)
     assert fields_['dob'].allow_none is True
コード例 #2
0
 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')
コード例 #3
0
 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'
コード例 #4
0
 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
コード例 #5
0
 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_
コード例 #6
0
 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
コード例 #7
0
 def test_overridden_with_fk(self, models):
     graded_paper_fields = fields_for_model(models.GradedPaper, include_fk=False)
     assert "id" in graded_paper_fields
コード例 #8
0
 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
コード例 #9
0
    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
コード例 #10
0
    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
コード例 #11
0
 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"]
コード例 #12
0
 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"
     )
コード例 #13
0
 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
コード例 #14
0
    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
コード例 #15
0
 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
コード例 #16
0
    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
コード例 #17
0
 def test_none_length_validator_not_set(self, models):
     fields_ = fields_for_model(models.Course)
     assert not contains_validator(fields_["transcription"],
                                   validate.Length)