This commit is contained in:
Waylon Walker 2023-05-19 20:37:42 -05:00
parent c238b9d757
commit fcc0698aeb
No known key found for this signature in database
GPG key ID: 66E2BF2B4190EFE4
12 changed files with 95 additions and 97 deletions

View file

@ -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()