mirror of
https://github.com/django/django.git
synced 2025-07-06 10:49:17 +00:00
[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
This commit is contained in:
parent
7230b609c3
commit
66cb5d5aae
@ -1,47 +1,61 @@
|
|||||||
"""
|
from datetime import datetime, timedelta
|
||||||
>>> from django.http import HttpRequest
|
import time
|
||||||
>>> print repr(HttpRequest())
|
import unittest
|
||||||
<HttpRequest
|
|
||||||
GET:{},
|
|
||||||
POST:{},
|
|
||||||
COOKIES:{},
|
|
||||||
META:{}>
|
|
||||||
|
|
||||||
>>> from django.core.handlers.wsgi import WSGIRequest
|
from django.http import HttpRequest, HttpResponse, parse_cookie
|
||||||
>>> print repr(WSGIRequest({'PATH_INFO': 'bogus', 'REQUEST_METHOD': 'bogus'}))
|
from django.core.handlers.wsgi import WSGIRequest
|
||||||
<WSGIRequest
|
from django.core.handlers.modpython import ModPythonRequest
|
||||||
GET:<QueryDict: {}>,
|
from django.utils.http import cookie_date
|
||||||
POST:<QueryDict: {}>,
|
|
||||||
COOKIES:{},
|
|
||||||
META:{...}>
|
|
||||||
|
|
||||||
>>> from django.core.handlers.modpython import ModPythonRequest
|
class RequestsTests(unittest.TestCase):
|
||||||
>>> 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
|
def test_httprequest(self):
|
||||||
>>> parse_cookie('invalid:key=true')
|
self.assertEquals(repr(HttpRequest()),
|
||||||
{}
|
"<HttpRequest\n"\
|
||||||
|
"GET:{},\n"\
|
||||||
|
"POST:{},\n"\
|
||||||
|
"COOKIES:{},\n"\
|
||||||
|
"META:{}>"
|
||||||
|
)
|
||||||
|
|
||||||
>>> request = HttpRequest()
|
def test_wsgirequest(self):
|
||||||
>>> print request.build_absolute_uri(location="https://www.example.com/asdf")
|
self.assertEquals(repr(WSGIRequest({'PATH_INFO': 'bogus', 'REQUEST_METHOD': 'bogus'})),
|
||||||
https://www.example.com/asdf
|
"<WSGIRequest\n"\
|
||||||
>>> request.get_host = lambda: 'www.example.com'
|
"GET:<QueryDict: {}>,\n"\
|
||||||
>>> request.path = ''
|
"POST:<QueryDict: {}>,\n"\
|
||||||
>>> print request.build_absolute_uri(location="/path/with:colons")
|
"COOKIES:{},\n"\
|
||||||
http://www.example.com/path/with:colons
|
"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')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user