django-restless
django-restless copied to clipboard
multipart payload TEST not working on Django 1.10.6
`--> pip freeze
alabaster==0.7.10
Babel==2.3.4
coverage==4.3.4
Django==1.10.6
docutils==0.13.1
flake8==3.3.0
imagesize==0.7.1
Jinja2==2.9.5
MarkupSafe==0.23
mccabe==0.6.1
pycodestyle==2.3.1
pyflakes==1.5.0
Pygments==2.2.0
pytz==2016.10
requests==2.13.0
six==1.10.0
snowballstemmer==1.2.1
Sphinx==1.5.3
`--> python3 manage.py test --failfast
Creating test database for alias 'default'...
................F
======================================================================
FAIL: test_create_author_multipart (testapp.tests.TestEndpoint)
Exercise multipart/form-data POST
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/cleber/code/third-party/django-restless/testproject/testapp/tests.py", line 346, in test_create_author_multipart
self.assertEqual(r.status_code, 201, r.content)
AssertionError: 400 != 201 : b'{"error": "invalid author data", "details": {"name": ["This field is required."]}}'
I made a slight modification on asserEqual so it could print r.content. Aparently, although name is indeed being present on the payload (see below), it's not being recognized somewhere.
The test:
def test_create_author_multipart(self):
"""Exercise multipart/form-data POST"""
r = self.client.post('author_list', data={
'name': 'New User',
}) # multipart/form-data is default in test client
self.assertEqual(r.status_code, 201, r.content)
self.assertEqual(r.json['name'], 'New User')
self.assertEqual(r.json['name'],
Author.objects.get(id=r.json['id']).name)
I proposed a solution. It seems the issue is in Django itself: https://github.com/django/django/pull/8142
(The weird thing is: am I the only one getting this error?)
Hi @cleberzavadniak, Django 1.10 introduces content_type attribute on the HttpRequest thus clashing with content_type we used. Django's attribute can be normally used from restless, but ours doesn't behave exactly as Django expects, thus the errors.
I had a fix sitting in the branch waiting for validation since Dec, but noticed I hadn't merged it. I have now (see #28 and #27 for related bug report). Please let me know if this fixes your problem.
Man, you can't forget that kind of thing! Haha! Thanks.