Browse Source

use order_by().last() instead of slice in tests

Rafał Pitoń 8 years ago
parent
commit
d1cd4af166

+ 7 - 7
misago/threads/tests/test_post_mentions.py

@@ -48,7 +48,7 @@ class PostMentionsTests(AuthenticatedUserTestCase):
         })
         self.assertEqual(response.status_code, 200)
 
-        post = self.user.post_set.order_by('-id')[:1][0]
+        post = self.user.post_set.order_by('id').last()
         self.assertEqual(post.mentions.count(), 0)
 
     def test_mention_nonexistant(self):
@@ -58,7 +58,7 @@ class PostMentionsTests(AuthenticatedUserTestCase):
         })
         self.assertEqual(response.status_code, 200)
 
-        post = self.user.post_set.order_by('-id')[:1][0]
+        post = self.user.post_set.order_by('id').last()
         self.assertEqual(post.mentions.count(), 0)
 
     def test_mention_self(self):
@@ -68,7 +68,7 @@ class PostMentionsTests(AuthenticatedUserTestCase):
         })
         self.assertEqual(response.status_code, 200)
 
-        post = self.user.post_set.order_by('-id')[:1][0]
+        post = self.user.post_set.order_by('id').last()
 
         self.assertEqual(post.mentions.count(), 1)
         self.assertEqual(post.mentions.all()[0], self.user)
@@ -91,7 +91,7 @@ class PostMentionsTests(AuthenticatedUserTestCase):
         })
         self.assertEqual(response.status_code, 200)
 
-        post = self.user.post_set.order_by('-id')[:1][0]
+        post = self.user.post_set.order_by('id').last()
 
         self.assertEqual(post.mentions.count(), 24)
         self.assertEqual(list(post.mentions.order_by('id')), users[:24])
@@ -107,7 +107,7 @@ class PostMentionsTests(AuthenticatedUserTestCase):
         })
         self.assertEqual(response.status_code, 200)
 
-        post = self.user.post_set.order_by('-id')[:1][0]
+        post = self.user.post_set.order_by('id').last()
 
         self.assertEqual(post.mentions.count(), 1)
         self.assertEqual(post.mentions.all()[0], user_a)
@@ -158,7 +158,7 @@ class PostMentionsTests(AuthenticatedUserTestCase):
         })
         self.assertEqual(response.status_code, 200)
 
-        post_a = self.user.post_set.order_by('-id')[:1][0]
+        post_a = self.user.post_set.order_by('id').last()
 
         self.assertEqual(post_a.mentions.count(), 1)
         self.assertEqual(list(post_a.mentions.all()), [user_a])
@@ -172,7 +172,7 @@ class PostMentionsTests(AuthenticatedUserTestCase):
         })
         self.assertEqual(response.status_code, 200)
 
-        post_b = self.user.post_set.order_by('-id')[:1][0]
+        post_b = self.user.post_set.order_by('id').last()
 
         # merge posts and validate that post A has all mentions
         post_b.merge(post_a)

+ 3 - 3
misago/threads/tests/test_thread_editreply_api.py

@@ -202,7 +202,7 @@ class EditReplyTests(AuthenticatedUserTestCase):
         response = self.client.get(self.thread.get_absolute_url())
         self.assertContains(response, "<p>This is test edit!</p>")
 
-        post = self.thread.post_set.all()[:1][0]
+        post = self.thread.post_set.order_by('id').last()
         self.assertEqual(post.edits, 1)
         self.assertEqual(post.original, "This is test edit!")
         self.assertEqual(post.last_editor_id, self.user.id)
@@ -243,7 +243,7 @@ class EditReplyTests(AuthenticatedUserTestCase):
         })
         self.assertEqual(response.status_code, 200)
 
-        post = self.user.post_set.all()[:1][0]
+        post = self.user.post_set.order_by('id').last()
         self.assertTrue(post.is_protected)
 
     def test_protect_post_no_permission(self):
@@ -258,7 +258,7 @@ class EditReplyTests(AuthenticatedUserTestCase):
         })
         self.assertEqual(response.status_code, 200)
 
-        post = self.user.post_set.all()[:1][0]
+        post = self.user.post_set.order_by('id').last()
         self.assertFalse(post.is_protected)
 
     def test_post_unicode(self):