I have test.py
from rest_framework.test import APITestCase
from django.core.files.uploadedfile import SimpleUploadedFile
from django.urls import reverse
class PostImageTest(APITestCase):
def setUp(self) -> None:
self.product = Product.objects.create(...)
self.sampleImage = SimpleUploadedFile("test_image.jpg", b"binary data", content_type="image/jpeg")
def test_with_valid_data(self) -> None:
data = { "image":self.sampleImage, "is_featured":true }
response = client.post(reverse('images'), data, format='multipart')
I want to pass query params like images?product=id to the client.post() method. Also i'm not getting as to how to encode the image and send a POST request.
When i tried like this
response = client.post(reverse('images'), {'product' : self.product.id}, data=data, format='multipart')
It gives me this error
TypeError: Client.post() got multiple values for argument 'data'
{{baseUrl}}/images?product=1. This is the request i'm sending via postman where it works. Also i'm selecting an image via theform-dataoption in postman to hit the request