wip
This commit is contained in:
parent
c238b9d757
commit
fcc0698aeb
12 changed files with 95 additions and 97 deletions
|
|
@ -1,7 +1,6 @@
|
|||
import tempfile
|
||||
|
||||
import pytest
|
||||
from sqlmodel import Session
|
||||
|
||||
from learn_sql_model.config import Config, get_config
|
||||
from learn_sql_model.factories.hero import HeroFactory
|
||||
|
|
@ -11,15 +10,25 @@ Hero
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def config() -> Session:
|
||||
def config() -> Config:
|
||||
tmp_db = tempfile.NamedTemporaryFile(suffix=".db")
|
||||
config = get_config({"database_url": f"sqlite:///{tmp_db.name}"})
|
||||
config.create_db_and_tables()
|
||||
return config
|
||||
|
||||
|
||||
def test_post_hero(config: Config) -> None:
|
||||
hero = HeroFactory().build(name="Batman", age=50)
|
||||
hero.post(config=config)
|
||||
assert hero.get(hero.id) == hero
|
||||
breakpoint()
|
||||
hero = HeroFactory().build(name="Batman", age=50, id=1)
|
||||
hero = hero.post(config=config)
|
||||
db_hero = Hero().get(hero.id, config=config)
|
||||
assert db_hero == hero
|
||||
|
||||
|
||||
def test_update_hero(config: Config) -> None:
|
||||
hero = HeroFactory().build(name="Batman", age=50, id=1)
|
||||
hero = hero.post(config=config)
|
||||
db_hero = Hero().get(id=hero.id, config=config)
|
||||
assert db_hero.dict() == hero.dict()
|
||||
db_hero.name = "Superman"
|
||||
hero = db_hero.post(config=config)
|
||||
db_hero = Hero().get(id=hero.id, config=config)
|
||||
assert db_hero.dict() == hero.dict()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue