Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multipart payload TEST not working on Django 1.10.6 #29

Open
cleberzavadniak opened this issue Mar 3, 2017 · 3 comments
Open

multipart payload TEST not working on Django 1.10.6 #29

cleberzavadniak opened this issue Mar 3, 2017 · 3 comments

Comments

@cleberzavadniak
Copy link

`--> 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)
@cleberzavadniak cleberzavadniak changed the title multipart payload not working on Django 1.10.6 multipart payload TEST not working on Django 1.10.6 Mar 3, 2017
@cleberzavadniak
Copy link
Author

I proposed a solution. It seems the issue is in Django itself:
django/django#8142

(The weird thing is: am I the only one getting this error?)

@senko
Copy link
Member

senko commented Mar 22, 2017

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.

@cleberzavadniak
Copy link
Author

Man, you can't forget that kind of thing! Haha!
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants