예제 #1
0
def test_execute_select(mocked_connection, mocked_cursor, mocker):
    mocked_cursor.description = 1, 1, 1, 1, 1, 1, 1
    mocked_cursor.fetchall.side_effect = [((1, 'abc'),)]
    dummy = PostgreSQLJDBC(mocked_connection, transaction_id='123')
    dummy.use_database = mocker.Mock()
    assert dummy.execute(
        "select * from users", database_name='test'
    ) == ExecuteStatementResponse(
        numberOfRecordsUpdated=0,
        records=[[Field.from_value(1), Field.from_value('abc')]],
    )

    mocked_cursor.execute.assert_has_calls([mocker.call('select * from users')])
    mocked_cursor.close.assert_called_once_with()
예제 #2
0
def test_execute_select_with_include_metadata(mocked_connection, mocked_cursor, mocker):
    meta_mock = mocker.Mock()
    mocked_cursor._meta = meta_mock
    mocked_cursor.description = (1, 2, 3, 4, 5, 6, 7), (8, 9, 10, 11, 12, 13, 14)
    mocked_cursor.fetchall.side_effect = [((1, 'abc'),)]
    dummy = PostgreSQLJDBC(mocked_connection, transaction_id='123')
    dummy.use_database = mocker.Mock()
    create_column_metadata_set_mock = mocker.patch(
        'local_data_api.resources.jdbc.create_column_metadata_set'
    )
    create_column_metadata_set_mock.side_effect = [
        [
            ColumnMetadata(
                arrayBaseColumnType=0,
                isAutoIncrement=False,
                isCaseSensitive=False,
                isCurrency=False,
                isSigned=False,
                label=1,
                name=1,
                precision=5,
                scale=6,
                tableName=None,
                type=None,
                typeName=None,
            ),
            ColumnMetadata(
                arrayBaseColumnType=0,
                isAutoIncrement=False,
                isCaseSensitive=False,
                isCurrency=False,
                isSigned=False,
                label=8,
                name=8,
                precision=12,
                scale=13,
                tableName=None,
                type=None,
                typeName=None,
            ),
        ]
    ]

    assert dummy.execute(
        "select * from users", database_name='test', include_result_metadata=True
    ) == ExecuteStatementResponse(
        numberOfRecordsUpdated=0,
        records=[[Field.from_value(1), Field.from_value('abc')]],
        columnMetadata=[
            ColumnMetadata(
                arrayBaseColumnType=0,
                isAutoIncrement=False,
                isCaseSensitive=False,
                isCurrency=False,
                isSigned=False,
                label=1,
                name=1,
                precision=5,
                scale=6,
                tableName=None,
                type=None,
                typeName=None,
            ),
            ColumnMetadata(
                arrayBaseColumnType=0,
                isAutoIncrement=False,
                isCaseSensitive=False,
                isCurrency=False,
                isSigned=False,
                label=8,
                name=8,
                precision=12,
                scale=13,
                tableName=None,
                type=None,
                typeName=None,
            ),
        ],
    )

    create_column_metadata_set_mock.assert_called_once_with(meta_mock)
    mocked_cursor.execute.assert_has_calls([mocker.call('select * from users')])
    mocked_cursor.close.assert_called_once_with()