recipe links

This commit is contained in:
Joren de Graaf
2026-10-23 14:30:58 +02:00
parent 5b986134be
commit 4d76a2bc9c
52 changed files with 2698 additions and 19 deletions
+21 -6
View File
@@ -112,7 +112,7 @@ class FoodApiTests(TestCase):
path = '/api/v1/kitchen/bulk-update/'
row = {'item_id': str(item.api_id), 'changes': {'notes': 'new'}}
self.assertEqual(self.call('post', path, {'items': [row, row], 'dry_run': False}, HTTP_IDEMPOTENCY_KEY='dup').status_code, 400)
self.assertEqual(self.call('post', path, {'items': [row] * 21, 'dry_run': False}, HTTP_IDEMPOTENCY_KEY='large').status_code, 400)
self.assertEqual(self.call('post', path, {'items': [row] * 51, 'dry_run': False}, HTTP_IDEMPOTENCY_KEY='large').status_code, 400)
self.assertEqual(self.call('post', path, {'items': [row], 'dry_run': False}).json()['error']['code'], 'idempotency_key_required')
result = self.call('post', path, {'items': [{**row, 'expected_updated_at': '2000-01-01T00:00:00+00:00'}],
'dry_run': False}, HTTP_IDEMPOTENCY_KEY='stale')
@@ -120,16 +120,31 @@ class FoodApiTests(TestCase):
item.refresh_from_db()
self.assertEqual(item.notes, '')
def test_bulk_inventory_accepts_twenty_updates_in_one_request(self):
def test_bulk_inventory_accepts_twenty_three_updates_in_one_request(self):
location = InventoryLocation.objects.create(user=self.a, name='Pantry')
items = [KitchenInventoryItem.objects.create(user=self.a, product=self.product_a, location=location)
for _ in range(20)]
for _ in range(23)]
payload = {'items': [{'item_id': str(item.api_id), 'changes': {'notes': 'Checked'}} for item in items],
'dry_run': False}
result = self.call('post', '/api/v1/kitchen/bulk-update/', payload, HTTP_IDEMPOTENCY_KEY='twenty-items')
path = '/api/v1/kitchen/bulk-update/'
preview = self.call('post', path, {**payload, 'dry_run': True})
self.assertEqual(preview.json()['counts']['validated'], 23)
self.assertEqual(KitchenInventoryItem.objects.filter(user=self.a, notes='Checked').count(), 0)
result = self.call('post', path, payload, HTTP_IDEMPOTENCY_KEY='twenty-three-items')
self.assertEqual(result.status_code, 200, result.content)
self.assertEqual(result.json()['counts']['changed'], 20)
self.assertEqual(KitchenInventoryItem.objects.filter(user=self.a, notes='Checked').count(), 20)
self.assertEqual(result.json()['counts']['changed'], 23)
self.assertEqual(KitchenInventoryItem.objects.filter(user=self.a, notes='Checked').count(), 23)
self.assertEqual(self.call('post', path, payload, HTTP_IDEMPOTENCY_KEY='twenty-three-items').json(), result.json())
def test_bulk_inventory_rejects_more_than_fifty_distinct_items(self):
location = InventoryLocation.objects.create(user=self.a, name='Pantry')
items = [KitchenInventoryItem.objects.create(user=self.a, product=self.product_a, location=location)
for _ in range(51)]
payload = {'items': [{'item_id': str(item.api_id), 'changes': {'notes': 'Checked'}} for item in items],
'dry_run': False, 'atomic': True}
result = self.call('post', '/api/v1/kitchen/bulk-update/', payload, HTTP_IDEMPOTENCY_KEY='over-limit')
self.assertEqual(result.status_code, 400)
self.assertEqual(KitchenInventoryItem.objects.filter(user=self.a, notes='Checked').count(), 0)
def test_bulk_inventory_delete_preview_confirm_and_history(self):
location = InventoryLocation.objects.create(user=self.a, name='Pantry')