Beispiel #1
0
    def test_ok_wo_where_list(self, model_manager: BaseModelManager, mocker: MockFixture):
        mocked_get_sql = mocker.Mock()

        mocker.patch.object(model_manager, 'get_sql', mocked_get_sql)

        model_manager.where()

        mocked_get_sql.return_value.where.assert_not_called()
Beispiel #2
0
    def test_ok_wo_offset(self, model_manager: BaseModelManager, mocker: MockFixture):
        mocked_get_sql = mocker.patch.object(model_manager, 'get_sql')

        model_manager.limit()

        mocked_get_sql.return_value.limit.assert_called_once_with(None)

        compared_sql = model_manager.sql
        expected_sql = mocked_get_sql.return_value.limit.return_value

        assert compared_sql == expected_sql
Beispiel #3
0
    def test_ok_wo_offset(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.offset()

        mocked_get_sql.assert_not_called()

        compared_sql = model_manager.sql

        assert compared_sql == fake_sql
Beispiel #4
0
    def test_ok(self, model_manager: BaseModelManager, mocker: MockFixture):
        fake_values = {'foo': 'bar'}
        mocked_get_sql = mocker.patch.object(model_manager, 'get_sql')

        model_manager.values(**fake_values)

        mocked_get_sql.return_value.values.assert_called_once_with(**fake_values)

        compared_sql = model_manager.sql
        expected_sql = mocked_get_sql.return_value.values.return_value

        assert compared_sql == expected_sql
Beispiel #5
0
    def test_ok_with_offset(self, model_manager: BaseModelManager, mocker: MockFixture):
        fake_offset = 10
        mocked_get_sql = mocker.patch.object(model_manager, 'get_sql')

        model_manager.offset(fake_offset)

        mocked_get_sql.return_value.offset.assert_called_once_with(fake_offset)

        compared_sql = model_manager.sql
        expected_sql = mocked_get_sql.return_value.offset.return_value

        assert compared_sql == expected_sql
Beispiel #6
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)
Beispiel #7
0
    def test_ok_with_where_list(self, model_manager: BaseModelManager, mocker: MockFixture):
        fake_where_list = ['foo', 'bar']
        mocked_get_sql = mocker.Mock()

        mocker.patch.object(model_manager, 'get_sql', mocked_get_sql)
        mocker.patch.object(model_manager, 'sql')

        model_manager.where(fake_where_list)

        compared_sql = model_manager.sql
        expected_sql = mocked_get_sql.return_value.where.return_value

        calls = [mocker.call(where) for where in fake_where_list]
        mocked_get_sql.return_value.where.assert_has_calls(calls)

        assert compared_sql == expected_sql
Beispiel #8
0
    def test_ok(self, mocker: MockFixture):
        fake_table = mocker.Mock()
        fake_row_class = mocker.Mock()

        model_manager = BaseModelManager(fake_table, fake_row_class)

        assert model_manager.table == fake_table
        assert model_manager.row_class == fake_row_class
Beispiel #9
0
    def test_ok(self, mocker: MockFixture, model_manager: BaseModelManager):
        mocked_table = mocker.patch.object(model_manager, 'table')
        mocked_row_class = mocker.patch.object(model_manager, 'row_class')
        mocked_init = mocker.patch.object(BaseModelManager, '__init__', return_value=None)

        compared_instance = model_manager.new_instance()

        mocked_init.assert_called_once_with(table=mocked_table, row_class=mocked_row_class)
        assert isinstance(compared_instance, BaseModelManager)
Beispiel #10
0
    def test_ok(self, mocker: MockFixture, model_manager: BaseModelManager):
        mocked_transaction_cm_cls = mocker.patch('aiosqlalchemy_miniorm.orm._TransactionContextManager')
        mocked_new_instance = mocker.patch.object(model_manager, 'new_instance')

        compared_transaction_cm = model_manager.transaction()
        expected_transaction_cm = mocked_transaction_cm_cls.return_value

        assert compared_transaction_cm == expected_transaction_cm
        mocked_transaction_cm_cls.assert_called_once_with(mocked_new_instance.return_value)
Beispiel #11
0
def model_manager(mocker: MockFixture):
    fake_table = mocker.Mock()
    fake_row_class = mocker.Mock()

    return BaseModelManager(fake_table, fake_row_class)
Beispiel #12
0
    def test_ok(self, model_manager: BaseModelManager, mocker: MockFixture):
        fake_sql = mocker.Mock()

        model_manager.set_sql(fake_sql)

        assert model_manager.sql == fake_sql
Beispiel #13
0
    def test_error(self, model_manager: BaseModelManager, mocker: MockFixture):
        mocker.patch.object(model_manager, 'sql', None)

        with pytest.raises(AssertionError):
            model_manager.get_sql()
Beispiel #14
0
    def test_ok(self, model_manager: BaseModelManager, mocker: MockFixture):
        fake_sql = mocker.patch.object(model_manager, 'sql')

        compared_sql = model_manager.get_sql()

        assert compared_sql == fake_sql