Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Fixing the MockHttpRequest helper #9

Merged
merged 2 commits into from about 1 year ago

2 participants

Jannis Leidel David Cramer
Jannis Leidel

No description provided.

added some commits December 20, 2012
Jannis Leidel Correctly define the raw_post_data property. bb13fa3
Jannis Leidel Renamed the `url` parameter of the MockHttpRequest to `path` since th…
…at's what I expected it to be.

Also added a SERVER_PORT value to the default META so the `build_absolute_uri` method actually works.
c12f891
David Cramer dcramer merged commit 7ab8e2c into from January 23, 2013
David Cramer dcramer closed this January 23, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Dec 20, 2012
Jannis Leidel Correctly define the raw_post_data property. bb13fa3
Jannis Leidel Renamed the `url` parameter of the MockHttpRequest to `path` since th…
…at's what I expected it to be.

Also added a SERVER_PORT value to the default META so the `build_absolute_uri` method actually works.
c12f891
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 4 additions and 8 deletions. Show diff stats Hide diff stats

  1. 12  mock_django/http.py
12  mock_django/http.py
@@ -6,7 +6,6 @@
6 6
 :license: Apache License 2.0, see LICENSE for more details.
7 7
 """
8 8
 
9  
-from mock import Mock
10 9
 from django.contrib.auth.models import AnonymousUser
11 10
 from django.http import HttpRequest
12 11
 from django.utils.datastructures import MergeDict
@@ -20,7 +19,6 @@ def __init__(self, *args, **kwargs):
20 19
         super(WsgiHttpRequest, self).__init__(*args, **kwargs)
21 20
         self.user = AnonymousUser()
22 21
         self.session = {}
23  
-        self.url = '/'
24 22
         self.META = {}
25 23
         self.GET = {}
26 24
         self.POST = {}
@@ -31,9 +29,6 @@ def _get_request(self):
31 29
         return self._request
32 30
     REQUEST = property(_get_request)
33 31
 
34  
-    def build_absolute_uri(self, location=None):
35  
-        return self.url
36  
-
37 32
     def _get_raw_post_data(self):
38 33
         if not hasattr(self, '_raw_post_data'):
39 34
             self._raw_post_data = urlencode(self.POST)
@@ -42,10 +37,10 @@ def _get_raw_post_data(self):
42 37
     def _set_raw_post_data(self, data):
43 38
         self._raw_post_data = data
44 39
         self.POST = {}
45  
-    raw_post_data = property(_set_raw_post_data)
  40
+    raw_post_data = property(_get_raw_post_data, _set_raw_post_data)
46 41
 
47 42
 
48  
-def MockHttpRequest(url='/', method='GET', GET=None, POST=None, META=None):
  43
+def MockHttpRequest(path='/', method='GET', GET=None, POST=None, META=None):
49 44
     if GET is None:
50 45
         GET = {}
51 46
     if POST is None:
@@ -55,12 +50,13 @@ def MockHttpRequest(url='/', method='GET', GET=None, POST=None, META=None):
55 50
     if META is None:
56 51
         META = {
57 52
             'REMOTE_ADDR': '127.0.0.1',
  53
+            'SERVER_PORT': '8000',
58 54
             'HTTP_REFERER': '',
59 55
             'SERVER_NAME': 'testserver',
60 56
         }
61 57
 
62 58
     request = WsgiHttpRequest()
63  
-    request.url = url
  59
+    request.path = request.path_info = path
64 60
     request.method = method
65 61
     request.META = META
66 62
     request.GET = GET
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.