def multiple_bars_inserted(session): bar_1 = Bar(id=1, name='name_1', count=5) bar_2 = Bar(id=2, name='name_2', count=10) bar_3 = Bar(id=3, name='name_1', count=None) bar_4 = Bar(id=4, name='name_4', count=15) session.add_all([bar_1, bar_2, bar_3, bar_4]) session.commit()
def test_multiple_models(self, session): bar_1 = Bar(id=1, name='name_1', count=15) bar_2 = Bar(id=2, name='name_2', count=10) bar_3 = Bar(id=3, name='name_1', count=20) bar_4 = Bar(id=4, name='name_1', count=10) qux_1 = Qux(id=1, name='name_1', count=15, created_at=datetime.date(2016, 7, 12), execution_time=datetime.datetime(2016, 7, 12, 1, 5, 9)) qux_2 = Qux(id=2, name='name_2', count=10, created_at=datetime.date(2016, 7, 13), execution_time=datetime.datetime(2016, 7, 13, 2, 5, 9)) qux_3 = Qux(id=3, name='name_1', count=10, created_at=None, execution_time=None) qux_4 = Qux(id=4, name='name_1', count=20, created_at=datetime.date(2016, 7, 14), execution_time=datetime.datetime(2016, 7, 14, 3, 5, 9)) session.add_all( [bar_1, bar_2, bar_3, bar_4, qux_1, qux_2, qux_3, qux_4]) session.commit() query = session.query(Bar).join(Qux, Bar.id == Qux.id) order_by = [ { 'model': 'Bar', 'field': 'name', 'direction': 'asc' }, { 'model': 'Qux', 'field': 'count', 'direction': 'asc' }, ] sorted_query = apply_sort(query, order_by) results = sorted_query.all() assert len(results) == 4 assert results[0].id == 3 assert results[1].id == 1 assert results[2].id == 4 assert results[3].id == 2
def multiple_bars_inserted(session): bar_1 = Bar(id=1, name='name_1', count=5) bar_2 = Bar(id=2, name='name_2', count=10) bar_3 = Bar(id=3, name='name_1', count=None) bar_4 = Bar(id=4, name='name_4', count=12) bar_5 = Bar(id=5, name='name_1', count=2) bar_6 = Bar(id=6, name='name_4', count=15) bar_7 = Bar(id=7, name='name_1', count=2) bar_8 = Bar(id=8, name='name_5', count=1) session.add_all([bar_1, bar_2, bar_3, bar_4, bar_5, bar_6, bar_7, bar_8]) session.commit()