Didn't see which request client you were using. Did you try
adding format='multipart' to your post call? That seems like your issue

On Sun, Oct 28, 2018, 8:58 PM Alexander Lamas <alexander.g.la...@gmail.com>
wrote:

> Hi Jason,
>
> Thanks for your reply.
>
> Actually, my view is working fine and running time.
> The problem is only at the unit test time.
>
>
>
> On Friday, October 26, 2018 at 8:08:24 PM UTC+9, Jason wrote:
>>
>> sounds like your view is a little wrong, because its not returning any
>> response (eg None)
>>
>> On Friday, October 26, 2018 at 6:11:26 AM UTC-4, Alexander Lamas wrote:
>>>
>>> Hi All,
>>>
>>> I've created a DRF Web API application and I've got the following error
>>> when running my unit test.
>>>
>>> *Message: Expected a `Response`, `HttpResponse` or
>>> `HttpStreamingResponse` to be returned from the view, but received a
>>> `<class 'NoneType'>`*
>>>
>>> My intention is to simulate my ajax call when uploading the file.
>>> The only difference I've noticed between ajax call and unit test api
>>> call is when calling via ajax I can use *request.data['file'].read()* which
>>> gives me the file contents.
>>> When I make the API call via django I can not use*
>>> request.data['file'].read()*, as it gives me *b'' (which means blank)*
>>>
>>> This is the  code
>>>
>>> class Import_CSV_File_Test(TestCase):
>>>     def setUp(self):
>>>         utf8_file = os.path.join(settings.BASE_DIR, "app", "tests", "data", 
>>> "user_utf8n.csv")
>>>
>>>         file_utf8 = SimpleUploadedFile(utf8_file, open(utf8_file, 
>>> 'rb').read(), content_type='application/vnd.ms-excel')
>>>
>>>         self.form_data = {'encode': 'utf8', 'file': file_utf8}
>>>
>>>     def test_import_file_format_utf8(self):
>>>         response = self.client.post(reverse(self._url, 
>>> args=[self._egateid]), data=self.form_data)
>>>         self.assertEqual(response.status_code, status.HTTP_201_CREATED)
>>>
>>>
>>> Have any of you encountered this issue?
>>>
>>> Do you guys have another way of unit testing the file upload api call?
>>>
>>> Thank you very much.
>>>
>>> Regards,
>>> Alex
>>>
>>>
>>>
>>>
>>>
>>> --
> You received this message because you are subscribed to the Google Groups
> "Django REST framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-rest-framework+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to