Fix OAuth page

This commit is contained in:
Joren de Graaf
2026-10-19 16:51:53 +02:00
parent a8418cdba7
commit 743785c2e0
54 changed files with 1794 additions and 27 deletions
+27 -2
View File
@@ -10,7 +10,7 @@ from django.test import TestCase
from django.urls import reverse
from planner.models import UserSettings
from .services.diary import diary_context
from .services.diary import diary_context, ring_progress
from .models import FoodFavourite, FoodLogAttachment, FoodLogEntry, FoodPortion, FoodProduct, MealType, Unit, InventoryLocation, KitchenInventoryItem, InventoryConsumption
@@ -81,12 +81,37 @@ class FoodFoundationTests(TestCase):
context = diary_context(self.user, date(2026, 10, 3))
self.assertEqual(context['totals']['fibre_g'], Decimal('45'))
fibre = context['macros'][3]
self.assertEqual(fibre['percent'], 100)
self.assertEqual(fibre['percent'], 113)
self.assertEqual(fibre['remaining'], Decimal('-5'))
self.assertFalse(fibre['incomplete'])
self.client.force_login(self.user)
self.assertContains(self.client.get(reverse('food:diary'), {'date': '2026-10-03'}), '5.0 g over target')
def test_ring_laps_and_over_target_accessible_text(self):
for amount, percent, base, extra, laps in (
('0', 0, '0.00', '0.00', 0),
('36', 75, '75.00', '0.00', 0),
('48', 100, '100.00', '0.00', 1),
('60', 125, '100.00', '25.00', 1),
('80.4', 168, '100.00', '67.50', 1),
('96', 200, '100.00', '100.00', 2),
('108', 225, '100.00', '25.00', 2),
):
with self.subTest(amount=amount):
ring = ring_progress(Decimal(amount), Decimal('48'))
self.assertEqual((ring['percent'], ring['base_lap'], ring['extra_lap'], ring['full_laps']),
(percent, base, extra, laps))
UserSettings.objects.create(user=self.user, fat_goal_g=Decimal('48'))
FoodLogEntry.objects.create(user=self.user, date=date(2026, 10, 3), meal=MealType.SNACKS,
product_name_snapshot='Known fat', amount=Decimal('100'), unit=Unit.GRAM,
fat_g=Decimal('80.4'))
self.client.force_login(self.user)
response = self.client.get(reverse('food:diary'), {'date': '2026-10-03'})
self.assertContains(response, '168%')
self.assertContains(response, '32.4 g over target')
self.assertContains(response, 'stroke-dasharray="67.50 100"')
def test_favourite_and_portion_uniqueness(self):
FoodFavourite.objects.create(user=self.user, product=self.product)
FoodPortion.objects.create(user=self.user, product=self.product, label='My bowl', amount=Decimal('300'), unit=Unit.GRAM)