add summary
This commit is contained in:
@@ -178,6 +178,53 @@ def test_boxes_overview_renders_cleanly_when_note_is_empty(client, db_session):
|
||||
assert "状态:" not in response.text
|
||||
|
||||
|
||||
def test_boxes_overview_summary_shows_expected_counts_and_averages(client, db_session):
|
||||
first_box = Box(name="卧室箱")
|
||||
second_box = Box(name="书房箱")
|
||||
regular_item = Item(name="书", box=first_box, is_container=False)
|
||||
container_item = Item(name="配件袋", box=first_box, is_container=True)
|
||||
second_container_item = Item(name="文件袋", box=second_box, is_container=True)
|
||||
db_session.add_all(
|
||||
[
|
||||
first_box,
|
||||
second_box,
|
||||
regular_item,
|
||||
container_item,
|
||||
second_container_item,
|
||||
SubItem(name="转接头", parent_item=container_item),
|
||||
SubItem(name="数据线", parent_item=container_item),
|
||||
]
|
||||
)
|
||||
db_session.commit()
|
||||
|
||||
response = client.get("/boxes")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert "当前概览" in response.text
|
||||
assert "箱子总数" in response.text
|
||||
assert "物品总数(不含子物品)" in response.text
|
||||
assert "物品总数(含子物品)" in response.text
|
||||
assert "平均每箱物品数" in response.text
|
||||
assert "平均每个容器型 Item 的子物品数" in response.text
|
||||
assert "箱子总数:</strong>2" in response.text
|
||||
assert "物品总数(不含子物品):</strong>3" in response.text
|
||||
assert "物品总数(含子物品):</strong>5" in response.text
|
||||
assert "平均每箱物品数:</strong>1.5" in response.text
|
||||
assert "平均每个容器型 Item 的子物品数:</strong>1.0" in response.text
|
||||
|
||||
|
||||
def test_boxes_overview_summary_handles_empty_data_safely(client):
|
||||
response = client.get("/boxes")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert "当前概览" in response.text
|
||||
assert "箱子总数:</strong>0" in response.text
|
||||
assert "物品总数(不含子物品):</strong>0" in response.text
|
||||
assert "物品总数(含子物品):</strong>0" in response.text
|
||||
assert "平均每箱物品数:</strong>0.0" in response.text
|
||||
assert "平均每个容器型 Item 的子物品数:</strong>0.0" in response.text
|
||||
|
||||
|
||||
def test_can_create_box(client, db_session):
|
||||
response = create_box(client, name="Kitchen Box")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user