Opened 6 years ago

Closed 6 years ago

#29966 closed Cleanup/optimization (fixed)

Add test coverage for BaseHandler's "The view didn't return an HttpResponse object." error

Reported by: ziposcar Owned by: Hasan Ramezani
Component: HTTP handling Version: 2.1
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

FILE: django/core/handlers/base.py : 131-135

The isinstance(callback, types.FunctionType) is seems to always equal True even if I used CBV.
I think this is due to View.as_view() returns a function every time. So is this if statement useless?

Change History (7)

comment:1 by Rand01ph, 6 years ago

Owner: changed from nobody to Rand01ph
Status: newassigned

comment:2 by Tim Graham, 6 years ago

Component: Core (Other)HTTP handling
Summary: Useless judgment for CBVAdd test coverage for BaseHandler's "The view didn't return an HttpResponse object." error
Triage Stage: UnreviewedAccepted

The error message was added in 8a939224fa5df92f38532c76901975b9e765a1e9 and modified in e1d23323b631436eaae78bb5e4676d83c97d7a6c, both without tests. 27d16a3ca4a330f5aa46015ccd7d5a9ee72873b6 added Python 3 compatibility. Some tests were added in 52e0bcbc62c4df5d488b18f6a8e2cba798ec0807 (see null_view) but they were lost in d334f46b7a080fd3eb720141c19b37b10704a352.

Tests should be added for the "The view didn't return an HttpResponse object" error.

comment:3 by Hasan Ramezani, 6 years ago

Owner: changed from Rand01ph to Hasan Ramezani
Patch needs improvement: set

PR

It covers FBV:
https://github.com/django/django/blob/d5f4ce9849b062cc788988f2600359dc3c2890cb/django/core/handlers/base.py#L119

But I don't know how to test the CBV. I test some class-based view like this:

class WithoutReponse(ListView):

    def get(self, request):
        pass

But, when I call this view, the callback type is FunctionType and the else block doesn't execute.

in reply to:  3 comment:4 by ziposcar, 6 years ago

Replying to Hasan Ramezani:

PR

It covers FBV:
https://github.com/django/django/blob/d5f4ce9849b062cc788988f2600359dc3c2890cb/django/core/handlers/base.py#L119

But I don't know how to test the CBV. I test some class-based view like this:

class WithoutReponse(ListView):

    def get(self, request):
        pass

But, when I call this view, the callback type is FunctionType and the else block doesn't execute.

So i have the same question of CBV. And my ticket is for useless 'if' but not the test at first.
I think the callback should be always FunctionType and that 'if' is useless.

comment:5 by Tim Graham, 6 years ago

To exercise that branch, you can write a view like this:

class View:
    def __call__(self, request):
        pass

and use it in the URLconf as View().

comment:6 by Hasan Ramezani, 6 years ago

Patch needs improvement: unset

Thank you. ClassBasedView test added.

comment:7 by Tim Graham <timograham@…>, 6 years ago

Resolution: fixed
Status: assignedclosed

In 11a90171:

Fixed #29966 -- Added tests for BaseHandler's "The view didn't return an HttpResponse object" error.

Note: See TracTickets for help on using tickets.
Back to Top