adding food logging, polish + demo updates

This commit is contained in:
Joren de Graaf
2026-10-03 21:44:38 +02:00
parent 90b21a39fc
commit be49b66dae
7 changed files with 184 additions and 13 deletions
+46 -1
View File
@@ -9,7 +9,8 @@ from django.utils import timezone
from django.urls import reverse
from .models import FastingPause, FastingPeriod, FastingSettings, SickDaySettings, Task
from .models import UserSettings, WaterIntakeEntry
from .models import BowelHealthCheckIn, ToothBrushing, UserSettings, WaterIntakeEntry
from .timezones import localdate_for_user
from .services.hydration import hydration_context
from .forms import DAILY_FASTING_DURATION_CHOICES, FastingSettingsForm
from .services.deferrals import (
@@ -1025,10 +1026,17 @@ class OnboardingTests(TestCase):
class DemoSeedCommandTests(TestCase):
def test_command_creates_and_repeatedly_restores_only_the_demo_account(self):
from food.models import FoodFavourite, FoodLogEntry, FoodPortion, FoodProduct, MealType, Unit
other = get_user_model().objects.create_user(username="private-user", password="password")
private_task = Task.objects.create(
owner=other, title="Private task", scheduled_for=timezone.localdate()
)
private_food = FoodProduct.objects.create(owner=other, product_name='Private snack')
private_food_entry = FoodLogEntry.objects.create(
user=other, date=timezone.localdate(), meal=MealType.SNACKS,
product=private_food, product_name_snapshot='Private snack', amount=100, unit=Unit.GRAM,
)
call_command("seed_demo")
@@ -1039,17 +1047,54 @@ class DemoSeedCommandTests(TestCase):
self.assertEqual(NeckHeadacheCheckIn.objects.filter(user=demo).count(), 4)
self.assertEqual(SleepCheckIn.objects.filter(user=demo).count(), 4)
self.assertTrue(FastingSettings.objects.get(user=demo).enabled)
self.assertEqual(FoodProduct.objects.filter(owner=demo).count(), 6)
self.assertEqual(FoodLogEntry.objects.filter(user=demo).count(), 10)
self.assertEqual(FoodFavourite.objects.filter(user=demo).count(), 2)
self.assertEqual(FoodPortion.objects.filter(user=demo).count(), 2)
self.assertEqual(WaterIntakeEntry.objects.filter(user=demo).count(), 4)
self.assertEqual(ToothBrushing.objects.filter(user=demo).count(), 2)
self.assertEqual(BowelHealthCheckIn.objects.filter(user=demo).count(), 3)
profile = UserSettings.objects.get(user=demo)
self.assertEqual(profile.time_zone, "Europe/Amsterdam")
self.assertFalse(profile.onboarding_enabled)
self.assertEqual(profile.daily_calorie_goal, 2000)
self.assertEqual(profile.carbohydrate_goal_g, 250)
self.assertEqual(profile.protein_goal_g, 100)
self.assertEqual(profile.fat_goal_g, 70)
self.assertFalse(profile.ntfy_enabled)
today = localdate_for_user(demo)
self.assertEqual(FoodLogEntry.objects.filter(user=demo, date=today).count(), 6)
self.assertEqual(set(FoodLogEntry.objects.filter(user=demo, date=today).values_list('meal', flat=True)),
set(MealType.values))
bowl = FoodPortion.objects.get(user=demo, label='My bowl')
self.assertTrue(bowl.is_default)
self.assertEqual(FoodLogEntry.objects.get(user=demo, date=today, portion_label_snapshot='My bowl').calories_kcal, 182.5)
self.assertTrue(Task.objects.filter(owner=demo, title="Fold the clothes", parent_task__isnull=False).exists())
Task.objects.create(owner=demo, title="Temporary demo edit", scheduled_for=timezone.localdate())
FoodProduct.objects.create(owner=demo, product_name='Temporary demo food')
banana = FoodProduct.objects.get(owner=demo, product_name='Banana')
FoodFavourite.objects.create(user=demo, product=banana)
FoodPortion.objects.create(user=demo, product=banana, label='Temporary portion', amount=100, unit=Unit.GRAM)
FoodLogEntry.objects.filter(user=demo, portion_label_snapshot='My bowl').update(product_name_snapshot='Edited demo food')
profile.ntfy_url = 'https://ntfy.example.com/old-demo-topic'
profile.ntfy_enabled = True
profile.save()
call_command("seed_demo")
self.assertEqual(Task.objects.filter(owner=demo).count(), 5)
self.assertFalse(Task.objects.filter(owner=demo, title="Temporary demo edit").exists())
self.assertEqual(FoodProduct.objects.filter(owner=demo).count(), 6)
self.assertEqual(FoodLogEntry.objects.filter(user=demo).count(), 10)
self.assertFalse(FoodLogEntry.objects.filter(user=demo, product_name_snapshot='Edited demo food').exists())
self.assertEqual(FoodFavourite.objects.filter(user=demo).count(), 2)
self.assertEqual(FoodPortion.objects.filter(user=demo).count(), 2)
profile.refresh_from_db()
self.assertFalse(profile.ntfy_enabled)
self.assertEqual(profile.ntfy_url, '')
self.assertTrue(Task.objects.filter(pk=private_task.pk, owner=other).exists())
self.assertTrue(FoodProduct.objects.filter(pk=private_food.pk, owner=other).exists())
self.assertTrue(FoodLogEntry.objects.filter(pk=private_food_entry.pk, user=other).exists())
class UserTimeZoneTests(TestCase):