-
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
1 parent
bb154ae
commit 3906b00
Showing
4 changed files
with
61 additions
and
0 deletions.
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ alembic | |
asyncpg | ||
email-validator | ||
fastapi | ||
httpx | ||
pydantic-settings | ||
SQLAlchemy | ||
uvicorn[standard] | ||
|
Empty file.
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,49 @@ | ||
import asyncio | ||
from typing import AsyncGenerator | ||
|
||
import pytest | ||
#from fastapi.testclient import TestClient | ||
from httpx import AsyncClient | ||
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine, async_sessionmaker | ||
from sqlalchemy.orm import sessionmaker | ||
|
||
from app.core.dependencies import get_async_session | ||
from app.data.load_data import load_models_data | ||
from app.models.models import Base | ||
from app.core.config import settings | ||
from app.main import app | ||
|
||
engine_test = create_async_engine(settings.database_url, echo=True) | ||
AsyncSessionLocal = async_sessionmaker(engine_test, expire_on_commit=False) | ||
Base.metadata.bind = engine_test | ||
|
||
async def override_get_async_session() -> AsyncGenerator[AsyncSession, None]: | ||
async with AsyncSessionLocal() as session: | ||
yield session | ||
|
||
app.dependency_overrides[get_async_session] = override_get_async_session | ||
|
||
@pytest.fixture(autouse=True, scope='session') | ||
async def prepare_database(): | ||
async with engine_test.begin() as conn: | ||
await conn.run_sync(Base.metadata.drop_all) | ||
await conn.run_sync(Base.metadata.create_all) | ||
await load_models_data() | ||
yield | ||
|
||
# SETUP | ||
@pytest.fixture(scope='session') | ||
def event_loop(): | ||
loop = asyncio.get_event_loop_policy().new_event_loop() | ||
yield loop | ||
loop.close() | ||
|
||
#client = TestClient(app) | ||
|
||
@pytest.fixture(scope="session") | ||
async def ac() -> AsyncGenerator[AsyncClient, None]: | ||
async with AsyncClient( | ||
app=app, | ||
base_url="http://localhost/api/v1/hrspace" | ||
) as ac: | ||
yield ac |
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,11 @@ | ||
import pytest | ||
from httpx import AsyncClient | ||
|
||
import app.main | ||
from tests import conftest | ||
|
||
@pytest.mark.asyncio | ||
async def test_get_cities(ac: AsyncClient): | ||
params = {"id": 2, "name": "Москва"} | ||
response = await ac.get("/cities") | ||
assert response.status_code == 200 |