58 lines
1.4 KiB
Python
58 lines
1.4 KiB
Python
import pytest
|
|
from fastapi.testclient import TestClient
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.core.database import SessionLocal
|
|
from app.main import app
|
|
from app.models.finished_goods import (
|
|
FinishedGoodsBox,
|
|
FinishedGoodsBoxItem,
|
|
FinishedGoodsLocation,
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def client():
|
|
return TestClient(app)
|
|
|
|
|
|
@pytest.fixture
|
|
def db():
|
|
session = SessionLocal()
|
|
yield session
|
|
session.close()
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def cleanup_test_data(db: Session):
|
|
yield
|
|
test_zongpai_nos = [
|
|
"26B999",
|
|
"26C999",
|
|
"26BW0999",
|
|
"26T999",
|
|
"26T998",
|
|
"26B998",
|
|
"26C998",
|
|
]
|
|
db.query(FinishedGoodsLocation).filter(
|
|
FinishedGoodsLocation.zongpai_no.in_(test_zongpai_nos)
|
|
).delete(synchronize_session=False)
|
|
test_boxes = (
|
|
db.query(FinishedGoodsBox)
|
|
.filter(
|
|
FinishedGoodsBox.paichan_no == "W00009",
|
|
FinishedGoodsBox.box_no >= 900,
|
|
)
|
|
.all()
|
|
)
|
|
test_box_ids = [box.id for box in test_boxes]
|
|
if test_box_ids:
|
|
db.query(FinishedGoodsBoxItem).filter(
|
|
FinishedGoodsBoxItem.box_id.in_(test_box_ids)
|
|
).delete(synchronize_session=False)
|
|
db.query(FinishedGoodsBox).filter(
|
|
FinishedGoodsBox.id.in_(test_box_ids)
|
|
).delete(synchronize_session=False)
|
|
db.commit()
|