Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kaziamov committed Jan 8, 2025
1 parent ed0c0f6 commit 1866e81
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 1 deletion.
4 changes: 4 additions & 0 deletions simplecrud/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
from . import crud

from .asyncpg_commands.cruds import insert_to_table


1 change: 0 additions & 1 deletion simplecrud/crud.py
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
Expand Down
File renamed without changes.
40 changes: 40 additions & 0 deletions tests/test_asyncpg/test_crud.py
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)]
6 changes: 6 additions & 0 deletions tests/test_postgres_scheme.sql
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.

0 comments on commit 1866e81

Please sign in to comment.