Defer loading of profile pic
This commit is contained in:
@@ -7,13 +7,19 @@ project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
||||
sys.path.insert(0, project_root)
|
||||
|
||||
from app.models import Reading
|
||||
from app.routes.main import calculate_progress_badges
|
||||
from app.routes.main import _compute_badges
|
||||
from pytz import utc
|
||||
|
||||
|
||||
def calculate_progress_badges_test_helper(readings, test_now=None):
|
||||
total = len(readings)
|
||||
timestamps = [(r.timestamp,) for r in sorted(readings, key=lambda x: x.timestamp, reverse=True)]
|
||||
now_date = test_now.date() if test_now else datetime.utcnow().date()
|
||||
return _compute_badges(total, timestamps, utc, now_local=now_date)
|
||||
|
||||
def test_no_readings():
|
||||
readings = []
|
||||
badges = calculate_progress_badges(readings)
|
||||
badges = calculate_progress_badges_test_helper(readings)
|
||||
assert badges == []
|
||||
|
||||
|
||||
@@ -22,7 +28,7 @@ def test_daily_streak():
|
||||
readings = [
|
||||
Reading(timestamp=now - timedelta(days=i)) for i in range(3)
|
||||
] # 3-day streak
|
||||
badges = calculate_progress_badges(readings)
|
||||
badges = calculate_progress_badges_test_helper(readings, test_now=now)
|
||||
assert "Current Streak: 3 Days" in badges
|
||||
|
||||
|
||||
@@ -31,7 +37,7 @@ def test_weekly_streak():
|
||||
readings = [
|
||||
Reading(timestamp=now - timedelta(days=i)) for i in range(7)
|
||||
] # 7-day streak
|
||||
badges = calculate_progress_badges(readings)
|
||||
badges = calculate_progress_badges_test_helper(readings, test_now=now)
|
||||
assert "Logged Every Day for a Week" in badges
|
||||
|
||||
|
||||
@@ -40,7 +46,7 @@ def test_morning_riser():
|
||||
readings = [
|
||||
Reading(timestamp=now - timedelta(days=i)) for i in range(7)
|
||||
]
|
||||
badges = calculate_progress_badges(readings)
|
||||
badges = calculate_progress_badges_test_helper(readings, test_now=now)
|
||||
assert "Morning Riser: Logged Readings Every Morning for a Week" in badges
|
||||
|
||||
|
||||
@@ -49,7 +55,7 @@ def test_night_owl():
|
||||
readings = [
|
||||
Reading(timestamp=now - timedelta(days=i)) for i in range(7)
|
||||
]
|
||||
badges = calculate_progress_badges(readings)
|
||||
badges = calculate_progress_badges_test_helper(readings, test_now=now)
|
||||
assert "Night Owl: Logged Readings Every Night for a Week" in badges
|
||||
|
||||
|
||||
@@ -57,7 +63,7 @@ def test_milestones():
|
||||
readings = [
|
||||
Reading(timestamp=datetime.utcnow()) for _ in range(50)
|
||||
] # 50 readings
|
||||
badges = calculate_progress_badges(readings)
|
||||
badges = calculate_progress_badges_test_helper(readings)
|
||||
assert "50 Readings Logged" in badges
|
||||
assert "100 Readings Logged" not in badges # Ensure only the highest milestone
|
||||
|
||||
@@ -67,5 +73,5 @@ def test_no_streak_with_gaps():
|
||||
readings = [
|
||||
Reading(timestamp=now - timedelta(days=i * 2)) for i in range(3)
|
||||
] # Gaps in dates
|
||||
badges = calculate_progress_badges(readings)
|
||||
badges = calculate_progress_badges_test_helper(readings, test_now=now)
|
||||
assert "Current Streak" not in badges
|
||||
|
||||
Reference in New Issue
Block a user