Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Modified the requests unit tests so that they aren't dependent on dic…

…tionary ordering.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13948 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 75536fef1ff56894e35dad221a4215ebe3917673 1 parent 778cfe3
Russell Keith-Magee authored September 28, 2010

Showing 1 changed file with 24 additions and 26 deletions. Show diff stats Hide diff stats

  1. 50  tests/regressiontests/requests/tests.py
50  tests/regressiontests/requests/tests.py
@@ -10,22 +10,21 @@
10 10
 class RequestsTests(unittest.TestCase):
11 11
 
12 12
     def test_httprequest(self):
13  
-        self.assertEquals(repr(HttpRequest()),
14  
-            "<HttpRequest\n"\
15  
-            "GET:{},\n"\
16  
-            "POST:{},\n"\
17  
-            "COOKIES:{},\n"\
18  
-            "META:{}>"
19  
-        )
  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(), [])
20 18
 
21 19
     def test_wsgirequest(self):
22  
-        self.assertEquals(repr(WSGIRequest({'PATH_INFO': 'bogus', 'REQUEST_METHOD': 'bogus'})),
23  
-            "<WSGIRequest\n"\
24  
-            "GET:<QueryDict: {}>,\n"\
25  
-            "POST:<QueryDict: {}>,\n"\
26  
-            "COOKIES:{},\n"\
27  
-            "META:{'PATH_INFO': u'bogus', 'REQUEST_METHOD': 'bogus', 'SCRIPT_NAME': u''}>"
28  
-        )
  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'], '')
29 28
 
30 29
     def test_modpythonrequest(self):
31 30
         class FakeModPythonRequest(ModPythonRequest):
@@ -39,25 +38,24 @@ def get_options(self):
39 38
 
40 39
         req = Dummy()
41 40
         req.uri = 'bogus'
42  
-        self.assertEquals(repr(FakeModPythonRequest(req)),
43  
-            "<ModPythonRequest\n"\
44  
-            "path:bogus,\n"\
45  
-            "GET:{},\n"\
46  
-            "POST:{},\n"\
47  
-            "COOKIES:{},\n"\
48  
-            "META:{}>")
  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(), [])
49 47
 
50 48
     def test_parse_cookie(self):
51  
-        self.assertEquals(parse_cookie('invalid:key=true'), {})
  49
+        self.assertEqual(parse_cookie('invalid:key=true'), {})
52 50
 
53 51
     def test_httprequest_location(self):
54 52
         request = HttpRequest()
55  
-        self.assertEquals(request.build_absolute_uri(location="https://www.example.com/asdf"),
  53
+        self.assertEqual(request.build_absolute_uri(location="https://www.example.com/asdf"),
56 54
             'https://www.example.com/asdf')
57 55
 
58 56
         request.get_host = lambda: 'www.example.com'
59 57
         request.path = ''
60  
-        self.assertEquals(request.build_absolute_uri(location="/path/with:colons"),
  58
+        self.assertEqual(request.build_absolute_uri(location="/path/with:colons"),
61 59
             'http://www.example.com/path/with:colons')
62 60
 
63 61
     def test_near_expiration(self):
@@ -74,14 +72,14 @@ def test_near_expiration(self):
74 72
         time.sleep(0.001)
75 73
         response.set_cookie('datetime', expires=expires)
76 74
         datetime_cookie = response.cookies['datetime']
77  
-        self.assertEquals(datetime_cookie['max-age'], 10)
  75
+        self.assertEqual(datetime_cookie['max-age'], 10)
78 76
 
79 77
     def test_far_expiration(self):
80 78
         "Cookie will expire when an distant expiration time is provided"
81 79
         response = HttpResponse()
82 80
         response.set_cookie('datetime', expires=datetime(2028, 1, 1, 4, 5, 6))
83 81
         datetime_cookie = response.cookies['datetime']
84  
-        self.assertEquals(datetime_cookie['expires'], 'Sat, 01-Jan-2028 04:05:06 GMT')
  82
+        self.assertEqual(datetime_cookie['expires'], 'Sat, 01-Jan-2028 04:05:06 GMT')
85 83
 
86 84
     def test_max_age_expiration(self):
87 85
         "Cookie will expire if max_age is provided"

0 notes on commit 75536fe

Please sign in to comment.
Something went wrong with that request. Please try again.