Skip to content

Commit

Permalink
fix: Let's use from psycopg import sql instead
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasfarias committed Nov 9, 2023
1 parent aaa29a2 commit dc1afc9
Showing 1 changed file with 7 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
from uuid import uuid4

import psycopg
import psycopg.sql
import pytest
import pytest_asyncio
from django.conf import settings
from django.test import override_settings
from psycopg import sql
from temporalio import activity
from temporalio.client import WorkflowFailureError
from temporalio.common import RetryPolicy
Expand Down Expand Up @@ -41,9 +41,7 @@ async def assert_events_in_postgres(connection, schema, table_name, events, excl

async with connection.cursor() as cursor:
await cursor.execute(
psycopg.sql.SQL("SELECT * FROM {} ORDER BY event, timestamp").format(
psycopg.sql.Identifier(schema, table_name)
)
sql.SQL("SELECT * FROM {} ORDER BY event, timestamp").format(sql.Identifier(schema, table_name))
)
columns = [column.name for column in cursor.description]

Expand Down Expand Up @@ -110,14 +108,12 @@ async def setup_test_db(postgres_config):

async with connection.cursor() as cursor:
await cursor.execute(
psycopg.sql.SQL("SELECT 1 FROM pg_database WHERE datname = %s"),
sql.SQL("SELECT 1 FROM pg_database WHERE datname = %s"),
(postgres_config["database"],),
)

if await cursor.fetchone() is None:
await cursor.execute(
psycopg.sql.SQL("CREATE DATABASE {}").format(psycopg.sql.Identifier(postgres_config["database"]))
)
await cursor.execute(sql.SQL("CREATE DATABASE {}").format(sql.Identifier(postgres_config["database"])))

await connection.close()

Expand All @@ -133,15 +129,13 @@ async def setup_test_db(postgres_config):

async with connection.cursor() as cursor:
await cursor.execute(
psycopg.sql.SQL("CREATE SCHEMA IF NOT EXISTS {}").format(psycopg.sql.Identifier(postgres_config["schema"]))
sql.SQL("CREATE SCHEMA IF NOT EXISTS {}").format(sql.Identifier(postgres_config["schema"]))
)

yield

async with connection.cursor() as cursor:
await cursor.execute(
psycopg.sql.SQL("DROP SCHEMA {} CASCADE").format(psycopg.sql.Identifier(postgres_config["schema"]))
)
await cursor.execute(sql.SQL("DROP SCHEMA {} CASCADE").format(sql.Identifier(postgres_config["schema"])))

await connection.close()

Expand All @@ -155,9 +149,7 @@ async def setup_test_db(postgres_config):
await connection.set_autocommit(True)

async with connection.cursor() as cursor:
await cursor.execute(
psycopg.sql.SQL("DROP DATABASE {}").format(psycopg.sql.Identifier(postgres_config["database"]))
)
await cursor.execute(sql.SQL("DROP DATABASE {}").format(sql.Identifier(postgres_config["database"])))

await connection.close()

Expand Down

0 comments on commit dc1afc9

Please sign in to comment.