mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2025-11-30 13:20:40 +03:00
move delete method to base class, minor api updates and code linting
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from uuid import UUID
|
||||
|
||||
import pytest
|
||||
from fastapi import status
|
||||
from httpx import AsyncClient
|
||||
@@ -11,10 +12,7 @@ pytestmark = pytest.mark.asyncio
|
||||
"payload, status_code",
|
||||
(
|
||||
(
|
||||
{
|
||||
"name": "motorhead",
|
||||
"description": "we play rock and roll"
|
||||
},
|
||||
{"name": "motorhead", "description": "we play rock and roll"},
|
||||
status.HTTP_201_CREATED,
|
||||
),
|
||||
),
|
||||
@@ -29,10 +27,7 @@ async def test_add_configuration(client: AsyncClient, payload: dict, status_code
|
||||
"payload, status_code",
|
||||
(
|
||||
(
|
||||
{
|
||||
"name": "motorhead",
|
||||
"description": "we play rock and roll"
|
||||
},
|
||||
{"name": "motorhead", "description": "we play rock and roll"},
|
||||
status.HTTP_200_OK,
|
||||
),
|
||||
),
|
||||
@@ -50,18 +45,15 @@ async def test_get_configuration(client: AsyncClient, payload: dict, status_code
|
||||
"payload, status_code",
|
||||
(
|
||||
(
|
||||
{
|
||||
"name": "motorhead",
|
||||
"description": "we play rock and roll"
|
||||
},
|
||||
{"name": "motorhead", "description": "we play rock and roll"},
|
||||
status.HTTP_200_OK,
|
||||
),
|
||||
),
|
||||
)
|
||||
async def test_delete_configuration(client: AsyncClient, payload: dict, status_code: int):
|
||||
response = await client.post("/v1/", json=payload)
|
||||
stuff_id = response.json()["id"]
|
||||
response = await client.delete(f"/v1/?stuff_id={stuff_id}")
|
||||
name = response.json()["name"]
|
||||
response = await client.delete(f"/v1/?name={name}")
|
||||
assert response.status_code == status_code
|
||||
|
||||
|
||||
@@ -69,10 +61,7 @@ async def test_delete_configuration(client: AsyncClient, payload: dict, status_c
|
||||
"payload, status_code",
|
||||
(
|
||||
(
|
||||
{
|
||||
"name": "motorhead",
|
||||
"description": "we play rock and roll"
|
||||
},
|
||||
{"name": "motorhead", "description": "we play rock and roll"},
|
||||
status.HTTP_200_OK,
|
||||
),
|
||||
),
|
||||
@@ -81,15 +70,14 @@ async def test_delete_configuration(client: AsyncClient, payload: dict, status_c
|
||||
"patch_payload, patch_status_code",
|
||||
(
|
||||
(
|
||||
{
|
||||
"name": "motorhead",
|
||||
"description": "we play loud"
|
||||
},
|
||||
{"name": "motorhead", "description": "we play loud"},
|
||||
status.HTTP_200_OK,
|
||||
),
|
||||
),
|
||||
)
|
||||
async def test_update_configuration(client: AsyncClient, payload: dict, status_code: int, patch_payload: dict, patch_status_code: int):
|
||||
async def test_update_configuration(
|
||||
client: AsyncClient, payload: dict, status_code: int, patch_payload: dict, patch_status_code: int
|
||||
):
|
||||
await client.post("/v1/", json=payload)
|
||||
name = payload["name"]
|
||||
response = await client.patch(f"/v1/?name={name}", json=patch_payload)
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
import pytest
|
||||
from httpx import AsyncClient
|
||||
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.ext.asyncio import create_async_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from sqlalchemy.pool import NullPool
|
||||
|
||||
from the_app.main import app
|
||||
from the_app import config
|
||||
from the_app.database import get_db
|
||||
from the_app.main import app
|
||||
from the_app.models.base import Base
|
||||
|
||||
from sqlalchemy.pool import NullPool
|
||||
|
||||
global_settings = config.get_settings()
|
||||
url = global_settings.asyncpg_test_url
|
||||
engine = create_async_engine(url, poolclass=NullPool)
|
||||
@@ -31,6 +28,7 @@ async def get_test_db():
|
||||
finally:
|
||||
await session.close()
|
||||
|
||||
|
||||
app.dependency_overrides[get_db] = get_test_db
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user