food diary bug fix, blocking calorie count
This commit is contained in:
@@ -39,6 +39,20 @@ class FoodApiTests(TestCase):
|
||||
data = json.dumps(data)
|
||||
return getattr(self.client, method)(path, data=data, **args)
|
||||
|
||||
def test_today_reports_quantity_scaled_known_subtotals_and_missing_fields(self):
|
||||
day = timezone.localdate()
|
||||
FoodLogEntry.objects.create(user=self.a, date=day, meal='lunch',
|
||||
product_name_snapshot='Known lunch', amount=Decimal('100'), quantity=Decimal('2'),
|
||||
unit='g', calories_kcal=Decimal('120'), protein_g=Decimal('5'))
|
||||
FoodLogEntry.objects.create(user=self.a, date=day, meal='dinner',
|
||||
product_name_snapshot='Unknown dinner', amount=Decimal('100'), unit='g')
|
||||
result = self.call('get', '/api/v1/food/today/').json()
|
||||
self.assertEqual(Decimal(result['totals']['calories_kcal']), Decimal('240'))
|
||||
self.assertEqual(Decimal(result['totals']['protein_g']), Decimal('10'))
|
||||
self.assertTrue(result['incomplete']['calories_kcal'])
|
||||
self.assertTrue(result['incomplete']['protein_g'])
|
||||
self.assertIsNone(result['totals']['fat_g'])
|
||||
|
||||
def test_atomic_food_log_and_inventory_keeps_historical_snapshot(self):
|
||||
old = FoodLogEntry.objects.create(user=self.a, product=self.product_a,
|
||||
date=timezone.localdate() - timedelta(days=1), meal='dinner',
|
||||
|
||||
Reference in New Issue
Block a user