test_chores.py 851 B

12345678910111213141516171819202122
  1. from unittest import mock
  2. from django.conf import settings
  3. from django.core import management
  4. from django.test import override_settings, TestCase
  5. from django.utils import timezone
  6. from desecapi.models import Captcha
  7. class ChoresCommandTest(TestCase):
  8. @override_settings(CAPTCHA_VALIDITY_PERIOD=timezone.timedelta(hours=1))
  9. def test_captcha_cleanup(self):
  10. faketime = timezone.now() - settings.CAPTCHA_VALIDITY_PERIOD - timezone.timedelta(seconds=1)
  11. with mock.patch('django.db.models.fields.timezone.now', return_value=faketime):
  12. captcha1 = Captcha.objects.create()
  13. captcha2 = Captcha.objects.create()
  14. self.assertGreaterEqual((captcha2.created - captcha1.created).total_seconds(), 3601)
  15. management.call_command('chores')
  16. self.assertEqual(list(Captcha.objects.all()), [captcha2])