Commit fd52ff29ab991c8f586d09a1f65cdc34673331de

Authored by Claude Paroz
1 parent 8112496f

Used the first() queryset method

@@ -119,7 +119,7 @@ class CommentViewTests(CommentTestCase): @@ -119,7 +119,7 @@ class CommentViewTests(CommentTestCase):
119 response = self.client.post("/post/", data, REMOTE_ADDR=address) 119 response = self.client.post("/post/", data, REMOTE_ADDR=address)
120 self.assertEqual(response.status_code, 302) 120 self.assertEqual(response.status_code, 302)
121 self.assertEqual(Comment.objects.count(), 1) 121 self.assertEqual(Comment.objects.count(), 1)
122 - c = Comment.objects.all()[0] 122 + c = Comment.objects.first()
123 self.assertEqual(c.ip_address, address) 123 self.assertEqual(c.ip_address, address)
124 self.assertEqual(c.comment, "This is my comment") 124 self.assertEqual(c.comment, "This is my comment")
125 125
@@ -136,7 +136,7 @@ class CommentViewTests(CommentTestCase): @@ -136,7 +136,7 @@ class CommentViewTests(CommentTestCase):
136 response = self.client.post("/post/", data, REMOTE_ADDR=address) 136 response = self.client.post("/post/", data, REMOTE_ADDR=address)
137 self.assertEqual(response.status_code, 302) 137 self.assertEqual(response.status_code, 302)
138 self.assertEqual(Comment.objects.count(), 1) 138 self.assertEqual(Comment.objects.count(), 1)
139 - c = Comment.objects.all()[0] 139 + c = Comment.objects.first()
140 self.assertEqual(c.ip_address, address) 140 self.assertEqual(c.ip_address, address)
141 self.assertEqual(c.comment, "This is my comment") 141 self.assertEqual(c.comment, "This is my comment")
142 142
@@ -156,7 +156,7 @@ class CommentViewTests(CommentTestCase): @@ -156,7 +156,7 @@ class CommentViewTests(CommentTestCase):
156 response = self.client.post("/post/", data, REMOTE_ADDR=address) 156 response = self.client.post("/post/", data, REMOTE_ADDR=address)
157 self.assertEqual(response.status_code, 302) 157 self.assertEqual(response.status_code, 302)
158 self.assertEqual(Comment.objects.count(), 1) 158 self.assertEqual(Comment.objects.count(), 1)
159 - c = Comment.objects.all()[0] 159 + c = Comment.objects.first()
160 # We trim the '::ffff:' bit off because it is an IPv4 addr 160 # We trim the '::ffff:' bit off because it is an IPv4 addr
161 self.assertEqual(c.ip_address, address[7:]) 161 self.assertEqual(c.ip_address, address[7:])
162 self.assertEqual(c.comment, "This is my comment") 162 self.assertEqual(c.comment, "This is my comment")
@@ -169,7 +169,7 @@ class CommentViewTests(CommentTestCase): @@ -169,7 +169,7 @@ class CommentViewTests(CommentTestCase):
169 response = self.client.post("/post/", data, REMOTE_ADDR="1.2.3.4") 169 response = self.client.post("/post/", data, REMOTE_ADDR="1.2.3.4")
170 self.assertEqual(response.status_code, 302) 170 self.assertEqual(response.status_code, 302)
171 self.assertEqual(Comment.objects.count(), 1) 171 self.assertEqual(Comment.objects.count(), 1)
172 - c = Comment.objects.all()[0] 172 + c = Comment.objects.first()
173 self.assertEqual(c.ip_address, "1.2.3.4") 173 self.assertEqual(c.ip_address, "1.2.3.4")
174 u = User.objects.get(username='normaluser') 174 u = User.objects.get(username='normaluser')
175 self.assertEqual(c.user, u) 175 self.assertEqual(c.user, u)
@@ -255,7 +255,7 @@ class CommentViewTests(CommentTestCase): @@ -255,7 +255,7 @@ class CommentViewTests(CommentTestCase):
255 255
256 signals.comment_will_be_posted.connect(receive) 256 signals.comment_will_be_posted.connect(receive)
257 self.testCreateValidComment() 257 self.testCreateValidComment()
258 - c = Comment.objects.all()[0] 258 + c = Comment.objects.first()
259 self.assertFalse(c.is_public) 259 self.assertFalse(c.is_public)
260 260
261 def testCommentNext(self): 261 def testCommentNext(self):
@@ -291,7 +291,7 @@ class CommentViewTests(CommentTestCase): @@ -291,7 +291,7 @@ class CommentViewTests(CommentTestCase):
291 pk = int(match.group('pk')) 291 pk = int(match.group('pk'))
292 response = self.client.get(location) 292 response = self.client.get(location)
293 self.assertTemplateUsed(response, "comments/posted.html") 293 self.assertTemplateUsed(response, "comments/posted.html")
294 - self.assertEqual(response.context[0]["comment"], Comment.objects.get(pk=pk)) 294 + self.assertEqual(response.context["comment"], Comment.objects.get(pk=pk))
295 295
296 def testCommentNextWithQueryString(self): 296 def testCommentNextWithQueryString(self):
297 """ 297 """
Please register or login to post a comment