from django test import TestCase from dishes models import Dish Ingred

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from django.test import TestCase
from dishes.models import Dish, Ingredient
class TestModels(TestCase):
def setUp(self):
self.ingredient1 = Ingredient.objects.create(
title='Ingredient 1'
)
self.ingredient2 = Ingredient.objects.create(
title='Ingredient 2'
)
def test_ingredient_is_assigned_title_on_creation(self):
self.assertEquals(self.ingredient1.title, 'Ingredient 1')
def test_dish_is_assigned_title_on_creation(self):
self.dish1 = Dish.objects.create(
title="Dish 1"
)
self.assertEquals(self.dish1.title, 'Dish 1')
def test_dish_is_assigned_ingredient_title_on_creation(self):
self.dish1 = Dish.objects.create(
title="Dish 1"
)
self.dish1.ingredients.add(self.ingredient1)
print(list(self.dish1.ingredients.all(), [self.ingridient1,]))