|
1 from datetime import datetime, timedelta |
|
2 import time |
|
3 import unittest |
|
4 |
|
5 from django.http import HttpRequest, HttpResponse, parse_cookie |
|
6 from django.core.handlers.wsgi import WSGIRequest |
|
7 from django.core.handlers.modpython import ModPythonRequest |
|
8 from django.utils.http import cookie_date |
|
9 |
|
10 class RequestsTests(unittest.TestCase): |
|
11 |
|
12 def test_httprequest(self): |
|
13 request = HttpRequest() |
|
14 self.assertEqual(request.GET.keys(), []) |
|
15 self.assertEqual(request.POST.keys(), []) |
|
16 self.assertEqual(request.COOKIES.keys(), []) |
|
17 self.assertEqual(request.META.keys(), []) |
|
18 |
|
19 def test_wsgirequest(self): |
|
20 request = WSGIRequest({'PATH_INFO': 'bogus', 'REQUEST_METHOD': 'bogus'}) |
|
21 self.assertEqual(request.GET.keys(), []) |
|
22 self.assertEqual(request.POST.keys(), []) |
|
23 self.assertEqual(request.COOKIES.keys(), []) |
|
24 self.assertEqual(set(request.META.keys()), set(['PATH_INFO', 'REQUEST_METHOD', 'SCRIPT_NAME'])) |
|
25 self.assertEqual(request.META['PATH_INFO'], 'bogus') |
|
26 self.assertEqual(request.META['REQUEST_METHOD'], 'bogus') |
|
27 self.assertEqual(request.META['SCRIPT_NAME'], '') |
|
28 |
|
29 def test_modpythonrequest(self): |
|
30 class FakeModPythonRequest(ModPythonRequest): |
|
31 def __init__(self, *args, **kwargs): |
|
32 super(FakeModPythonRequest, self).__init__(*args, **kwargs) |
|
33 self._get = self._post = self._meta = self._cookies = {} |
|
34 |
|
35 class Dummy: |
|
36 def get_options(self): |
|
37 return {} |
|
38 |
|
39 req = Dummy() |
|
40 req.uri = 'bogus' |
|
41 request = FakeModPythonRequest(req) |
|
42 self.assertEqual(request.path, 'bogus') |
|
43 self.assertEqual(request.GET.keys(), []) |
|
44 self.assertEqual(request.POST.keys(), []) |
|
45 self.assertEqual(request.COOKIES.keys(), []) |
|
46 self.assertEqual(request.META.keys(), []) |
|
47 |
|
48 def test_parse_cookie(self): |
|
49 self.assertEqual(parse_cookie('invalid:key=true'), {}) |
|
50 |
|
51 def test_httprequest_location(self): |
|
52 request = HttpRequest() |
|
53 self.assertEqual(request.build_absolute_uri(location="https://www.example.com/asdf"), |
|
54 'https://www.example.com/asdf') |
|
55 |
|
56 request.get_host = lambda: 'www.example.com' |
|
57 request.path = '' |
|
58 self.assertEqual(request.build_absolute_uri(location="/path/with:colons"), |
|
59 'http://www.example.com/path/with:colons') |