revsys / django-test-plus

Useful additions to Django's default TestCase

Home Page:https://django-test-plus.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Behaviour of TestCase.post is not as expected

goodtune opened this issue · comments

I have a test using the post method which is failing under a use case I would expect to work.

def test_some_view(self):
    data = {}
    self.post('named:view', data)
    self.response_302()

The above test case is failing, because the response code is 404 not 302.

However if I rework the test case as below, it now works with the desired side effects.

def test_some_view(self):
    data = {}
    url = self.reverse('named:view')
    res = self.client.post(url, data)
    self.assertEqual(res.status_code, 302)

Is there anything obvious that is wrong in my usage of the post method, or is this a bug?

I'd add, looking at the source there isn't much that I think can go wrong, so I'm struggling to explain it.

Hmmm yeah this pattern is used all the time so if it was breaking in a general way I'd be running into it daily myself. I'm gonna guess perhaps there was a typo of 'named:view' that you fixed when you reworked it maybe?

If you can create a reproducible case please reopen this. Thanks!