Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.2.X] Migrated requests doctests. Thanks to Stephan Jaekel.

Backport of r13927 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@13930 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 66cb5d5aae6d0de993dd1ac972732aea2de8e605 1 parent 7230b60
Russell Keith-Magee authored September 28, 2010

Showing 1 changed file with 61 additions and 47 deletions. Show diff stats Hide diff stats

  1. 108  tests/regressiontests/requests/tests.py
108  tests/regressiontests/requests/tests.py
... ...
@@ -1,47 +1,61 @@
1  
-"""
2  
->>> from django.http import HttpRequest
3  
->>> print repr(HttpRequest())
4  
-<HttpRequest
5  
-GET:{},
6  
-POST:{},
7  
-COOKIES:{},
8  
-META:{}>
9  
-
10  
->>> from django.core.handlers.wsgi import WSGIRequest
11  
->>> print repr(WSGIRequest({'PATH_INFO': 'bogus', 'REQUEST_METHOD': 'bogus'}))
12  
-<WSGIRequest
13  
-GET:<QueryDict: {}>,
14  
-POST:<QueryDict: {}>,
15  
-COOKIES:{},
16  
-META:{...}>
17  
-
18  
->>> from django.core.handlers.modpython import ModPythonRequest
19  
->>> class FakeModPythonRequest(ModPythonRequest):
20  
-...    def __init__(self, *args, **kwargs):
21  
-...        super(FakeModPythonRequest, self).__init__(*args, **kwargs)
22  
-...        self._get = self._post = self._meta = self._cookies = {}
23  
->>> class Dummy:
24  
-...     def get_options(self):
25  
-...         return {}
26  
->>> req = Dummy()
27  
->>> req.uri = 'bogus'
28  
->>> print repr(FakeModPythonRequest(req))
29  
-<ModPythonRequest
30  
-path:bogus,
31  
-GET:{},
32  
-POST:{},
33  
-COOKIES:{},
34  
-META:{}>
35  
-
36  
->>> from django.http import parse_cookie
37  
->>> parse_cookie('invalid:key=true')
38  
-{}
39  
-
40  
->>> request = HttpRequest()
41  
->>> print request.build_absolute_uri(location="https://www.example.com/asdf")
42  
-https://www.example.com/asdf
43  
->>> request.get_host = lambda: 'www.example.com'
44  
->>> request.path = ''
45  
->>> print request.build_absolute_uri(location="/path/with:colons")
46  
-http://www.example.com/path/with:colons
47  
-"""
  1
+from datetime import datetime, timedelta
  2
+import time
  3
+import unittest
  4
+
  5
+from django.http import HttpRequest, HttpResponse, parse_cookie
  6
+from django.core.handlers.wsgi import WSGIRequest
  7
+from django.core.handlers.modpython import ModPythonRequest
  8
+from django.utils.http import cookie_date
  9
+
  10
+class RequestsTests(unittest.TestCase):
  11
+
  12
+    def test_httprequest(self):
  13
+        self.assertEquals(repr(HttpRequest()),
  14
+            "<HttpRequest\n"\
  15
+            "GET:{},\n"\
  16
+            "POST:{},\n"\
  17
+            "COOKIES:{},\n"\
  18
+            "META:{}>"
  19
+        )
  20
+
  21
+    def test_wsgirequest(self):
  22
+        self.assertEquals(repr(WSGIRequest({'PATH_INFO': 'bogus', 'REQUEST_METHOD': 'bogus'})),
  23
+            "<WSGIRequest\n"\
  24
+            "GET:<QueryDict: {}>,\n"\
  25
+            "POST:<QueryDict: {}>,\n"\
  26
+            "COOKIES:{},\n"\
  27
+            "META:{'PATH_INFO': u'bogus', 'REQUEST_METHOD': 'bogus', 'SCRIPT_NAME': u''}>"
  28
+        )
  29
+
  30
+    def test_modpythonrequest(self):
  31
+        class FakeModPythonRequest(ModPythonRequest):
  32
+           def __init__(self, *args, **kwargs):
  33
+               super(FakeModPythonRequest, self).__init__(*args, **kwargs)
  34
+               self._get = self._post = self._meta = self._cookies = {}
  35
+
  36
+        class Dummy:
  37
+            def get_options(self):
  38
+                return {}
  39
+
  40
+        req = Dummy()
  41
+        req.uri = 'bogus'
  42
+        self.assertEquals(repr(FakeModPythonRequest(req)),
  43
+            "<ModPythonRequest\n"\
  44
+            "path:bogus,\n"\
  45
+            "GET:{},\n"\
  46
+            "POST:{},\n"\
  47
+            "COOKIES:{},\n"\
  48
+            "META:{}>")
  49
+
  50
+    def test_parse_cookie(self):
  51
+        self.assertEquals(parse_cookie('invalid:key=true'), {})
  52
+
  53
+    def test_httprequest_location(self):
  54
+        request = HttpRequest()
  55
+        self.assertEquals(request.build_absolute_uri(location="https://www.example.com/asdf"),
  56
+            'https://www.example.com/asdf')
  57
+
  58
+        request.get_host = lambda: 'www.example.com'
  59
+        request.path = ''
  60
+        self.assertEquals(request.build_absolute_uri(location="/path/with:colons"),
  61
+            'http://www.example.com/path/with:colons')

0 notes on commit 66cb5d5

Please sign in to comment.
Something went wrong with that request. Please try again.