def test_upload_image_to_recipe(self):
    'Test uploading an image to recipe'
    url = image_upload_url(self.recipe.id)
    with tempfile.NamedTemporaryFile(suffix='.jpg') as ntf:
        img = Image.new('RGB', (10, 10))
        img.save(ntf, format='JPEG')
        ntf.seek(0)
        res = self.client.post(url, {'image': ntf}, format='multipart')
    self.recipe.refresh_from_db()
    self.assertEqual(res.status_code, status.HTTP_200_OK)
    self.assertIn('image', res.data)
    self.assertTrue(os.path.exists(self.recipe.image.path))
Test uploading an image to recipe
def test_upload_image_to_recipe(self):
    
    url = image_upload_url(self.recipe.id)
    with tempfile.NamedTemporaryFile(suffix='.jpg') as ntf:
        img = Image.new('RGB', (10, 10))
        img.save(ntf, format='JPEG')
        ntf.seek(0)
        res = self.client.post(url, {'image': ntf}, format='multipart')
    self.recipe.refresh_from_db()
    self.assertEqual(res.status_code, status.HTTP_200_OK)
    self.assertIn('image', res.data)
    self.assertTrue(os.path.exists(self.recipe.image.path))