diff --git a/.github/workflows/python-integration.yml b/.github/workflows/python-integration.yml index 4c51f586..e5a52acc 100644 --- a/.github/workflows/python-integration.yml +++ b/.github/workflows/python-integration.yml @@ -37,8 +37,22 @@ jobs: cd multicorn2 git checkout v2.5 pip install . + - name: Start the Postgres service + run: | + docker-compose -f postgres/docker-compose.yml up --build -d + - name: Check if Postgres is ready + run: | + docker run --network container:postgres_postgres_1 postgres_postgres pg_isready \ + -h postgres \ + -p 5432 \ + -U shillelagh \ + --timeout=30 - name: Test with pytest env: SHILLELAGH_ADAPTER_KWARGS: ${{ secrets.SHILLELAGH_ADAPTER_KWARGS }} run: | pytest --cov-fail-under=100 --cov=src/shillelagh -vv tests/ --doctest-modules src/shillelagh --with-integration --with-slow-integration + - name: Stop the Postgres service + if: always() + run: | + docker-compose -f postgres/docker-compose.yml down diff --git a/README.rst b/README.rst index 65b1a3e3..fcc2a208 100644 --- a/README.rst +++ b/README.rst @@ -56,7 +56,7 @@ There is also an [experimental backend](https://shillelagh.readthedocs.io/en/lat from shillelagh.backends.multicorn.db import connect connection = connect( - username="username", + user="username", password="password", host="localhost", port=5432, diff --git a/tests/adapters/api/gsheets/integration_test.py b/tests/adapters/api/gsheets/integration_test.py index 6ff750b5..14f2478f 100644 --- a/tests/adapters/api/gsheets/integration_test.py +++ b/tests/adapters/api/gsheets/integration_test.py @@ -14,6 +14,7 @@ from shillelagh.adapters.api.gsheets.types import SyncMode from shillelagh.backends.apsw.db import connect +from shillelagh.backends.multicorn.db import connect as connect_multicorn @pytest.mark.skip("Credentials no longer valid") @@ -726,3 +727,59 @@ def test_weird_symbols(adapter_kwargs: Dict[str, Any]) -> None: assert cursor.fetchall() == [(1.0, "a", 45.0), (2.0, "b", 1999.0)] assert cursor.description is not None assert [column[0] for column in cursor.description] == ['foo"', '"bar', 'a"b'] + + +@pytest.mark.slow_integration_test +def test_public_sheet_apsw() -> None: + """ + Test reading values from a public sheet with APSW. + """ + table = ( + '"https://docs.google.com/spreadsheets/d/' + '1LcWZMsdCl92g7nA-D6qGRqg1T5TiHyuKJUY1u9XAnsk/edit#gid=0"' + ) + + connection = connect(":memory:") + cursor = connection.cursor() + sql = f"SELECT * FROM {table}" + cursor.execute(sql) + assert cursor.fetchall() == [ + ("BR", 2), + ("BR", 4), + ("ZA", 7), + ("CR", 11), + ("CR", 11), + ("FR", 100), + ("AR", 42), + ] + + +@pytest.mark.slow_integration_test +def test_public_sheet_multicorn() -> None: + """ + Test reading values from a public sheet with Multicorn2. + """ + table = ( + '"https://docs.google.com/spreadsheets/d/' + '1LcWZMsdCl92g7nA-D6qGRqg1T5TiHyuKJUY1u9XAnsk/edit#gid=0"' + ) + + connection = connect_multicorn( + user="shillelagh", + password="shillelagh123", + host="localhost", + port=12345, + database="shillelagh", + ) + cursor = connection.cursor() + sql = f"SELECT * FROM {table}" + cursor.execute(sql) + assert cursor.fetchall() == [ + ("BR", 2), + ("BR", 4), + ("ZA", 7), + ("CR", 11), + ("CR", 11), + ("FR", 100), + ("AR", 42), + ] diff --git a/tests/backends/multicorn/db_test.py b/tests/backends/multicorn/db_test.py index ea08c425..56e3e29b 100644 --- a/tests/backends/multicorn/db_test.py +++ b/tests/backends/multicorn/db_test.py @@ -27,7 +27,7 @@ def test_connect(mocker: MockerFixture, registry: AdapterLoader) -> None: connect( None, ["dummy"], - username="username", + user="username", password="password", host="host", port=1234, @@ -40,7 +40,7 @@ def test_connect(mocker: MockerFixture, registry: AdapterLoader) -> None: {}, "main", ), - username="username", + user="username", password="password", host="host", port=1234, @@ -60,7 +60,7 @@ def test_cursor_factory(mocker: MockerFixture) -> None: "main", ) assert cursor_factory( - username="username", + user="username", password="password", host="host", port=1234, @@ -69,7 +69,7 @@ def test_cursor_factory(mocker: MockerFixture) -> None: adapters=["dummy"], adapter_kwargs={}, schema="main", - username="username", + user="username", password="password", host="host", port=1234,