# from sqlmodel import select
from app.src.db.engine import get_db
from sqlmodel import Session, select
from app.src.db.manager import create_table
from app.src.models.db.product import Product
from app.src.models.db.product_type import ProductType
from app.src.models.db.tag import Tag


def test_data():

    # create the tables (come renderle dipendenti da una sessione)
    engine = get_db()
    create_table()

    with Session(engine) as session:
        # define data
        type_panini = ProductType(name="Panino", description="Tutto ciò che è panino")
        cibo_tag = Tag(name="cibo")
        panino = Product(
            name="panino",
            description="panino buono",
            price=3.30,
            available=True,
            product_type=type_panini,
            tags=[cibo_tag],
        )
        kebab = Product(
            name="kebab",
            description="senza cipolla",
            price=4,
            available=True,
            product_type=type_panini,
            tags=[cibo_tag],
        )

        session.add(type_panini)
        session.add(cibo_tag)
        session.add(panino)
        session.add(kebab)

        statement = select(Product)
        results = session.exec(statement)
        products = results.all()
        assert len(products) >= 1

        results = select(Product).where(Product.name == "kebab")
        results = session.exec(statement)
        products = results.all()
        assert len(products) != 0

        session.rollback()

app.src.db.engine.get_db app.src.models.db.product_type.ProductType sqlmodel.Session app.src.models.db.tag.Tag sqlmodel.select app.src.models.db.product.Product app.src.db.manager.create_table
[((387, 395), 'app.src.db.engine.get_db', 'get_db', ([], {}), '()\n', (393, 395), False, 'from app.src.db.engine import get_db\n'), ((400, 414), 'app.src.db.manager.create_table', 'create_table', ([], {}), '()\n', (412, 414), False, 'from app.src.db.manager import create_table\n'), ((425, 440), 'sqlmodel.Session', 'Session', (['engine'], {}), '(engine)\n', (432, 440), False, 'from sqlmodel import Session, select\n'), ((497, 561), 'app.src.models.db.product_type.ProductType', 'ProductType', ([], {'name': '"""Panino"""', 'description': '"""Tutto ciò che è panino"""'}), "(name='Panino', description='Tutto ciò che è panino')\n", (508, 561), False, 'from app.src.models.db.product_type import ProductType\n'), ((581, 597), 'app.src.models.db.tag.Tag', 'Tag', ([], {'name': '"""cibo"""'}), "(name='cibo')\n", (584, 597), False, 'from app.src.models.db.tag import Tag\n'), ((615, 740), 'app.src.models.db.product.Product', 'Product', ([], {'name': '"""panino"""', 'description': '"""panino buono"""', 'price': '(3.3)', 'available': '(True)', 'product_type': 'type_panini', 'tags': '[cibo_tag]'}), "(name='panino', description='panino buono', price=3.3, available=\n    True, product_type=type_panini, tags=[cibo_tag])\n", (622, 740), False, 'from app.src.models.db.product import Product\n'), ((836, 958), 'app.src.models.db.product.Product', 'Product', ([], {'name': '"""kebab"""', 'description': '"""senza cipolla"""', 'price': '(4)', 'available': '(True)', 'product_type': 'type_panini', 'tags': '[cibo_tag]'}), "(name='kebab', description='senza cipolla', price=4, available=True,\n    product_type=type_panini, tags=[cibo_tag])\n", (843, 958), False, 'from app.src.models.db.product import Product\n'), ((1178, 1193), 'sqlmodel.select', 'select', (['Product'], {}), '(Product)\n', (1184, 1193), False, 'from sqlmodel import Session, select\n'), ((1322, 1337), 'sqlmodel.select', 'select', (['Product'], {}), '(Product)\n', (1328, 1337), False, 'from sqlmodel import Session, select\n')]