示例#1
0
    def test_create_token_for_user(self):
        """
        Test that a token is created for the user
        """
        payload = {
            'email': '*****@*****.**',
            'password': '******',
        }
        sample_user(**payload)
        res = self.client.post(TOKEN_URL, payload)

        self.assertIn('token', res.data)
        self.assertEqual(res.status_code, status.HTTP_200_OK)
示例#2
0
    def test_create_token_invalid_credentials(self):
        """
        Test that token is not created if invalid credentials are given
        """
        sample_user(email='*****@*****.**', password='******')
        payload = {
            'email': '*****@*****.**',
            'password': '******',
        }
        res = self.client.post(TOKEN_URL, payload)

        self.assertNotIn('token', res.data)
        self.assertEqual(res.status_code, status.HTTP_400_BAD_REQUEST)
示例#3
0
    def test_create_existing_user(self):
        """
        Test creating a duplicate fails
        """
        payload = {
            'email': '*****@*****.**',
            'password': '******',
            'name': 'yea boiiiii',
        }
        sample_user(**payload)

        res = self.client.post(CREATE_USER_URL, payload)

        self.assertEqual(res.status_code, status.HTTP_400_BAD_REQUEST)
示例#4
0
 def test_ingredient_str(self):
     """
     Test the ingredient string representation
     """
     ingredient = models.Ingredient.objects.create(user=sample_user(),
                                                   name='Potato')
     self.assertEqual(str(ingredient), ingredient.name)
示例#5
0
    def test_recipe_str(self):
        """
        Test the recipe string representation
        """
        recipe = models.Recipe.objects.create(
            user=sample_user(),
            title='Steak and mushroom sauce',
            time_minutes=5,
            price=5.00,
        )

        self.assertEqual(str(recipe), recipe.title)
示例#6
0
    def test_list_recipes_only_for_current_user(self):
        """
        Recipes returned must be for the current user
        """
        user2 = sample_user(email="*****@*****.**")
        sample_recipe(user=user2)
        recipe = sample_recipe(user=self.user)

        res = self.client.get(RECIPES_URL)

        self.assertEqual(res.status_code, status.HTTP_200_OK)
        self.assertEqual(len(res.data), 1)
        self.assertEqual(res.data[0]['title'], recipe.title)
    def test_list_ingredients_only_for_current_user(self):
        """
        Ingredients returned must be for the current user
        """
        user2 = sample_user(
            email='*****@*****.**',
            password='******',
            name='aww yeaaaaa',
        )
        Ingredient.objects.create(user=user2, name='Salt')
        ingredient = Ingredient.objects.create(user=self.user, name='Flour')

        res = self.client.get(INGREDIENTS_URL)

        self.assertEqual(res.status_code, status.HTTP_200_OK)
        self.assertEqual(len(res.data), 1)
        self.assertEqual(res.data[0]['name'], ingredient.name)
示例#8
0
    def test_list_tags_for_only_current_user(self):
        """
        Tags returned must be for the current user
        """
        user2 = sample_user(
            email='*****@*****.**',
            password='******',
            name='aww yeaaaaa',
        )
        Tag.objects.create(user=user2, name='Vegan')
        tag = Tag.objects.create(user=self.user, name='Dessert')

        res = self.client.get(TAGS_URL)

        self.assertEqual(res.status_code, status.HTTP_200_OK)
        self.assertEqual(len(res.data), 1)
        self.assertEqual(res.data[0]['name'], tag.name)
示例#9
0
 def setUp(self):
     self.user = sample_user()
     self.client = APIClient()
     self.client.force_authenticate(user=self.user)
示例#10
0
 def test_tag_str(self):
     """
     Test the Tag string representation
     """
     tag = models.Tag.objects.create(user=sample_user(), name='Vegan')
     self.assertEqual(str(tag), tag.name)
示例#11
0
 def setUp(self):
     self.client = Client()
     self.admin = sample_superuser()
     self.client.force_login(self.admin)
     self.user = sample_user()