Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[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
@freakboy3742 freakboy3742 authored
Showing with 61 additions and 47 deletions.
  1. +61 −47 tests/regressiontests/requests/tests.py
View
108 tests/regressiontests/requests/tests.py
@@ -1,47 +1,61 @@
-"""
->>> from django.http import HttpRequest
->>> print repr(HttpRequest())
-<HttpRequest
-GET:{},
-POST:{},
-COOKIES:{},
-META:{}>
-
->>> from django.core.handlers.wsgi import WSGIRequest
->>> print repr(WSGIRequest({'PATH_INFO': 'bogus', 'REQUEST_METHOD': 'bogus'}))
-<WSGIRequest
-GET:<QueryDict: {}>,
-POST:<QueryDict: {}>,
-COOKIES:{},
-META:{...}>
-
->>> from django.core.handlers.modpython import ModPythonRequest
->>> class FakeModPythonRequest(ModPythonRequest):
-... def __init__(self, *args, **kwargs):
-... super(FakeModPythonRequest, self).__init__(*args, **kwargs)
-... self._get = self._post = self._meta = self._cookies = {}
->>> class Dummy:
-... def get_options(self):
-... return {}
->>> req = Dummy()
->>> req.uri = 'bogus'
->>> print repr(FakeModPythonRequest(req))
-<ModPythonRequest
-path:bogus,
-GET:{},
-POST:{},
-COOKIES:{},
-META:{}>
-
->>> from django.http import parse_cookie
->>> parse_cookie('invalid:key=true')
-{}
-
->>> request = HttpRequest()
->>> print request.build_absolute_uri(location="https://www.example.com/asdf")
-https://www.example.com/asdf
->>> request.get_host = lambda: 'www.example.com'
->>> request.path = ''
->>> print request.build_absolute_uri(location="/path/with:colons")
-http://www.example.com/path/with:colons
-"""
+from datetime import datetime, timedelta
+import time
+import unittest
+
+from django.http import HttpRequest, HttpResponse, parse_cookie
+from django.core.handlers.wsgi import WSGIRequest
+from django.core.handlers.modpython import ModPythonRequest
+from django.utils.http import cookie_date
+
+class RequestsTests(unittest.TestCase):
+
+ def test_httprequest(self):
+ self.assertEquals(repr(HttpRequest()),
+ "<HttpRequest\n"\
+ "GET:{},\n"\
+ "POST:{},\n"\
+ "COOKIES:{},\n"\
+ "META:{}>"
+ )
+
+ def test_wsgirequest(self):
+ self.assertEquals(repr(WSGIRequest({'PATH_INFO': 'bogus', 'REQUEST_METHOD': 'bogus'})),
+ "<WSGIRequest\n"\
+ "GET:<QueryDict: {}>,\n"\
+ "POST:<QueryDict: {}>,\n"\
+ "COOKIES:{},\n"\
+ "META:{'PATH_INFO': u'bogus', 'REQUEST_METHOD': 'bogus', 'SCRIPT_NAME': u''}>"
+ )
+
+ def test_modpythonrequest(self):
+ class FakeModPythonRequest(ModPythonRequest):
+ def __init__(self, *args, **kwargs):
+ super(FakeModPythonRequest, self).__init__(*args, **kwargs)
+ self._get = self._post = self._meta = self._cookies = {}
+
+ class Dummy:
+ def get_options(self):
+ return {}
+
+ req = Dummy()
+ req.uri = 'bogus'
+ self.assertEquals(repr(FakeModPythonRequest(req)),
+ "<ModPythonRequest\n"\
+ "path:bogus,\n"\
+ "GET:{},\n"\
+ "POST:{},\n"\
+ "COOKIES:{},\n"\
+ "META:{}>")
+
+ def test_parse_cookie(self):
+ self.assertEquals(parse_cookie('invalid:key=true'), {})
+
+ def test_httprequest_location(self):
+ request = HttpRequest()
+ self.assertEquals(request.build_absolute_uri(location="https://www.example.com/asdf"),
+ 'https://www.example.com/asdf')
+
+ request.get_host = lambda: 'www.example.com'
+ request.path = ''
+ self.assertEquals(request.build_absolute_uri(location="/path/with:colons"),
+ 'http://www.example.com/path/with:colons')
Please sign in to comment.
Something went wrong with that request. Please try again.