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=10, price=5.0, 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)
Test filtering tags by those assigned to recipes
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.0, 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)