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.

Reply via email to