File: tests.py

package info (click to toggle)
python-django 1.2.3-3%2Bsqueeze10
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 29,064 kB
  • ctags: 20,458
  • sloc: python: 101,293; xml: 574; makefile: 149; sh: 121; sql: 7
file content (47 lines) | stat: -rw-r--r-- 1,257 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
>>> 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
"""