-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
from . import crud | ||
|
||
from .asyncpg_commands.cruds import insert_to_table | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import logging | ||
from typing import Dict, List | ||
|
||
from sqlalchemy import select, delete | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import os | ||
|
||
import psycopg2 | ||
import pytest | ||
|
||
from asyncpg import connect | ||
from dotenv import load_dotenv | ||
|
||
load_dotenv() | ||
|
||
from simplecrud import insert_to_table | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def database_url(): | ||
return os.getenv("TEST_DATABASE_URL") | ||
|
||
@pytest.fixture(autouse=True) | ||
def table(): | ||
with psycopg2.connect(os.getenv("TEST_DATABASE_URL")) as pg_conn: | ||
cur = pg_conn.cursor() | ||
table = "test_table" | ||
cur.execute(f"CREATE TABLE {table} (id SERIAL PRIMARY KEY, name TEXT, age INT)") | ||
pg_conn.commit() | ||
yield table | ||
cur.execute(f"DROP TABLE {table}") | ||
pg_conn.commit() | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_insert_to_table(database_url): | ||
data = {"name": "test", "age": 20} | ||
table = "test_table" | ||
conn = connect(dsn=database_url) | ||
await insert_to_table(conn, table, data) | ||
with psycopg2.connect(database_url) as pg_conn: | ||
cur = pg_conn.cursor() | ||
cur.execute(f"SELECT * FROM {table}") | ||
result = cur.fetchall() | ||
assert result == [(1, "test", 20)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE TABLE test_table ( | ||
id SERIAL PRIMARY KEY, | ||
name VARCHAR(255) NOT NULL, | ||
age INT NOT NULL, | ||
created_at TIMESTAMP NOT NULL DEFAULT NOW(), | ||
); |
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.