Browse Source

Test attachments exports

Rafał Pitoń 6 years ago
parent
commit
fc5135e457
2 changed files with 81 additions and 7 deletions
  1. 11 1
      misago/threads/signals.py
  2. 70 6
      misago/users/tests/test_datadownloads.py

+ 11 - 1
misago/threads/signals.py

@@ -130,7 +130,17 @@ def archive_user_attachments(sender, archive=None, **kwargs):
     queryset = sender.attachment_set.order_by('id')
     queryset = sender.attachment_set.order_by('id')
     for attachment in chunk_queryset(queryset):
     for attachment in chunk_queryset(queryset):
         archive.add_model_file(
         archive.add_model_file(
-            attachment.image or attachment.file,
+            attachment.file,
+            prefix=attachment.uploaded_on.strftime('%H%M%S'),
+            date=attachment.uploaded_on,
+        )
+        archive.add_model_file(
+            attachment.image,
+            prefix=attachment.uploaded_on.strftime('%H%M%S'),
+            date=attachment.uploaded_on,
+        )
+        archive.add_model_file(
+            attachment.thumbnail,
             prefix=attachment.uploaded_on.strftime('%H%M%S'),
             prefix=attachment.uploaded_on.strftime('%H%M%S'),
             date=attachment.uploaded_on,
             date=attachment.uploaded_on,
         )
         )

+ 70 - 6
misago/users/tests/test_datadownloads.py

@@ -2,6 +2,7 @@ import os
 
 
 from django.core.files import File
 from django.core.files import File
 
 
+from misago.threads.models import Attachment, AttachmentType
 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,
     user_has_data_download_request
     user_has_data_download_request
@@ -79,24 +80,87 @@ class PrepareUserDataDownload(AuthenticatedUserTestCase):
 
 
     def test_prepare_download_with_tmp_avatar(self):
     def test_prepare_download_with_tmp_avatar(self):
         """function creates data download for user with tmp avatar"""
         """function creates data download for user with tmp avatar"""
-        with open(TEST_FILE_PATH, 'rb') as download_file:
-            self.user.avatar_tmp = File(download_file)
+        with open(TEST_FILE_PATH, 'rb') as test_file:
+            self.user.avatar_tmp = File(test_file)
             self.user.save()
             self.user.save()
 
 
         self.assert_download_is_valid()
         self.assert_download_is_valid()
 
 
     def test_prepare_download_with_src_avatar(self):
     def test_prepare_download_with_src_avatar(self):
         """function creates data download for user with src avatar"""
         """function creates data download for user with src avatar"""
-        with open(TEST_FILE_PATH, 'rb') as download_file:
-            self.user.avatar_src = File(download_file)
+        with open(TEST_FILE_PATH, 'rb') as test_file:
+            self.user.avatar_src = File(test_file)
             self.user.save()
             self.user.save()
 
 
         self.assert_download_is_valid()
         self.assert_download_is_valid()
 
 
     def test_prepare_download_with_avatar_set(self):
     def test_prepare_download_with_avatar_set(self):
         """function creates data download for user with avatar set"""
         """function creates data download for user with avatar set"""
-        with open(TEST_FILE_PATH, 'rb') as download_file:
-            self.user.avatar_set.create(size=100, image=File(download_file))
+        with open(TEST_FILE_PATH, 'rb') as test_file:
+            self.user.avatar_set.create(size=100, image=File(test_file))
+
+        self.assert_download_is_valid()
+
+    def test_prepare_download_with_file_attachment(self):
+        """function creates data download for user with file attachment"""
+        filetype = AttachmentType.objects.create(
+            name="Test extension",
+            extensions='png',
+            mimetypes='image/png',
+        )
+
+        with open(TEST_FILE_PATH, 'rb') as test_file:
+            self.user.attachment_set.create(
+                secret='test',
+                filetype=filetype,
+                uploader_name=self.user.username,
+                uploader_slug=self.user.slug,
+                filename='test.png',
+                size=1000,
+                file=File(test_file),
+            )
+
+        self.assert_download_is_valid()
+
+    def test_prepare_download_with_image_attachment(self):
+        """function creates data download for user with image attachment"""
+        filetype = AttachmentType.objects.create(
+            name="Test extension",
+            extensions='png',
+            mimetypes='image/png',
+        )
+
+        with open(TEST_FILE_PATH, 'rb') as test_file:
+            self.user.attachment_set.create(
+                secret='test',
+                filetype=filetype,
+                uploader_name=self.user.username,
+                uploader_slug=self.user.slug,
+                filename='test.png',
+                size=1000,
+                image=File(test_file),
+            )
+
+        self.assert_download_is_valid()
+
+    def test_prepare_download_with_thumbnail_attachment(self):
+        """function creates data download for user with thumbnail attachment"""
+        filetype = AttachmentType.objects.create(
+            name="Test extension",
+            extensions='png',
+            mimetypes='image/png',
+        )
+
+        with open(TEST_FILE_PATH, 'rb') as test_file:
+            self.user.attachment_set.create(
+                secret='test',
+                filetype=filetype,
+                uploader_name=self.user.username,
+                uploader_slug=self.user.slug,
+                filename='test.png',
+                size=1000,
+                thumbnail=File(test_file),
+            )
 
 
         self.assert_download_is_valid()
         self.assert_download_is_valid()