59 lines
2.5 KiB
Python
59 lines
2.5 KiB
Python
from sqlalchemy import BigInteger, create_engine, inspect
|
|
from sqlalchemy.ext.compiler import compiles
|
|
|
|
from app.database import Base
|
|
from app.models import ProductionReport, ProductionReportItem # noqa: F401
|
|
|
|
|
|
@compiles(BigInteger, "sqlite")
|
|
def _compile_big_integer_for_sqlite(type_, compiler, **kw):
|
|
return "INTEGER"
|
|
|
|
|
|
def test_report_over_limit_columns_exist_on_sqlite_metadata():
|
|
engine = create_engine("sqlite:///:memory:")
|
|
Base.metadata.create_all(engine)
|
|
inspector = inspect(engine)
|
|
|
|
report_column_rows = inspector.get_columns("production_reports")
|
|
item_column_rows = inspector.get_columns("production_report_items")
|
|
report_columns = {column["name"] for column in report_column_rows}
|
|
item_columns = {column["name"] for column in item_column_rows}
|
|
report_column_by_name = {column["name"]: column for column in report_column_rows}
|
|
item_column_by_name = {column["name"]: column for column in item_column_rows}
|
|
report_indexes = {index["name"]: tuple(index["column_names"]) for index in inspector.get_indexes("production_reports")}
|
|
item_indexes = {
|
|
index["name"]: tuple(index["column_names"])
|
|
for index in inspector.get_indexes("production_report_items")
|
|
}
|
|
|
|
assert {"has_over_limit", "over_limit_summary"}.issubset(report_columns)
|
|
assert {
|
|
"over_limit_status",
|
|
"over_limit_type",
|
|
"over_limit_reason",
|
|
"over_limit_checked_at",
|
|
"over_limit_check_source",
|
|
"over_limit_batch_no",
|
|
"over_limit_product_gross_weight_kg",
|
|
"over_limit_issued_weight_kg",
|
|
"over_limit_max_reportable_qty",
|
|
"over_limit_previous_good_qty",
|
|
"over_limit_current_cumulative_qty",
|
|
"over_limit_current_report_qty",
|
|
}.issubset(item_columns)
|
|
|
|
assert report_indexes["idx_reports_over_limit"] == ("has_over_limit", "submitted_at")
|
|
assert item_indexes["idx_report_items_over_limit_status"] == ("over_limit_status",)
|
|
assert item_indexes["idx_report_items_process_batch"] == (
|
|
"attendance_point_name",
|
|
"project_no",
|
|
"product_name",
|
|
"raw_material_batch_no",
|
|
"process_name",
|
|
)
|
|
assert report_column_by_name["has_over_limit"]["nullable"] is False
|
|
assert str(report_column_by_name["has_over_limit"]["default"]).strip("'\"") in {"0", "false", "FALSE"}
|
|
assert item_column_by_name["over_limit_status"]["nullable"] is False
|
|
assert str(item_column_by_name["over_limit_status"]["default"]).strip("'\"") == "not_checked"
|