ソースを参照

Moved some documents tests to correct place

Karl Hobley 6 年 前
コミット
ea7237ec9f

+ 40 - 0
wagtail/documents/tests/test_admin_views.py

@@ -282,6 +282,46 @@ class TestDocumentEditView(TestCase, WagtailTestUtils):
         self.assertContains(response, self.document.usage_url)
         self.assertContains(response, 'Used 0 times')
 
+    def test_reupload_same_name(self):
+        """
+        Checks that reuploading the document file with the same file name
+        changes the file name, to avoid browser cache issues (see #3816).
+        """
+        old_file = self.document.file
+        new_name = self.document.filename
+        new_file = SimpleUploadedFile(new_name, b'An updated test content.')
+
+        response = self.client.post(reverse('wagtaildocs:edit', args=(self.document.pk,)), {
+            'title': self.document.title, 'file': new_file,
+        })
+        self.assertRedirects(response, reverse('wagtaildocs:index'))
+        self.document.refresh_from_db()
+        self.assertFalse(self.document.file.storage.exists(old_file.name))
+        self.assertTrue(self.document.file.storage.exists(self.document.file.name))
+        self.assertNotEqual(self.document.file.name, 'documents/' + new_name)
+        self.assertEqual(self.document.file.read(),
+                         b'An updated test content.')
+
+    def test_reupload_different_name(self):
+        """
+        Checks that reuploading the document file with a different file name
+        correctly uses the new file name.
+        """
+        old_file = self.document.file
+        new_name = 'test_reupload_different_name.txt'
+        new_file = SimpleUploadedFile(new_name, b'An updated test content.')
+
+        response = self.client.post(reverse('wagtaildocs:edit', args=(self.document.pk,)), {
+            'title': self.document.title, 'file': new_file,
+        })
+        self.assertRedirects(response, reverse('wagtaildocs:index'))
+        self.document.refresh_from_db()
+        self.assertFalse(self.document.file.storage.exists(old_file.name))
+        self.assertTrue(self.document.file.storage.exists(self.document.file.name))
+        self.assertEqual(self.document.file.name, 'documents/' + new_name)
+        self.assertEqual(self.document.file.read(),
+                         b'An updated test content.')
+
 
 class TestDocumentDeleteView(TestCase, WagtailTestUtils):
     def setUp(self):

+ 0 - 56
wagtail/documents/tests/test_views.py

@@ -4,67 +4,11 @@ import unittest
 import mock
 from django.conf import settings
 from django.core.files.base import ContentFile
-from django.core.files.uploadedfile import SimpleUploadedFile
 from django.test import TestCase
 from django.test.utils import override_settings
 from django.urls import reverse
 
 from wagtail.documents import models
-from wagtail.tests.utils import WagtailTestUtils
-
-
-class TestEditView(TestCase, WagtailTestUtils):
-    def setUp(self):
-        self.login()
-
-        self.document = models.Document(title='Test')
-        self.document.file.save('test_edit_view.txt',
-                                ContentFile('A test content.'))
-        self.edit_url = reverse('wagtaildocs:edit', args=(self.document.pk,))
-        self.storage = self.document.file.storage
-
-    def update_from_db(self):
-        self.document = models.Document.objects.get(pk=self.document.pk)
-
-    def test_reupload_same_name(self):
-        """
-        Checks that reuploading the document file with the same file name
-        changes the file name, to avoid browser cache issues (see #3816).
-        """
-        old_file = self.document.file
-        new_name = self.document.filename
-        new_file = SimpleUploadedFile(new_name, b'An updated test content.')
-
-        response = self.client.post(self.edit_url, {
-            'title': self.document.title, 'file': new_file,
-        })
-        self.assertRedirects(response, reverse('wagtaildocs:index'))
-        self.update_from_db()
-        self.assertFalse(self.storage.exists(old_file.name))
-        self.assertTrue(self.storage.exists(self.document.file.name))
-        self.assertNotEqual(self.document.file.name, 'documents/' + new_name)
-        self.assertEqual(self.document.file.read(),
-                         b'An updated test content.')
-
-    def test_reupload_different_name(self):
-        """
-        Checks that reuploading the document file with a different file name
-        correctly uses the new file name.
-        """
-        old_file = self.document.file
-        new_name = 'test_reupload_different_name.txt'
-        new_file = SimpleUploadedFile(new_name, b'An updated test content.')
-
-        response = self.client.post(self.edit_url, {
-            'title': self.document.title, 'file': new_file,
-        })
-        self.assertRedirects(response, reverse('wagtaildocs:index'))
-        self.update_from_db()
-        self.assertFalse(self.storage.exists(old_file.name))
-        self.assertTrue(self.storage.exists(self.document.file.name))
-        self.assertEqual(self.document.file.name, 'documents/' + new_name)
-        self.assertEqual(self.document.file.read(),
-                         b'An updated test content.')
 
 
 class TestServeView(TestCase):