recipe links
This commit is contained in:
+37
-1
@@ -11,7 +11,7 @@ from django.test.utils import override_settings
|
||||
from django.urls import reverse
|
||||
from PIL import Image
|
||||
|
||||
from .models import Recipe, RecipeIngredient, RecipeSubrecipe
|
||||
from .models import Recipe, RecipeIngredient, RecipeLink, RecipeSubrecipe
|
||||
from .templatetags.recipe_markdown import recipe_markdown
|
||||
|
||||
|
||||
@@ -86,6 +86,42 @@ class RecipeWebTests(TestCase):
|
||||
with self.assertRaises(ValidationError):
|
||||
RecipeIngredient(recipe=a, name='Flour', quantity=Decimal('-1'), unit='g').full_clean()
|
||||
|
||||
def test_linked_recipe_and_composition_web_flows(self):
|
||||
main = Recipe.objects.create(owner=self.user, title='Main')
|
||||
side = Recipe.objects.create(owner=self.user, title='Side')
|
||||
other = Recipe.objects.create(owner=self.other, title='Private')
|
||||
response = self.client.post(reverse('recipes:link', args=[main.api_id]), {
|
||||
'recipe_id': str(side.api_id), 'relationship': 'goes_well_with',
|
||||
'note': 'Serve together', 'reciprocal': '1'})
|
||||
self.assertRedirects(response, reverse('recipes:detail', args=[main.api_id]))
|
||||
link = RecipeLink.objects.get()
|
||||
edit_url = reverse('recipes:link-edit', args=[main.api_id, link.id])
|
||||
self.assertContains(self.client.get(edit_url), 'Edit linked recipe')
|
||||
self.assertEqual(self.client.post(edit_url, {
|
||||
'relationship': 'alternative_to', 'note': 'Different texture',
|
||||
'reciprocal': ''}).status_code, 302)
|
||||
link.refresh_from_db()
|
||||
self.assertEqual((link.relationship, link.note, link.reciprocal),
|
||||
('alternative_to', 'Different texture', False))
|
||||
self.assertContains(self.client.get(reverse('recipes:detail', args=[side.api_id])), 'Main')
|
||||
response = self.client.post(reverse('recipes:link', args=[main.api_id]), {
|
||||
'recipe_id': str(other.api_id), 'relationship': 'goes_well_with'})
|
||||
self.assertEqual(response.status_code, 404)
|
||||
preview = self.client.post(reverse('recipes:compose'), {
|
||||
'component': [str(main.api_id), str(side.api_id)],
|
||||
f'servings_{main.api_id}': '2', f'servings_{side.api_id}': '1',
|
||||
'action': 'preview'})
|
||||
self.assertEqual(preview.status_code, 200)
|
||||
self.assertContains(preview, 'Component preview')
|
||||
created = self.client.post(reverse('recipes:compose'), {
|
||||
'title': 'Combined', 'default_servings': '2',
|
||||
'component': [str(main.api_id), str(side.api_id)],
|
||||
f'servings_{main.api_id}': '2', f'servings_{side.api_id}': '1',
|
||||
'action': 'create'})
|
||||
self.assertEqual(created.status_code, 302)
|
||||
combined = Recipe.objects.get(title='Combined')
|
||||
self.assertEqual(set(combined.subrecipes.values_list('component_id', flat=True)), {main.pk, side.pk})
|
||||
|
||||
def test_photo_upload_is_private(self):
|
||||
image = BytesIO()
|
||||
Image.new('RGB', (2, 2), '#217857').save(image, format='PNG')
|
||||
|
||||
Reference in New Issue
Block a user