Example #1
0
 def test_retrieve_tags_assigned_to_recipes(self):
     """Test filtering tags by those assigned to recipes"""
     tag1 = Tag.objects.create(user=self.user, name='Breakfast')
     tag2 = Tag.objects.create(user=self.user, name='Lunch')
     recipe = Recipe.objects.create(title='Coriander eggs on toast',
                                    time_minutes=5,
                                    price=5.00,
                                    user=self.user)
     recipe.tags.add(tag1)
     res = self.client.get(TAGS_URL, {'assigned_only': 1})
     serializer1 = TagSerializer(tag1)
     serializer2 = TagSerializer(tag2)
     self.assertIn(serializer1.data, res.data)
     self.assertNotIn(serializer2.data, res.data)
Example #2
0
    def test_retrieve_tags_assigned_to_recipes(self):
        """Returns a list of tags that are assigned to recipes"""
        tag1 = sample_tag(user=self.user, name="Spicy")
        tag2 = sample_tag(user=self.user, name="Dinner")
        recipe = sample_recipe(user=self.user, title="Koshary")

        recipe.tags.add(tag1)

        res = self.client.get(TAGS_URL, {"assigned_only": 1})

        serializer1 = TagSerializer(tag1)
        serializer2 = TagSerializer(tag2)

        self.assertEqual(res.status_code, status.HTTP_200_OK)
        self.assertIn(serializer1.data, res.data)
        self.assertNotIn(serializer2.data, res.data)
Example #3
0
    def test_retrieve_tags_assigned_to_recipes(self):
        tag1 = Tag.objects.create(user=self.user, name="Breakfast")
        tag2 = Tag.objects.create(user=self.user, name="Lunch")
        recipe = Recipe.objects.create(
            title="Coriander eggs on toast",
            time_minutes=10,
            price=5.00,
            user=self.user,
        )
        recipe.tags.add(tag1)

        res = self.client.get(TAG_URL, {"assigned_only": 1})

        serializer1 = TagSerializer(tag1)
        serializer2 = TagSerializer(tag2)
        self.assertIn(serializer1.data, res.data)
        self.assertNotIn(serializer2.data, res.data)
Example #4
0
    def test_retrieve_tags_assigned_to_recipes(self):
        """Test filtering tags by those assigned to recipes"""
        breakfast = Tag.objects.create(user=self.user, name='Breakfast')
        lunch = Tag.objects.create(user=self.user, name='Lunch')
        gods_breakfast = Recipe.objects.create(
            title='Bacon and Eggs',
            time_minutes=10,
            price=30.00,
            user=self.user,
        )
        gods_breakfast.tags.add(breakfast)
        breakfast_data = TagSerializer(breakfast).data
        lunch_data = TagSerializer(lunch).data

        res = self.client.get(TAGS_URL, {'assigned_only': 1})
        self.assertIn(breakfast_data, res.data)
        self.assertNotIn(lunch_data, res.data)
Example #5
0
    def test_retrieve_tags(self):
        Tag.objects.create(user=self.user, name='Vegan')
        Tag.objects.create(user=self.user, name='Dessert')

        res = self.client.get(self.url)
        tags = Tag.objects.all().order_by('-name')
        serializer = TagSerializer(tags, many=True)

        self.assertEqual(res.status_code, status.HTTP_200_OK)
        self.assertEqual(res.data, serializer.data)
Example #6
0
    def test_retrieve_tag_list_successful(self):
        """Test retrieving list of tags"""
        Tag.objects.create(user=self.user, name="Spicy")
        Tag.objects.create(user=self.user, name="Well-Done")

        res = self.client.get(TAGS_URL)
        tags = Tag.objects.all().order_by("-name")
        serializer = TagSerializer(tags, many=True)

        self.assertEqual(res.data, serializer.data)
        self.assertEqual(res.status_code, status.HTTP_200_OK)
Example #7
0
    def test_retrieve_tags(self):
        """ Test retrieving tags """
        Tag.objects.create(user=self.user, name="Korean")
        Tag.objects.create(user=self.user, name="Chinese")

        res = self.client.get(TAGS_URL)

        tags = Tag.objects.all().order_by('-name')
        serializer = TagSerializer(tags, many=True)
        self.assertEqual(res.status_code, status.HTTP_200_OK)
        self.assertEqual(res.data, serializer.data)
Example #8
0
    def test_list_tags(self):
        Tag.objects.create(user=self.user, name="Vegan")
        Tag.objects.create(user=self.user, name="Dessert")

        res = self.client.get(TAG_URL)

        tags = Tag.objects.all().order_by("-name")
        serializer = TagSerializer(tags, many=True)

        self.assertEqual(res.status_code, status.HTTP_200_OK)
        self.assertEqual(res.data, serializer.data)
Example #9
0
    def test_get_tags(self):
        """Test retrieving tags"""
        Tag.objects.create(name="Dessert", user=self.user)
        Tag.objects.create(name="Italian", user=self.user)

        tags = Tag.objects.all().order_by("-name")
        serializer = TagSerializer(tags, many=True)

        res = self.client.get(TAGS_URL)
        self.assertEqual(res.status_code, status.HTTP_200_OK)
        self.assertEqual(res.data, serializer.data)
Example #10
0
    def test_retrieve_tags(self):
        """Test that tags are retrieved"""
        Tag.objects.create(user=self.user, name='Meatarian')
        Tag.objects.create(user=self.user, name='dessert')

        res = self.client.get(TAGS_URL)
        tags = Tag.objects.all().order_by('-name')
        serializer = TagSerializer(tags, many=True)

        self.assertEqual(res.status_code, status.HTTP_200_OK)
        self.assertEqual(res.data, serializer.data)
Example #11
0
    def test_retrieving_tags(self):
        """Tests retrieving tags"""

        Tag.objects.create(user=self.user, name='lactopurga-vegan')
        Tag.objects.create(user=self.user, name='dessert')

        response = self.client.get(TAGS_URL)

        tags = Tag.objects.all().order_by('-name')
        serializer = TagSerializer(tags, many=True)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, serializer.data)
Example #12
0
    def test_get_only_user_tags(self):
        """Test that only user tags are retrieved"""
        Tag.objects.create(name="Dessert", user=self.user)
        Tag.objects.create(name="Italian", user=self.user)

        other_user = create_user(email="*****@*****.**",
                                 password="******")
        Tag.objects.create(name="Vegan", user=other_user)
        Tag.objects.create(name="Keto", user=other_user)

        tags = Tag.objects.filter(user=self.user).order_by("-name")
        serializer = TagSerializer(tags, many=True)

        res = self.client.get(TAGS_URL)
        self.assertEqual(res.status_code, status.HTTP_200_OK)
        self.assertEqual(res.data, serializer.data)
Example #13
0
    def test_user_tags_listed(self):
        # Second user for test (shouldn't return this tag)
        second_user_tag = Tag.objects.create(
            user=sample_user(email="*****@*****.**"), name="Dinner")

        Tag.objects.create(user=self.user, name="Vegan")
        Tag.objects.create(user=self.user, name="Dessert")

        res = self.client.get(TAG_URL)
        user_tags = Tag.objects.filter(user=self.user)

        serializer = TagSerializer(user_tags, many=True)

        # The second tag will be the second_user_tag because it's ordered
        self.assertNotEqual(second_user_tag.name, res.data[1]["name"])
        self.assertEqual(len(res.data), 2)
        self.assertEqual(res.data, serializer.data)
        self.assertEqual(res.status_code, status.HTTP_200_OK)