from django.test import TestCase from rest_framework.test import APIClient class FileUploadTestCase(TestCase): def test_upload(self): client = APIClient() client.credentials(HTTP_AUTHORIZATION='Token ' + self.token.key) # or self.client (Django https://docs.djangoproject.com/en/dev/topics/testing/advanced/) response = client.post(reverse('upload-file'), { "image": open("tests/test.png", "rb"), "name": "test" }) self.assertEqual(200, response.status_code)