Skip to content

Commit

Permalink
Add tests for current Boolean validators
Browse files Browse the repository at this point in the history
  • Loading branch information
mlenzen committed Feb 6, 2020
1 parent 098fc12 commit fc32be9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ class Course(Model):
description = Column(sqla_types.Text, nullable=False)
level = Column(sqla_types.Enum('Primary', 'Secondary'))
has_prereqs = Column(sqla_types.Boolean, nullable=False)
boolean_nullable = Column(sqla_types.Boolean, nullable=True)
started = Column(sqla_types.DateTime, nullable=False)
grade = Column(AnotherInteger, nullable=False)

Expand Down Expand Up @@ -256,9 +257,14 @@ class Student(Model):
self.sess = Session()

def test_auto_validators(self):
course_form = model_form(self.Course, self.sess)()
student_form = model_form(self.Student, self.sess)()
assert contains_validator(student_form.dob, Optional)
assert contains_validator(student_form.full_name, Required)
assert not contains_validator(course_form.has_prereqs, Optional)
assert contains_validator(course_form.has_prereqs, Required)
assert contains_validator(course_form.boolean_nullable, Optional)
assert not contains_validator(course_form.boolean_nullable, Required)

def test_field_args(self):
shared = {'full_name': {'validators': [Regexp('test')]}}
Expand Down Expand Up @@ -303,7 +309,7 @@ def test_convert_basic(self):
self.assertRaises(ModelConversionError, model_form, self.Course)
form_class = model_form(self.Course, exclude=['students'])
form = form_class()
self.assertEqual(len(list(form)), 7)
self.assertEqual(len(list(form)), 8)

def test_only(self):
desired_fields = ['id', 'cost', 'description']
Expand All @@ -318,7 +324,7 @@ def test_no_mro(self):
self.assertRaises(ModelConversionError, model_form, self.Course, self.sess, converter=converter)
# If we exclude 'grade' everything should continue working
F = model_form(self.Course, self.sess, exclude=['grade'], converter=converter)
self.assertEqual(len(list(F())), 7)
self.assertEqual(len(list(F())), 8)


class ModelFormColumnDefaultTest(TestCase):
Expand Down

0 comments on commit fc32be9

Please sign in to comment.