fix: unify completed item visibility
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from datetime import UTC, date, datetime, timedelta
|
||||
from datetime import date, timedelta
|
||||
|
||||
from tests.test_mvp_backend import boot
|
||||
from tests.test_mvp_backend import boot, local_today
|
||||
|
||||
|
||||
def create_habit(client, **overrides):
|
||||
@@ -97,7 +97,7 @@ def test_habit_update_rejects_non_finite_numeric_target_and_max_value(client):
|
||||
def test_habit_log_post_rejects_non_finite_value(client):
|
||||
boot(client)
|
||||
habit = create_habit(client).json()
|
||||
day = datetime.now(UTC).date().isoformat()
|
||||
day = local_today().isoformat()
|
||||
|
||||
for value in ("NaN", "Infinity", "-Infinity"):
|
||||
response = client.post(
|
||||
@@ -110,7 +110,7 @@ def test_habit_log_post_rejects_non_finite_value(client):
|
||||
def test_habit_log_put_rejects_non_finite_value(client):
|
||||
boot(client)
|
||||
habit = create_habit(client).json()
|
||||
day = datetime.now(UTC).date().isoformat()
|
||||
day = local_today().isoformat()
|
||||
|
||||
for value in ("NaN", "Infinity", "-Infinity"):
|
||||
response = client.put(
|
||||
@@ -147,7 +147,7 @@ def test_archived_habit_rejects_edit_logs_pause_and_active_permanent_delete(clie
|
||||
|
||||
habit = create_habit(client).json()
|
||||
hid = habit["id"]
|
||||
day = datetime.now(UTC).date().isoformat()
|
||||
day = local_today().isoformat()
|
||||
assert client.put(f"/api/v1/habits/{hid}/logs/{day}", json={"value": 1}).status_code == 200
|
||||
assert client.delete(f"/api/v1/habits/{hid}").status_code == 204
|
||||
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
from datetime import UTC, datetime, timedelta
|
||||
from datetime import datetime, timedelta
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from sqlalchemy import event
|
||||
|
||||
BUSINESS_TIME_ZONE = ZoneInfo("Asia/Shanghai")
|
||||
|
||||
|
||||
def local_today():
|
||||
return datetime.now(BUSINESS_TIME_ZONE).date()
|
||||
|
||||
|
||||
def boot(client):
|
||||
response = client.post(
|
||||
@@ -299,12 +306,12 @@ def test_habits_numeric_accumulation_pause_archive_grid_and_stats(client):
|
||||
)
|
||||
assert habit.status_code == 201
|
||||
habit_id = habit.json()["id"]
|
||||
today = datetime.now(UTC).date().isoformat()
|
||||
today = local_today().isoformat()
|
||||
for value in (6, 7):
|
||||
assert client.post(f"/api/v1/habits/{habit_id}/logs", json={"day": today, "value": value}).status_code == 200
|
||||
assert client.get(f"/api/v1/habits/{habit_id}/logs").json()[0]["value"] == 10
|
||||
assert client.put(f"/api/v1/habits/{habit_id}/logs/{today}", json={"value": 8}).json()["value"] == 8
|
||||
yesterday = (datetime.now(UTC).date() - timedelta(days=1)).isoformat()
|
||||
yesterday = (local_today() - timedelta(days=1)).isoformat()
|
||||
assert client.post(f"/api/v1/habits/{habit_id}/pauses", json={"start_date": yesterday, "end_date": today}).status_code == 201
|
||||
grid = client.get("/api/v1/habits/grid", params={"week": yesterday}).json()
|
||||
assert len(grid["days"]) == 7 and grid["habits"][0]["cells"]
|
||||
@@ -328,7 +335,7 @@ def test_habit_permanent_delete_removes_habit_and_history(client):
|
||||
json={"name": "待删除习惯", "kind": "numeric", "target": 3, "schedule_type": "daily"},
|
||||
)
|
||||
habit_id = created.json()["id"]
|
||||
today = datetime.now(UTC).date().isoformat()
|
||||
today = local_today().isoformat()
|
||||
assert client.put(f"/api/v1/habits/{habit_id}/logs/{today}", json={"value": 2}).status_code == 200
|
||||
|
||||
assert client.delete(f"/api/v1/habits/{habit_id}").status_code == 204
|
||||
@@ -346,7 +353,7 @@ def test_boolean_interval_habit_schedule(client):
|
||||
)
|
||||
assert habit.status_code == 201
|
||||
assert client.post(
|
||||
f"/api/v1/habits/{habit.json()['id']}/logs", json={"day": datetime.now(UTC).date().isoformat(), "value": 1}
|
||||
f"/api/v1/habits/{habit.json()['id']}/logs", json={"day": local_today().isoformat(), "value": 1}
|
||||
).json()["value"] == 1
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user