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
+34
View File
@@ -182,3 +182,37 @@ class RecipeApiTests(TestCase):
{'consumed_servings': '1', 'meal': 'lunch'}, key='meal-with-shortage').status_code, 201)
self.package.refresh_from_db()
self.assertEqual(self.package.remaining_amount, Decimal('300'))
def test_recipe_suggestion_and_explicit_composition_api(self):
base_id = self.create()
fries = self.call('post', 'recipes/create/', {'title': 'Fries'}, key='fries').json()['id']
linked = self.call('post', f'recipes/{base_id}/links/', {
'recipe_id': fries, 'relationship': 'goes_well_with', 'note': 'Serve hot',
'reciprocal': True}, key='link-fries')
self.assertEqual(linked.status_code, 201, linked.content)
replay = self.call('post', f'recipes/{base_id}/links/', {
'recipe_id': fries, 'relationship': 'goes_well_with', 'note': 'Serve hot',
'reciprocal': True}, key='link-fries')
self.assertEqual(replay.status_code, 200)
self.assertEqual(replay.json()['link_id'], linked.json()['link_id'])
self.assertEqual(self.call('get', f'recipes/{fries}/').json()['linked_recipes'][0]['recipe_id'], base_id)
edited = self.call('patch', f'recipes/{base_id}/links/{linked.json()["link_id"]}/',
{'note': 'Serve warm', 'reciprocal': False})
self.assertEqual(edited.json()['note'], 'Serve warm')
self.assertEqual(self.call('get', f'recipes/{fries}/').json()['linked_recipes'], [])
self.assertEqual(self.call('post', f'recipes/{base_id}/links/', {
'recipe_id': str(self.other_recipe.api_id)}).status_code, 404)
self.assertEqual(self.call('post', 'recipes/compositions/preview/', {
'components': [{'recipe_id': base_id, 'servings': '2'},
{'recipe_id': fries, 'servings': '1'}]}).status_code, 200)
composed = self.call('post', 'recipes/compositions/', {
'title': 'Meal plate', 'default_servings': '2', 'components': [
{'recipe_id': base_id, 'servings': '2'}, {'recipe_id': fries, 'servings': '1'}]},
key='meal-plate')
self.assertEqual(composed.status_code, 201, composed.content)
self.assertEqual(len(composed.json()['subrecipes']), 2)
self.assertEqual(self.call('post', 'recipes/compositions/', {
'title': 'bad', 'components': [{'recipe_id': str(self.other_recipe.api_id), 'servings': '1'}]
}).status_code, 400)
self.assertEqual(self.call('delete', f'recipes/{base_id}/links/{linked.json()["link_id"]}/').status_code, 200)
self.assertEqual(self.call('get', f'recipes/{base_id}/').json()['linked_recipes'], [])