Update
This problem was caused by the fact that I did not include the token in the APIClient header. It is allowed.
I have a standard ModelViewSet in /test-endpoint. I am trying to use APIClient to verify the endpoint.
from rest_framework.test import APIClient
...
self.client = APIClient()
...
sample_call = {
"name": "test_document",
"description": "test_document_description"
}
response = self.client.post('/test-endpoint', sample_call, format='json')
self.assertEqual(response.status_code, 201)
This call works with the parameters set in sample_call. It returns 201. When I run the test, however, I get 500. How can I change this to pass 201?
I run tests with python src/manage.py test modulename
To rule out the obvious, I copied the sample request to Postman and ran it without problems. I believe that the status code 500 comes from the fact that I am testing the call and not using it in a live environment.
Error messages do not go beyond AssertionError:
AssertionError: 500! = 201
/home/bryant/.virtualenvs/REDACTED/lib/python3.4/site- packages/django_boto/s3/shortcuts.py:28: RemovedInDjango110Warning: Backwards compatibility for storage backends without support for the `max_length` argument in Storage.get_available_name() will be removed in Django 1.10.
s3.save(full_path, fl)
F
======================================================================
FAIL: test_create (sample.tests.SampleTestCase)
Test CREATE Document
Traceback (most recent call last):
File "/home/bryant/api/redacted/src/sample/tests.py", line 31, in test_create
self.assertEqual(response.status_code, 201)
AssertionError: 500 != 201
Ran 1 test in 2.673s
FAILED (failures=1)
Destroying test database for alias 'default'...
S3. .