def test_recipe_str(self): """Test that ingredient string representation""" recipe = sample_recipe(user=sample_user(), title="Steak and ushroom Sauce", time_minutes=5, price=5.00) self.assertEqual(str(recipe), recipe.title)
def test_tags_limited_to_user(self): """Test that tags returned are for the authenticated user""" user2 = sample_user(email='*****@*****.**') sample_tag(user=user2, name='Fruity') tag = sample_tag(user=self.user, name='Comfort Food') resp = self.client.get(TAGS_URL) self.assertEqual(resp.status_code, status.HTTP_200_OK) self.assertEqual(len(resp.data), 1) self.assertEqual(resp.data[0]['name'], tag.name)
def test_ingredients_limited_to_user(self): """Test that only ingredients for the authenticated user are returned""" user2 = sample_user(email='*****@*****.**') sample_ingredient(user=user2, name='Vinegar') ingredient = sample_ingredient(user=self.user, name='Tumeric') resp = self.client.get(INGREDIENTS_URL) self.assertEqual(resp.status_code, status.HTTP_200_OK) self.assertEqual(len(resp.data), 1) self.assertEqual(resp.data[0]['name'], ingredient.name)
def test_recipes_limited_to_user(self): """Test retrieving recpies for user""" user2 = sample_user('*****@*****.**') sample_recipe(user=user2) sample_recipe(user=self.user) resp = self.client.get(RECIPES_URL) recipes = Recipe.objects.filter(user=self.user) serializer = RecipeSerializer(recipes, many=True) self.assertEqual(resp.status_code, status.HTTP_200_OK) self.assertEqual(len(resp.data), 1) self.assertEqual(resp.data, serializer.data)
def setUp(self): self.client = APIClient() self.user = sample_user() self.client.force_authenticate(self.user)
def test_ingredient_str(self): """Test that ingredient string representation""" ingredient = sample_ingredient(user=sample_user(), name='Cucumber') self.assertEqual(str(ingredient), ingredient.name)
def test_tag_str(self): """Test the tag string representation""" tag = sample_tag(user=sample_user(), name='Vegan') self.assertEqual(str(tag), tag.name)
def test_new_user_invalid_email(self): """Test creating user with email raises error""" with self.assertRaises(ValueError): sample_user(email=None, password=self.password)
def test_new_user_email_normalized(self): """Test the email for a new user is normalized""" user = sample_user(email=self.destabilize_email, password=self.password) self.assertEqual(user.email, self.normalize_email)
def test_create_user_with_email_successful(self): """Test creating a new user with a email is successful""" user = sample_user(email=self.email, password=self.password) self.assertEqual(user.email, self.email) self.assertTrue(user.check_password(self.password))