Example #1
0
    def test_ok_wo_order_by(self, model_manager: BaseModelManager, mocker: MockFixture):
        fake_sql = mocker.patch.object(model_manager, 'sql')
        mocked_get_sql = mocker.patch.object(model_manager, 'get_sql')

        model_manager.order_by()

        mocked_get_sql.assert_not_called()

        compared_sql = model_manager.sql

        assert compared_sql == fake_sql
Example #2
0
    def test_ok_with_order_by_desc(self, model_manager: BaseModelManager, mocker: MockFixture):
        fake_column_name = 'foo'
        fake_order_by = [OrderBy(field=fake_column_name, order='desc')]
        fake_column = mocker.Mock(desc=mocker.Mock())
        mocked_get_sql = mocker.patch.object(model_manager, 'get_sql')

        mocker.patch.object(model_manager, 'table', columns={fake_column_name: fake_column})

        model_manager.order_by(fake_order_by)

        mocked_get_sql.assert_called_once_with()
        assert model_manager.sql == mocked_get_sql.return_value.order_by.return_value
        mocked_get_sql.return_value.order_by.assert_called_once_with(fake_column.desc.return_value)