from django.test.client import MULTIPART_CONTENT, encode_multipart, BOUNDARY
from PIL import Image
import tempfile
def get_temporary_image(temp_file):
size = (200,200)
color = (255, 0, 0, 0)
image = Image.new("RGBA", size, color)
image.save(temp_file, 'png')
return temp_file
def test_create_review_with_image(self):
temp_file = tempfile.NamedTemporaryFile()
temp_file.name = "image.png"
image_file = get_temporary_image(temp_file)
image_file.seek(0)
self.review_data["review_image_one"] = image_file
response = self.client.post(
path=reverse("review_list_view", kwargs={'place_id':1}),
HTTP_AUTHORIZATION=f"Bearer {self.access_token}",
content_type=MULTIPART_CONTENT,
data=encode_multipart(data = self.review_data, boundary=BOUNDARY)
)
self.assertEqual(response.status_code, 201)