Working factories
This commit is contained in:
@ -2,40 +2,30 @@
|
||||
# https://coderpad.io/blog/development/a-guide-to-database-unit-testing-with-pytest-and-sqlalchemy/
|
||||
|
||||
import pytest
|
||||
from sqlalchemy import text, event
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker
|
||||
from sqlalchemy import text
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.domain.city import City
|
||||
from app.lib import settings
|
||||
from app.lib.sqlalchemy_plugin import engine
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
import sqlalchemy
|
||||
from sqlalchemy.ext.asyncio import (
|
||||
AsyncSession,
|
||||
create_async_engine,
|
||||
async_scoped_session,
|
||||
AsyncConnection,
|
||||
)
|
||||
from tests.factories.city_factory import CityFactory
|
||||
|
||||
|
||||
class TestGeneral:
|
||||
@pytest.fixture(scope="function", autouse=True)
|
||||
def setup_class(self, db_session):
|
||||
def setup_class(self, db_session: AsyncSession):
|
||||
self.db_session = db_session
|
||||
|
||||
# async def teardown_class(self):
|
||||
# await self.session.rollback()
|
||||
# await self.session.close()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_bla(self):
|
||||
async def test_get_cities(self):
|
||||
city_1 = await CityFactory.create()
|
||||
city_2 = await CityFactory.create()
|
||||
city_3 = await CityFactory.create()
|
||||
city_4 = await CityFactory.create()
|
||||
city_5 = await CityFactory.create()
|
||||
|
||||
stmt = text("select * from cities")
|
||||
result = await self.db_session.execute(stmt)
|
||||
print("#"*100)
|
||||
print("#" * 100)
|
||||
for c in result:
|
||||
print(c)
|
||||
print("#"*100)
|
||||
print("#" * 100)
|
||||
|
||||
assert True
|
||||
|
||||
Reference in New Issue
Block a user