Browse Source

fix threads tests

Rafał Pitoń 8 years ago
parent
commit
b4229e4ffa

+ 1 - 1
misago/threads/api/threadendpoints/merge.py

@@ -100,7 +100,7 @@ def threads_merge_endpoint(request):
 
 def clean_threads_for_merge(request):
     try:
-        threads_ids = list(map(int, request.data.getlist('threads', [])))
+        threads_ids = list(map(int, request.data.get('threads', [])))
     except (ValueError, TypeError):
         raise MergeError(_("One or more thread ids received were invalid."))
 

+ 4 - 4
misago/threads/models/post.py

@@ -2,7 +2,7 @@ from django.contrib.postgres.fields import JSONField
 from django.core.urlresolvers import reverse
 from django.db import models
 from django.dispatch import receiver
-from django.utils import timezone
+from django.utils import six, timezone
 
 from misago.conf import settings
 
@@ -88,8 +88,8 @@ class Post(models.Model):
         if self.pk == other_post.pk:
             raise ValueError("post can't be merged with itself")
 
-        other_post.original = '%s\n\n%s' % (other_post.original, self.original)
-        other_post.parsed = '%s\n%s' % (other_post.parsed, self.parsed)
+        other_post.original = six.text_type('\n\n').join((other_post.original, self.original))
+        other_post.parsed = six.text_type('\n').join((other_post.parsed, self.parsed))
         update_post_checksum(other_post)
 
         from ..signals import merge_post
@@ -116,7 +116,7 @@ class Post(models.Model):
     def short(self):
         if self.is_valid:
             if len(self.original) > 150:
-                return '%s...' % self.original[:150].strip()
+                return six.text_type('%s...') % self.original[:150].strip()
             else:
                 return self.original
         else:

+ 29 - 46
misago/threads/tests/test_post_model.py

@@ -53,28 +53,13 @@ class PostModelTests(TestCase):
 
     def test_merge_invalid(self):
         """see if attempts for invalid merges fail"""
+        # can't merge with itself
         with self.assertRaises(ValueError):
             self.post.merge(self.post)
 
         User = get_user_model()
         other_user = User.objects.create_user("Jeff", "Je@ff.com", "Pass.123")
 
-        other_post = Post.objects.create(
-            category=self.category,
-            thread=self.thread,
-            poster=other_user,
-            poster_name=other_user.username,
-            poster_ip='127.0.0.1',
-            original="Hello! I am test message!",
-            parsed="<p>Hello! I am test message!</p>",
-            checksum="nope",
-            posted_on=timezone.now() + timedelta(minutes=5),
-            updated_on=timezone.now() + timedelta(minutes=5)
-        )
-
-        with self.assertRaises(ValueError):
-            self.post.merge(other_post)
-
         other_thread = Thread.objects.create(
             category=self.category,
             started_on=timezone.now(),
@@ -85,38 +70,36 @@ class PostModelTests(TestCase):
             last_poster_slug='tester'
         )
 
-        other_post = Post.objects.create(
-            category=self.category,
-            thread=other_thread,
-            poster=self.user,
-            poster_name=self.user.username,
-            poster_ip='127.0.0.1',
-            original="Hello! I am test message!",
-            parsed="<p>Hello! I am test message!</p>",
-            checksum="nope",
-            posted_on=timezone.now() + timedelta(minutes=5),
-            updated_on=timezone.now() + timedelta(minutes=5)
-        )
-
-        with self.assertRaises(ValueError):
-            self.post.merge(other_post)
-
-        other_post = Post.objects.create(
-            category=self.category,
-            thread=self.thread,
-            poster_name=other_user.username,
-            poster_ip='127.0.0.1',
-            original="Hello! I am test message!",
-            parsed="<p>Hello! I am test message!</p>",
-            checksum="nope",
-            posted_on=timezone.now() + timedelta(minutes=5),
-            updated_on=timezone.now() + timedelta(minutes=5)
-        )
-
+        # can't merge across threads
         with self.assertRaises(ValueError):
-            self.post.merge(other_post)
+            self.post.merge(Post.objects.create(
+                category=self.category,
+                thread=other_thread,
+                poster=self.user,
+                poster_name=self.user.username,
+                poster_ip='127.0.0.1',
+                original="Hello! I am test message!",
+                parsed="<p>Hello! I am test message!</p>",
+                checksum="nope",
+                posted_on=timezone.now() + timedelta(minutes=5),
+                updated_on=timezone.now() + timedelta(minutes=5)
+            ))
+
+        # can't merge with events
         with self.assertRaises(ValueError):
-            other_post.merge(self.post)
+            self.post.merge(Post.objects.create(
+                category=self.category,
+                thread=self.thread,
+                poster=self.user,
+                poster_name=self.user.username,
+                poster_ip='127.0.0.1',
+                original="Hello! I am test message!",
+                parsed="<p>Hello! I am test message!</p>",
+                checksum="nope",
+                posted_on=timezone.now() + timedelta(minutes=5),
+                updated_on=timezone.now() + timedelta(minutes=5),
+                is_event=True
+            ))
 
     def test_merge(self):
         """merge method merges two posts into one"""

+ 2 - 2
misago/threads/tests/test_thread_postmerge_api.py

@@ -223,8 +223,8 @@ class ThreadPostMergeApiTestCase(AuthenticatedUserTestCase):
 
     def test_merge_posts(self):
         """api merges two posts"""
-        post_a = testutils.reply_thread(self.thread, poster="Bob", message="Battery")
-        post_b = testutils.reply_thread(self.thread, poster="Bob", message="Horse")
+        post_a = testutils.reply_thread(self.thread, poster="Bob", message="Battęry")
+        post_b = testutils.reply_thread(self.thread, poster="Bob", message="Hórse")
 
         thread_replies = self.thread.replies