mirror of
https://github.com/django/django.git
synced 2025-07-04 17:59:13 +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 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')
|
||||
|
Loading…
x
Reference in New Issue
Block a user