SQLAlchemy 1.0->SQLAlchemy 2.x

This commit is contained in:
2024-12-07 21:37:33 +09:00
parent 29501f785f
commit 3aec075927
7 changed files with 200 additions and 41 deletions

View File

@@ -9,6 +9,11 @@ from app.db.session import Base, get_db
from app.db import models,schemas
from app.main import app
from app.core import security
import jwt
SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg2://kabAdmin:P%40ssw0rd!@kintonetooldb.postgres.database.azure.com/test"
engine = create_engine(SQLALCHEMY_DATABASE_URI,echo=True)
@@ -100,6 +105,38 @@ def login_admin(test_db,test_client,admin,password):
response = test_client.post("/api/token", data={"username": admin.email, "password":password })
return response.json()["access_token"]
@pytest.fixture(scope="session")
def login_user_id(login_user):
payload = jwt.decode(login_user, security.SECRET_KEY, algorithms=[security.ALGORITHM])
id = payload.get("sub")
return id
@pytest.fixture(scope="session")
def login_admin_id(login_admin):
payload = jwt.decode(login_admin, security.SECRET_KEY, algorithms=[security.ALGORITHM])
id = payload.get("sub")
return id
@pytest.fixture(scope="session")
def test_domain(test_db,login_user_id):
domain = models.Domain(
tenantid = "1",
name = "テスト環境",
url = "https://alicorn.cybozu.com",
kintoneuser = "maxz",
kintonepwd = security.chacha20Encrypt("maxz1205"),
is_active = True,
createuserid =login_user_id,
updateuserid =login_user_id,
ownerid = login_user_id
)
test_db.add(domain)
test_db.commit()
test_db.refresh(domain)
return domain
# @pytest.fixture
# def test_password() -> str:
# return "securepassword"