diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2010-09-28 07:10:05 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2010-09-28 07:10:05 +0000 |
| commit | 66cb5d5aae6d0de993dd1ac972732aea2de8e605 (patch) | |
| tree | 006e44f06c80e6d62808bdbcd14df43c2098f4a5 | |
| parent | 7230b609c3619cbcd503062fecf00871a6087e4d (diff) | |
[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
| -rw-r--r-- | tests/regressiontests/requests/tests.py | 100 |
1 files changed, 57 insertions, 43 deletions
diff --git a/tests/regressiontests/requests/tests.py b/tests/regressiontests/requests/tests.py index 1615a73406..2bf636c3a2 100644 --- a/tests/regressiontests/requests/tests.py +++ b/tests/regressiontests/requests/tests.py @@ -1,47 +1,61 @@ -""" ->>> from django.http import HttpRequest ->>> print repr(HttpRequest()) -<HttpRequest -GET:{}, -POST:{}, -COOKIES:{}, -META:{}> +from datetime import datetime, timedelta +import time +import unittest ->>> 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.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 ->>> 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:{}> +class RequestsTests(unittest.TestCase): ->>> from django.http import parse_cookie ->>> parse_cookie('invalid:key=true') -{} + def test_httprequest(self): + self.assertEquals(repr(HttpRequest()), + "<HttpRequest\n"\ + "GET:{},\n"\ + "POST:{},\n"\ + "COOKIES:{},\n"\ + "META:{}>" + ) ->>> 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 -""" + 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') |
