Browse Source

feat(api): add test for Captcha cleanup

Peter Thomassen 5 years ago
parent
commit
ee825a1dd6
2 changed files with 22 additions and 5 deletions
  1. 22 0
      api/desecapi/tests/test_chores.py
  2. 0 5
      api/desecapi/tests/test_privacy_chores.py

+ 22 - 0
api/desecapi/tests/test_chores.py

@@ -0,0 +1,22 @@
+from unittest import mock
+
+from django.conf import settings
+from django.core import management
+from django.test import override_settings, TestCase
+from django.utils import timezone
+
+from desecapi.models import Captcha
+
+
+class ChoresCommandTest(TestCase):
+    @override_settings(CAPTCHA_VALIDITY_PERIOD=timezone.timedelta(hours=1))
+    def test_captcha_cleanup(self):
+        faketime = timezone.now() - settings.CAPTCHA_VALIDITY_PERIOD - timezone.timedelta(seconds=1)
+        with mock.patch('django.db.models.fields.timezone.now', return_value=faketime):
+            captcha1 = Captcha.objects.create()
+
+        captcha2 = Captcha.objects.create()
+        self.assertGreaterEqual((captcha2.created - captcha1.created).total_seconds(), 3601)
+
+        management.call_command('chores')
+        self.assertEqual(list(Captcha.objects.all()), [captcha2])

+ 0 - 5
api/desecapi/tests/test_privacy_chores.py

@@ -1,5 +0,0 @@
-from desecapi.tests.base import DesecTestCase
-
-
-class PrivacyChoresCommandTest(DesecTestCase):
-    pass