Created
April 18, 2011 12:54
-
-
Save tschellenbach/925270 to your computer and use it in GitHub Desktop.
Fake django requests for testing purposes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.handlers.base import BaseHandler | |
from django.test.client import RequestFactory | |
class RequestMock(RequestFactory): | |
def request(self, **request): | |
"Construct a generic request object." | |
request = RequestFactory.request(self, **request) | |
handler = BaseHandler() | |
handler.load_middleware() | |
for middleware_method in handler._request_middleware: | |
if middleware_method(request): | |
raise Exception("Couldn't create request mock object - " | |
"request middleware returned a response") | |
return request |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment