Changeset 3875
- Timestamp:
- 09/27/06 20:56:02 (2 years ago)
- Files:
-
- django/trunk/django/core/handlers/base.py (modified) (3 diffs)
- django/trunk/django/core/handlers/modpython.py (modified) (1 diff)
- django/trunk/django/core/handlers/wsgi.py (modified) (2 diffs)
- django/trunk/django/test/client.py (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/core/handlers/base.py
r3411 r3875 49 49 self._exception_middleware.insert(0, mw_instance.process_exception) 50 50 51 def get_response(self, path,request):51 def get_response(self, request): 52 52 "Returns an HttpResponse object for the given HttpRequest" 53 53 from django.core import exceptions, urlresolvers … … 63 63 resolver = urlresolvers.RegexURLResolver(r'^/', settings.ROOT_URLCONF) 64 64 try: 65 callback, callback_args, callback_kwargs = resolver.resolve( path)65 callback, callback_args, callback_kwargs = resolver.resolve(request.path) 66 66 67 67 # Apply view middleware … … 106 106 receivers = dispatcher.send(signal=signals.got_request_exception) 107 107 # When DEBUG is False, send an error message to the admins. 108 subject = 'Error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS and 'internal' or 'EXTERNAL'), getattr(request, 'path', ''))108 subject = 'Error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS and 'internal' or 'EXTERNAL'), request.path) 109 109 try: 110 110 request_repr = repr(request) django/trunk/django/core/handlers/modpython.py
r3866 r3875 151 151 try: 152 152 request = ModPythonRequest(req) 153 response = self.get_response(req .uri, request)153 response = self.get_response(request) 154 154 155 155 # Apply response middleware django/trunk/django/core/handlers/wsgi.py
r3820 r3875 75 75 self.environ = environ 76 76 self.path = environ['PATH_INFO'] 77 self.META = environ 77 self.META = environ 78 78 self.method = environ['REQUEST_METHOD'].upper() 79 79 … … 187 187 try: 188 188 request = WSGIRequest(environ) 189 response = self.get_response(request .path, request)189 response = self.get_response(request) 190 190 191 191 # Apply response middleware django/trunk/django/test/client.py
r3707 r3875 9 9 class ClientHandler(BaseHandler): 10 10 """ 11 A HTTP Handler that can be used for testing purposes. 11 A HTTP Handler that can be used for testing purposes. 12 12 Uses the WSGI interface to compose requests, but returns 13 13 the raw HttpResponse object … … 25 25 try: 26 26 request = WSGIRequest(environ) 27 response = self.get_response(request .path, request)27 response = self.get_response(request) 28 28 29 29 # Apply response middleware … … 33 33 finally: 34 34 dispatcher.send(signal=signals.request_finished) 35 35 36 36 return response 37 37 … … 45 45 A simple method for encoding multipart POST data from a dictionary of 46 46 form values. 47 47 48 48 The key will be used as the form data name; the value will be transmitted 49 49 as content. If the value is a file, the contents of the file will be sent … … 70 70 str(value) 71 71 ]) 72 72 73 73 lines.extend([ 74 74 '--' + boundary + '--', … … 79 79 class Client: 80 80 """ 81 A class that can act as a client for testing purposes. 82 81 A class that can act as a client for testing purposes. 82 83 83 It allows the user to compose GET and POST requests, and 84 84 obtain the response that the server gave to those requests. … … 89 89 Client objects are stateful - they will retain cookie (and 90 90 thus session) details for the lifetime of the Client instance. 91 91 92 92 This is not intended as a replacement for Twill/Selenium or 93 93 the like - it is here to allow testing against the … … 99 99 self.defaults = defaults 100 100 self.cookie = SimpleCookie() 101 101 102 102 def request(self, **request): 103 103 """ 104 The master request method. Composes the environment dictionary 104 The master request method. Composes the environment dictionary 105 105 and passes to the handler, returning the result of the handler. 106 106 Assumes defaults for the query environment, which can be overridden … … 113 113 'QUERY_STRING': '', 114 114 'REQUEST_METHOD': 'GET', 115 'SCRIPT_NAME': None, 115 'SCRIPT_NAME': None, 116 116 'SERVER_NAME': 'testserver', 117 117 'SERVER_PORT': 80, 118 118 'SERVER_PROTOCOL': 'HTTP/1.1', 119 } 119 } 120 120 environ.update(self.defaults) 121 environ.update(request) 121 environ.update(request) 122 122 123 123 # Curry a data dictionary into an instance of … … 126 126 on_template_render = curry(store_rendered_templates, data) 127 127 dispatcher.connect(on_template_render, signal=signals.template_rendered) 128 128 129 129 response = self.handler(environ) 130 130 131 131 # Add any rendered template detail to the response 132 # If there was only one template rendered (the most likely case), 132 # If there was only one template rendered (the most likely case), 133 133 # flatten the list to a single element 134 134 for detail in ('template', 'context'): … … 140 140 else: 141 141 setattr(response, detail, None) 142 142 143 143 if response.cookies: 144 144 self.cookie.update(response.cookies) 145 145 146 146 return response 147 147 148 148 def get(self, path, data={}, **extra): 149 149 "Request a response from the server using GET." … … 156 156 } 157 157 r.update(extra) 158 158 159 159 return self.request(**r) 160 160 161 161 def post(self, path, data={}, **extra): 162 162 "Request a response from the server using POST." 163 163 164 164 BOUNDARY = 'BoUnDaRyStRiNg' 165 165 … … 174 174 } 175 175 r.update(extra) 176 176 177 177 return self.request(**r) 178 178 … … 181 181 A specialized sequence of GET and POST to log into a view that 182 182 is protected by a @login_required access decorator. 183 183 184 184 path should be the URL of the page that is login protected. 185 186 Returns the response from GETting the requested URL after 185 186 Returns the response from GETting the requested URL after 187 187 login is complete. Returns False if login process failed. 188 188 """ 189 # First, GET the page that is login protected. 189 # First, GET the page that is login protected. 190 190 # This page will redirect to the login page. 191 191 response = self.get(path) 192 192 if response.status_code != 302: 193 193 return False 194 194 195 195 login_path, data = response['Location'].split('?') 196 196 next = data.split('=')[1] … … 200 200 if response.status_code != 200: 201 201 return False 202 202 203 203 # Last, POST the login data. 204 204 form_data = {
