first add
This commit is contained in:
27
tests/test_smoke.py
Normal file
27
tests/test_smoke.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from typing import Optional
|
||||
from sqlmodel import SQLModel, Field
|
||||
|
||||
from sqlmodel_pg_kit import create_all, Repository
|
||||
|
||||
|
||||
def test_smoke(tmp_path, monkeypatch):
|
||||
# 用 SQLite 临时库跑一遍(替换 cfg 同步 URL)
|
||||
from sqlmodel_pg_kit import db
|
||||
from sqlmodel_pg_kit.db import get_session
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str = Field(index=True)
|
||||
age: Optional[int] = None
|
||||
|
||||
monkeypatch.setattr(db, "cfg", db.DatabaseConfig(
|
||||
host="", port=0, user="", password="", database=":memory:", sslmode="disable"
|
||||
))
|
||||
monkeypatch.setattr(db, "engine", db.create_engine("sqlite:///:memory:", echo=False))
|
||||
|
||||
create_all()
|
||||
repo = Repository(Hero)
|
||||
with get_session() as s:
|
||||
repo.create(s, {"name": "Iron Man", "age": 45})
|
||||
names = [h.name for h in repo.list(s)]
|
||||
assert names == ["Iron Man"]
|
||||
Reference in New Issue
Block a user