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='Scrambled egg', time_minutes=10, price=8, 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)
def test_retrieve_tags_assigned_to_recipe(self): """test filtering tags by those assigned to recipes""" tag1 = Tag.objects.create(user=self.user, name='breakoh') tag2 = Tag.objects.create(user=self.user, name='lunch') recipe = Recipe.objects.create(user=self.user, title='continenatl breakfast', time_minutes=23, price=45.00) 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)
def test_retrieve_tags(self): Tag.objects.create(name='Vegan', user=self.user) Tag.objects.create(name='Dessert', user=self.user) resp = self.client.get(TAG_URL) tags = Tag.objects.all() serializer = TagSerializer(tags, many=True) self.assertEqual(resp.status_code, status.HTTP_200_OK) self.assertEqual(resp.data, serializer.data)
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(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)
def test_retrieve_tags(self): """test retrieving tags""" Tag.objects.create(user=self.user, name='nyamas') Tag.objects.create(user=self.user, name='mboga') 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)