Skip to content

Instantly share code, notes, and snippets.

@nghiaht
Created March 21, 2019 09:09
Show Gist options
  • Select an option

  • Save nghiaht/682c2d8d40272c52dbf7adf214f1c0f1 to your computer and use it in GitHub Desktop.

Select an option

Save nghiaht/682c2d8d40272c52dbf7adf214f1c0f1 to your computer and use it in GitHub Desktop.

Revisions

  1. nghiaht created this gist Mar 21, 2019.
    17 changes: 17 additions & 0 deletions test_upload.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    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)