Browse Source

Test data download with posts and posts edits

Rafał Pitoń 6 years ago
parent
commit
c085cf3187
2 changed files with 70 additions and 1 deletions
  1. 5 1
      misago/threads/signals.py
  2. 65 0
      misago/users/tests/test_datadownloads.py

+ 5 - 1
misago/threads/signals.py

@@ -156,7 +156,11 @@ def archive_user_posts(sender, archive=None, **kwargs):
 
 
 @receiver(archive_user_data)
 @receiver(archive_user_data)
 def archive_user_posts_edits(sender, archive=None, **kwargs):
 def archive_user_posts_edits(sender, archive=None, **kwargs):
-    queryset = sender.postedit_set.order_by('id')
+    queryset = PostEdit.objects.filter(post__poster=sender).order_by('id')
+    for post_edit in chunk_queryset(queryset):
+        item_name = post_edit.edited_on.strftime('%H%M%S-post-edit')
+        archive.add_text(item_name, post_edit.edited_from, date=post_edit.edited_on)
+    queryset = sender.postedit_set.exclude(id__in=queryset.values('id')).order_by('id')
     for post_edit in chunk_queryset(queryset):
     for post_edit in chunk_queryset(queryset):
         item_name = post_edit.edited_on.strftime('%H%M%S-post-edit')
         item_name = post_edit.edited_on.strftime('%H%M%S-post-edit')
         archive.add_text(item_name, post_edit.edited_from, date=post_edit.edited_on)
         archive.add_text(item_name, post_edit.edited_from, date=post_edit.edited_on)

+ 65 - 0
misago/users/tests/test_datadownloads.py

@@ -2,7 +2,9 @@ import os
 
 
 from django.core.files import File
 from django.core.files import File
 
 
+from misago.categories.models import Category
 from misago.threads.models import Attachment, AttachmentType
 from misago.threads.models import Attachment, AttachmentType
+from misago.threads.testutils import post_thread
 from misago.users.audittrail import create_user_audit_trail
 from misago.users.audittrail import create_user_audit_trail
 from misago.users.datadownloads import (
 from misago.users.datadownloads import (
     expire_user_data_download, prepare_user_data_download, request_user_data_download,
     expire_user_data_download, prepare_user_data_download, request_user_data_download,
@@ -191,6 +193,69 @@ class PrepareUserDataDownload(AuthenticatedUserTestCase):
 
 
         self.assert_download_is_valid()
         self.assert_download_is_valid()
 
 
+    def test_prepare_download_with_post(self):
+        """function creates data download for user with post"""
+        category = Category.objects.get(slug='first-category')
+        post_thread(category, poster=self.user)
+
+        self.assert_download_is_valid()
+
+    def test_prepare_download_with_owm_post_edit(self):
+        """function creates data download for user with own post edit"""
+        category = Category.objects.get(slug='first-category')
+        thread = post_thread(category, poster=self.user)
+        post = thread.first_post
+
+        post.edits_record.create(
+            category=category,
+            thread=thread,
+            editor=self.user,
+            editor_name=self.user.username,
+            editor_slug=self.user.slug,
+            edited_from="edited from",
+            edited_to="edited to",
+        )
+
+        self.assert_download_is_valid()
+
+    def test_prepare_download_with_other_users_post_edit(self):
+        """function creates data download for user with other user's post edit"""
+        category = Category.objects.get(slug='first-category')
+        thread = post_thread(category)
+        post = thread.first_post
+
+        post.edits_record.create(
+            category=category,
+            thread=thread,
+            editor=self.user,
+            editor_name=self.user.username,
+            editor_slug=self.user.slug,
+            edited_from="edited from",
+            edited_to="edited to",
+        )
+
+        self.assert_download_is_valid()
+
+    def test_prepare_download_with_own_post_edit_by_staff(self):
+        """function creates data download for user with post edited by staff"""
+        category = Category.objects.get(slug='first-category')
+        thread = post_thread(category, poster=self.user)
+        post = thread.first_post
+
+        staff_user = self.get_superuser()
+
+        post.edits_record.create(
+            category=category,
+            thread=thread,
+            editor=staff_user,
+            editor_name=staff_user.username,
+            editor_slug=staff_user.slug,
+            edited_from="edited from",
+            edited_to="edited to",
+        )
+
+        self.assert_download_is_valid()
+
 
 
 class RequestUserDataDownloadTests(AuthenticatedUserTestCase):
 class RequestUserDataDownloadTests(AuthenticatedUserTestCase):
     def test_util_creates_data_download_for_user_with_them_as_requester(self):
     def test_util_creates_data_download_for_user_with_them_as_requester(self):