コード例 #1
0
    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)
コード例 #2
0
    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)
コード例 #3
0
    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)
コード例 #4
0
    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)
コード例 #5
0
 def setUp(self):
     self.client = APIClient()
     self.user = sample_user()
     self.client.force_authenticate(self.user)
コード例 #6
0
    def test_ingredient_str(self):
        """Test that ingredient string representation"""
        ingredient = sample_ingredient(user=sample_user(), name='Cucumber')

        self.assertEqual(str(ingredient), ingredient.name)
コード例 #7
0
    def test_tag_str(self):
        """Test the tag string representation"""
        tag = sample_tag(user=sample_user(), name='Vegan')

        self.assertEqual(str(tag), tag.name)
コード例 #8
0
 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)
コード例 #9
0
    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)
コード例 #10
0
    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))