#26626: Update decorator_from_middleware to work with new-style middleware
-------------------------------+--------------------------------------
Reporter: Tim Graham | Owner: Carl Meyer
Type: New feature | Status: assigned
Component: HTTP handling | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Comment (by Andreas Pelme):
A use case for this is tests. I have a middleware that handles temporary
unavailability by showing a loading page/returning HTTP 503 for certain
exceptions.
This particular middleware uses custom logic in `__call__` and
`process_exception`. `decorator_from_middleware` makes it easy to test
this middleware:
{{{
@override_settings(MAINTENANCE_MODE=True)
def test_maintenance_mode(self):
@decorator_from_middleware(TemporaryUnavailable)
def view():
raise AssertionError("don't call")
response = view(RequestFactory().get('/')
assert response.status_code == 503
}}}
Of course, I could craft my own get_response, initiate the middleware and
call `__call__` or `process_exception` directly but that is ugly and easy
to get some details wrong, especially when the test involves exceptions.
--
Ticket URL: <https://code.djangoproject.com/ticket/26626#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.9218f49fc03eb93a42c12ed5d39f2817%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.