def test_filter_ref_and_condition(self, Student):
     student = Student.filter(
         and_(
             ref('id') == self.student1.id,
             ref('name') == self.student1.name
         )
     ).one()
     assert student.id == self.student1.id
 def test_filter_by_or_condition(self, Student):
     students = Student.filter(or_(
         ref('id') == self.student1.id,
         ref('name') == self.student2.name
     )).all()
     assert len(students) == 2
     assert self.get(students, 'id', self.student1.id) is not None
     assert self.get(students, 'id', self.student2.id) is not None
예제 #3
0
 def test_filter_by_ref_column(self, Student):
     student = Student.serialize(
         to_return=['id'],
         filter_by=and_(*[
             ref('id') == self.student1.id,
             ref('name') == self.student1.name
         ]),
         expose_all=True
     )
     assert len(student) == 1
     assert student[0]['id'] == self.student1.id
 def test_filter_ref_case(self, Student):
     assert len(Student.filter(
         case([(
             ref('created') <=
             func.now() - func.cast('2 YEARS', INTERVAL),
             'senior'
         ), (
             ref('created') <=
             func.now() - func.cast('1 YEAR', INTERVAL),
             'junior'
         )], else_='freshman') == 'freshman'
     ).all()) == 3
 def test_filter_ref_concurrent_and_conditions(self, Teacher):
     assert Teacher.filter(
         or_(
             and_(
                 ref('students.id') == self.student1.id,
                 ref('students.name') == self.student1.name
             ),
             and_(
                 ref('students.id') == self.student2.id,
                 ref('students.name') == self.student2.name
             )
         )
     ).one().id == self.teacher1.id
 def test_filter_ref_to_many_relationship(self, Teacher):
     assert Teacher.filter(
         ref('students.id') == self.student1.id
     ).one().id == self.teacher1.id
 def test_filter_ref(self, Student):
     assert Student.filter(
         ref('id') == self.student1.id
     ).one().id == self.student1.id
 def test_filter_ref_func(self, Student):
     assert Student.filter(
         ref('created') <= func.now()
     ).first() is not None
 def test_filter_ref_in(self, Student):
     assert Student.filter(
         ref('id').in_([self.student1.id, self.student2.id])
     ).first() is not None