Browse Source

Make tests compatible with Django 1.10

TheKit 8 years ago
parent
commit
365e57ea20

+ 5 - 4
misago/categories/tests/test_prunecategories.py

@@ -1,5 +1,6 @@
 from datetime import timedelta
 from datetime import timedelta
 
 
+from django.core.management import call_command
 from django.test import TestCase
 from django.test import TestCase
 from django.utils import timezone
 from django.utils import timezone
 from django.utils.six import StringIO
 from django.utils.six import StringIO
@@ -37,7 +38,7 @@ class PruneCategoriesTests(TestCase):
         command = prunecategories.Command()
         command = prunecategories.Command()
 
 
         out = StringIO()
         out = StringIO()
-        command.execute(stdout=out)
+        call_command(command, stdout=out)
 
 
         category.synchronize()
         category.synchronize()
         self.assertEqual(category.threads, 10)
         self.assertEqual(category.threads, 10)
@@ -73,7 +74,7 @@ class PruneCategoriesTests(TestCase):
         command = prunecategories.Command()
         command = prunecategories.Command()
 
 
         out = StringIO()
         out = StringIO()
-        command.execute(stdout=out)
+        call_command(command, stdout=out)
 
 
         category.synchronize()
         category.synchronize()
         self.assertEqual(category.threads, 10)
         self.assertEqual(category.threads, 10)
@@ -119,7 +120,7 @@ class PruneCategoriesTests(TestCase):
         command = prunecategories.Command()
         command = prunecategories.Command()
 
 
         out = StringIO()
         out = StringIO()
-        command.execute(stdout=out)
+        call_command(command, stdout=out)
 
 
         category.synchronize()
         category.synchronize()
         self.assertEqual(category.threads, 10)
         self.assertEqual(category.threads, 10)
@@ -168,7 +169,7 @@ class PruneCategoriesTests(TestCase):
         command = prunecategories.Command()
         command = prunecategories.Command()
 
 
         out = StringIO()
         out = StringIO()
-        command.execute(stdout=out)
+        call_command(command, stdout=out)
 
 
         category.synchronize()
         category.synchronize()
         self.assertEqual(category.threads, 10)
         self.assertEqual(category.threads, 10)

+ 2 - 1
misago/categories/tests/test_synchronizecategories.py

@@ -1,3 +1,4 @@
+from django.core.management import call_command
 from django.test import TestCase
 from django.test import TestCase
 from django.utils.six import StringIO
 from django.utils.six import StringIO
 from django.utils.six.moves import range
 from django.utils.six.moves import range
@@ -23,7 +24,7 @@ class SynchronizeCategoriesTests(TestCase):
         command = synchronizecategories.Command()
         command = synchronizecategories.Command()
 
 
         out = StringIO()
         out = StringIO()
-        command.execute(stdout=out)
+        call_command(command, stdout=out)
 
 
         category = Category.objects.get(id=category.id)
         category = Category.objects.get(id=category.id)
         self.assertEqual(category.threads, 10)
         self.assertEqual(category.threads, 10)

+ 2 - 1
misago/core/tests/test_misagodbrelations.py

@@ -1,3 +1,4 @@
+from django.core.management import call_command
 from django.test import TestCase
 from django.test import TestCase
 from django.utils.six import StringIO
 from django.utils.six import StringIO
 
 
@@ -9,4 +10,4 @@ class MisagoDBRelationsTests(TestCase):
         """command raises no errors during execution"""
         """command raises no errors during execution"""
         command = misagodbrelations.Command()
         command = misagodbrelations.Command()
 
 
-        command.execute(stdout=StringIO())
+        call_command(command, stdout=StringIO())

+ 2 - 1
misago/core/tests/test_remakemisagochecksums.py

@@ -1,3 +1,4 @@
+from django.core.management import call_command
 from django.test import TestCase
 from django.test import TestCase
 from django.utils.six import StringIO
 from django.utils.six import StringIO
 
 
@@ -10,6 +11,6 @@ class RemakeMisagoChecksumsTests(TestCase):
         command = remakemisagochecksums.Command()
         command = remakemisagochecksums.Command()
 
 
         out = StringIO()
         out = StringIO()
-        command.execute("--force", stdout=out)
+        call_command(command, "--force", stdout=out)
         command_output = out.getvalue().splitlines()[-1].strip()
         command_output = out.getvalue().splitlines()[-1].strip()
         self.assertEqual(command_output, "Done!")
         self.assertEqual(command_output, "Done!")

+ 4 - 14
misago/core/tests/test_testmailsetup.py

@@ -1,7 +1,9 @@
 from django.core import mail
 from django.core import mail
+from django.core.management import call_command
 from django.test import TestCase
 from django.test import TestCase
 from django.utils.six import StringIO
 from django.utils.six import StringIO
 
 
+
 from ..management.commands import testemailsetup
 from ..management.commands import testemailsetup
 
 
 
 
@@ -11,7 +13,7 @@ class TestEmailSetupTests(TestCase):
         command = testemailsetup.Command()
         command = testemailsetup.Command()
 
 
         out = StringIO()
         out = StringIO()
-        command.execute("t@mail.com", stdout=out)
+        call_command(command, "t@mail.com", stdout=out)
         command_output = out.getvalue().splitlines()[0].strip()
         command_output = out.getvalue().splitlines()[0].strip()
 
 
         self.assertEqual(command_output, 'Test message was sent to t@mail.com')
         self.assertEqual(command_output, 'Test message was sent to t@mail.com')
@@ -26,18 +28,6 @@ class TestEmailSetupTests(TestCase):
         out = StringIO()
         out = StringIO()
         err = StringIO()
         err = StringIO()
 
 
-        command.execute(stdout=out, stderr=err)
-        command_output = err.getvalue().splitlines()[-1].strip()
-        self.assertEqual(
-            command_output,
-            "Command accepts exactly one argument (e-mail address)")
-
-        command.execute("baww", "awww", stdout=out, stderr=err)
-        command_output = err.getvalue().splitlines()[-1].strip()
-        self.assertEqual(
-            command_output,
-            "Command accepts exactly one argument (e-mail address)")
-
-        command.execute("bawww", stdout=out, stderr=err)
+        call_command(command, "bawww", stdout=out, stderr=err)
         command_output = err.getvalue().splitlines()[-1].strip()
         command_output = err.getvalue().splitlines()[-1].strip()
         self.assertEqual(command_output, "This isn't valid e-mail address")
         self.assertEqual(command_output, "This isn't valid e-mail address")

+ 3 - 2
misago/threads/tests/test_clearattachments.py

@@ -1,6 +1,7 @@
 from datetime import timedelta
 from datetime import timedelta
 
 
 from django.conf import settings
 from django.conf import settings
+from django.core.management import call_command
 from django.test import TestCase
 from django.test import TestCase
 from django.utils import timezone
 from django.utils import timezone
 from django.utils.six import StringIO
 from django.utils.six import StringIO
@@ -18,7 +19,7 @@ class ClearAttachmentsTests(TestCase):
         command = clearattachments.Command()
         command = clearattachments.Command()
 
 
         out = StringIO()
         out = StringIO()
-        command.execute(stdout=out)
+        call_command(command, stdout=out)
         command_output = out.getvalue().strip()
         command_output = out.getvalue().strip()
 
 
         self.assertEqual(command_output, "No attachments were found")
         self.assertEqual(command_output, "No attachments were found")
@@ -75,7 +76,7 @@ class ClearAttachmentsTests(TestCase):
         command = clearattachments.Command()
         command = clearattachments.Command()
 
 
         out = StringIO()
         out = StringIO()
-        command.execute(stdout=out)
+        call_command(command, stdout=out)
 
 
         command_output = out.getvalue().splitlines()[-1].strip()
         command_output = out.getvalue().splitlines()[-1].strip()
         self.assertEqual(command_output, "Cleared 5 attachments")
         self.assertEqual(command_output, "Cleared 5 attachments")

+ 3 - 2
misago/threads/tests/test_synchronizethreads.py

@@ -1,3 +1,4 @@
+from django.core.management import call_command
 from django.test import TestCase
 from django.test import TestCase
 from django.utils.six import StringIO
 from django.utils.six import StringIO
 from django.utils.six.moves import range
 from django.utils.six.moves import range
@@ -14,7 +15,7 @@ class SynchronizeThreadsTests(TestCase):
         command = synchronizethreads.Command()
         command = synchronizethreads.Command()
 
 
         out = StringIO()
         out = StringIO()
-        command.execute(stdout=out)
+        call_command(command, stdout=out)
         command_output = out.getvalue().strip()
         command_output = out.getvalue().strip()
 
 
         self.assertEqual(command_output, "No threads were found")
         self.assertEqual(command_output, "No threads were found")
@@ -32,7 +33,7 @@ class SynchronizeThreadsTests(TestCase):
         command = synchronizethreads.Command()
         command = synchronizethreads.Command()
 
 
         out = StringIO()
         out = StringIO()
-        command.execute(stdout=out)
+        call_command(command, stdout=out)
 
 
         for i, thread in enumerate(threads):
         for i, thread in enumerate(threads):
             db_thread = category.thread_set.get(id=thread.id)
             db_thread = category.thread_set.get(id=thread.id)

+ 4 - 3
misago/users/tests/test_bansmaintenance.py

@@ -1,6 +1,7 @@
 from datetime import timedelta
 from datetime import timedelta
 
 
 from django.contrib.auth import get_user_model
 from django.contrib.auth import get_user_model
+from django.core.management import call_command
 from django.test import TestCase
 from django.test import TestCase
 from django.utils import timezone
 from django.utils import timezone
 from django.utils.six import StringIO
 from django.utils.six import StringIO
@@ -25,7 +26,7 @@ class BansMaintenanceTests(TestCase):
         command = bansmaintenance.Command()
         command = bansmaintenance.Command()
 
 
         out = StringIO()
         out = StringIO()
-        command.execute(stdout=out)
+        call_command(command, stdout=out)
         command_output = out.getvalue().splitlines()[0].strip()
         command_output = out.getvalue().splitlines()[0].strip()
 
 
         self.assertEqual(command_output, 'Bans invalidated: 5')
         self.assertEqual(command_output, 'Bans invalidated: 5')
@@ -49,7 +50,7 @@ class BansMaintenanceTests(TestCase):
         command = bansmaintenance.Command()
         command = bansmaintenance.Command()
 
 
         out = StringIO()
         out = StringIO()
-        command.execute(stdout=out)
+        call_command(command, stdout=out)
         command_output = out.getvalue().splitlines()[1].strip()
         command_output = out.getvalue().splitlines()[1].strip()
 
 
         self.assertEqual(command_output, 'Ban caches emptied: 0')
         self.assertEqual(command_output, 'Ban caches emptied: 0')
@@ -62,7 +63,7 @@ class BansMaintenanceTests(TestCase):
 
 
         # invalidate expired ban cache
         # invalidate expired ban cache
         out = StringIO()
         out = StringIO()
-        command.execute(stdout=out)
+        call_command(command, stdout=out)
         command_output = out.getvalue().splitlines()[1].strip()
         command_output = out.getvalue().splitlines()[1].strip()
 
 
         self.assertEqual(command_output, 'Ban caches emptied: 1')
         self.assertEqual(command_output, 'Ban caches emptied: 1')

+ 2 - 1
misago/users/tests/test_populateonlinetracker.py

@@ -1,4 +1,5 @@
 from django.contrib.auth import get_user_model
 from django.contrib.auth import get_user_model
+from django.core.management import call_command
 from django.test import TestCase
 from django.test import TestCase
 from django.utils.six import StringIO
 from django.utils.six import StringIO
 
 
@@ -17,7 +18,7 @@ class PopulateOnlineTrackerTests(TestCase):
         self.assertEqual(Online.objects.filter(user=test_user).count(), 0)
         self.assertEqual(Online.objects.filter(user=test_user).count(), 0)
 
 
         out = StringIO()
         out = StringIO()
-        populateonlinetracker.Command().execute(stdout=out)
+        call_command(populateonlinetracker.Command(), stdout=out)
         command_output = out.getvalue().splitlines()[0].strip()
         command_output = out.getvalue().splitlines()[0].strip()
 
 
         self.assertEqual(command_output, 'Tracker entries created: 1')
         self.assertEqual(command_output, 'Tracker entries created: 1')

+ 2 - 1
misago/users/tests/test_updateblankavatar.py

@@ -1,3 +1,4 @@
+from django.core.management import call_command
 from django.test import TestCase
 from django.test import TestCase
 from django.utils.six import StringIO
 from django.utils.six import StringIO
 
 
@@ -10,7 +11,7 @@ class UpdateBlankAvatarTests(TestCase):
         command = updateblankavatar.Command()
         command = updateblankavatar.Command()
 
 
         out = StringIO()
         out = StringIO()
-        command.execute(stdout=out)
+        call_command(command, stdout=out)
         command_output = out.getvalue().splitlines()[0].strip()
         command_output = out.getvalue().splitlines()[0].strip()
 
 
         self.assertEqual(command_output, 'Blank avatar was updated')
         self.assertEqual(command_output, 'Blank avatar was updated')

+ 2 - 2
runtests.py

@@ -119,8 +119,8 @@ def run_django(*args, **kwargs):
     setup()
     setup()
     setup_test_environment()
     setup_test_environment()
 
 
-    from django.core.management.commands import test
-    sys.exit(test.Command().execute(*args, **kwargs))
+    from django.core.management import call_command
+    sys.exit(call_command('test', *args, **kwargs))
 
 
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':