Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
ewjoachim committed Jan 23, 2024
1 parent 4cfe76d commit 2442922
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions tests/integration/contrib/aiopg/test_aiopg_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import functools
import json

import asgiref.sync
import attr
import pytest

Expand All @@ -14,15 +15,16 @@
async def aiopg_connector_factory(connection_params):
connectors = []

async def _(**kwargs):
async def _(*, open: bool = True, **kwargs):
json_dumps = kwargs.pop("json_dumps", None)
json_loads = kwargs.pop("json_loads", None)
connection_params.update(kwargs)
connector = aiopg.AiopgConnector(
json_dumps=json_dumps, json_loads=json_loads, **connection_params
)
connectors.append(connector)
await connector.open_async()
if open:
await connector.open_async()
return connector

yield _
Expand Down Expand Up @@ -119,6 +121,24 @@ async def test_execute_query(aiopg_connector):
assert result == [{"obj_description": "foo"}]


async def test_get_sync_connector(aiopg_connector_factory):
result = []

aiopg_connector = await aiopg_connector_factory(open=False)

@asgiref.sync.sync_to_async
def f():
sync_conn = aiopg_connector.get_sync_connector()
sync_conn.open()
try:
result.append(sync_conn.execute_query_one("SELECT 1"))
finally:
sync_conn.close()

await f()
assert list(result[0].values()) == [1]


async def test_execute_query_interpolate(aiopg_connector):
result = await aiopg_connector.execute_query_one_async(
"SELECT %(foo)s as foo;", foo="bar"
Expand Down

0 comments on commit 2442922

Please sign in to comment.