Mapepire-IBMi / mapepire-python

python client for mapepire
Apache License 2.0
4 stars 2 forks source link

pass .ini config file to SQLJob #60

Closed ajshedivy closed 3 days ago

ajshedivy commented 1 week ago

Fixes #

Changes proposed in this pull request:

def test_simple_cm():
    with SQLJob("~/.mapepire-test.ini", section="ossbuild") as job:
        with job.query("select * from sample.employee") as query:
            result = query.run(rows_to_fetch=5)

testing

Create a .mapepire-test.ini file in your home directory (the name and location does not matter, just needs to accessible by current user)

[ossbuild]
HOST=x
USER=x
PASSWORD=x
PORT=x

create a test file _test_config_ini.py in the tests directory (this file will be ignored by git), then paste in following code to test:

from mapepire_python import connect
from mapepire_python.client.sql_job import SQLJob

def test_simple():
    job = SQLJob()
    _ = job.connect("~/.mapepire-test.ini", section="ossbuild")
    query = job.query("select * from sample.employee")
    result = query.run(rows_to_fetch=5)
    job.close()
    assert result["success"] is True
    assert result["is_done"] is False
    assert result["has_results"] is True

def test_simple_cm():
    with SQLJob("~/.mapepire-test.ini", section="ossbuild") as job:
        with job.query("select * from sample.employee") as query:
            result = query.run(rows_to_fetch=5)
    assert result["success"] is True
    assert result["is_done"] is False
    assert result["has_results"] is True

def test_pep249_cm_fetchmany_ini():
    with connect("~/.mapepire-test.ini", section="ossbuild") as connection:
        with connection.execute("select * from sample.employee") as cur:
            res = cur.fetchmany(5)
            assert len(res["data"]) == 5

Before submitting